node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

Question: how to end chat process created by "bot.onText()"

Open Tr0jsperi opened this issue 7 years ago • 4 comments

Question

I created a weather forecast bot based on user's location. I use bot.onText(/\/weather/... to handle user's request and send a message including reply_markup to get user's location. Then I use bot.on('location',... to make the bot react when the user send the location. Everything goes well when I chat with the bot for the first time. But when I send /weather second time, the bot ask for my location again. After I sent the location, the first chat process got the location too, so the bot gives duplicated answer. If I ask the bot again, it'll send three same answers... I'd like to know is there any way to stop the chat after the bot has made response so the bot can give just one answer each time?

Tr0jsperi avatar Apr 29 '17 15:04 Tr0jsperi

The bot is not intelligent as human... As i know your questions ..... First check the message text Second use state for your multiple levels , ex. Use arrays ....

farzad-845 avatar Apr 29 '17 16:04 farzad-845

@FaRzad-845 Thanks for your reply. For now I use a flag to determine if the user's message has been replied. If the chat process has given the answer once, it will not response to location message any more. But actually the chat process is still running. Will it take too much memory space when more and more chat established? I'm new to node.js and javascript so I'm not familiar with the memory allocation and release mechanism in this case.

Tr0jsperi avatar Apr 30 '17 02:04 Tr0jsperi

+1 , I have another issue same as you. (https://github.com/yagop/node-telegram-bot-api/issues/513)

My Problem Solved with This: (https://github.com/saeedhei/node-telegram-bot-api-message-receiver)

saeedhei avatar Feb 03 '18 21:02 saeedhei

+1 I also have a similar issue #517

brianmituka avatar Feb 05 '18 07:02 brianmituka