yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.31k stars 1.51k forks source link

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

Open Tr0jsperi opened 7 years ago

Tr0jsperi commented 7 years ago

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?

fuzsh commented 7 years ago

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 ....

Tr0jsperi commented 7 years ago

@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.

saeedhei commented 6 years ago

+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)

brianmituka commented 6 years ago

+1 I also have a similar issue

517