echo-bot and loop
asarubbo opened this issue · 3 comments
Hi,
I tried the echo-bot example here: https://python-telegram.readthedocs.io/en/latest/tutorial.html
Suppose you change the ping -> pong messages with hi -> hi ( to answer the greeting ) it goes in an infinite loop. After that if you kill/stop the script and restore the ping -> pong messages, when you start the script it still sends a dozens of 'hi', the only way to stop this behavior is delete the files_directory
In any case while you have a ping -> pong you expect to get a ping and send a pong, but if you sent a ping, you will get the pong written by the bot, so I think that the example should cover the case to distinguish the message sent from the current account and the message received by the interlocutor
Can you reproduce the issue?
Hi! Yes, that's kind of expected. It's just an example and it does not check who sent the message. You can add a condition to if message_text == 'ping':
and check the author of the update.
I made a bit of testing in the meantime and I think adding the following solves the issue:
is_outgoing = update['message']['is_outgoing']
- if message_text == 'ping':
+ if is_outgoing == False and message_text == 'ping':
I think that update the example would be great for everyone =)
Yes, I think it’s a good idea. :) Feel free to make a PR, or I can create it a bit later.