R
R
RedSs2019-08-01 09:20:59
JavaScript
RedSs, 2019-08-01 09:20:59

Duplicate notification when re-executing a nodejs function?

There is an event handler for case yes, and it does it perfectly, but I found a bug when you execute the
event several times, the notification "Your city was successfully saved / changed" is duplicated. If you do it twice, then it is duplicated 2 times, if 3, then 3 times, etc. How can this bug be fixed?

//обрабатываем инлайн клавиатуру
    bot.on('callback_query', query => {
        const { chat, message_id, text } = query.message
        switch (query.data) {
            case 'yes':
//проверяем наличие юзера в бд если его нет заносим, иначе обновляем данн
                users.update({ids: `${msg.from.id}`},{$set:{login: `${chat.first_name}`,coords: `${coord}`,fullAddress:`${fullAddress}`}},{upsert:true})
                    .then(users => {
                        bot.sendMessage(chat.id, 'Ваш город успешно сохранен/изменен',{
                            reply_markup:{keyboard:keyboard.home,resize_keyboard: true}
                        })
                    })
                    .catch(e => bot.sendMessage(chat.id, 'Неизвестная ошибка, повторите ваш запрос позже'))


                break
            case 'no':
                bot.sendMessage(chat.id, 'Хорошо попробуйте ввести город еще раз\nНапример /gorod Самара,Россия')
                break
        }

        bot.answerCallbackQuery({
            callback_query_id: query.id
        })
    })

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly, 2019-08-02
@vshvydky

Judging by the given piece of code, the behavior described in the question is not observed. As a fortuneteller, I will assume that you re-install listeners to listen to the event and your memory is leaking. Look for similar places in the code, this is probably the problem.

A
Anton Spirin, 2017-11-28
@vikholodov

$('.counter').each(function(index) {
  // тут генерируйте и присваивайте значение, можно использовать индекс
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question