Open b-ferd opened 8 months ago
Maybe you have already found a solution yourself. If not, here is my guess.
First of all, you posted the log of the update polling running in the background. This is logged, but should run properly again as soon as the internet connection is re-established. (you wrote this as the funny postscript)
As far as I can see, this library has no integrated error handling for sending a message. However, you should be able to integrate this yourself quite easily.
bot = Bot(bot_token)
bot.add_listener(MessageListener(bot))
bot.add_commands(BotsCommands(bot))
bot.start()
...
while True: # your default task loop
while True: # loop to retry after exception
try:
bot.send_message(chat_id, "testmessage") # chat_id stored globally, the chat we want to send info to
except IOError: # may be more precise, e.g. requests.exceptions.ConnectionError
logging.exception("Telegram Server Connection lost")
time.sleep(5) # wait 5 seconds before retry
continue
else:
break # break inner loop if send_message was successfully
# sleep for a while
But my example has one big problem. It keeps trying to send the message until it succeeds. This could end in an endless loop.
I hope this helps you.
I did not find a solution, I ran into more issues like this and decided to switch to a different bot framework that offers better error handling. Thanks for trying to help!
I'm running OrigamiBot as part of a multi thread server process. From within the telegram communication thread, I run bot.start() (which starts more Origamibot threads in the background), then I use that thread for forwarding messages from the system to the bot asynchronously (i.e.: from the main thread, not triggered by incoming bot messages; I don't use the asyncio concept). This all works quite well.
Things seem to become a bit ugly when for example the network is down, or the server is not reachable for any other reason.
This leads to a flurry of messages like these:
(Bot data has been replaced with BOTID and BOTTOKEN in above log).
I would like to somewhat gracefully catch these, log them as a single concise message to syslog ("Telegram Server Connection lost"), and then try to recover (i.e. the system should continue to operate, and silently try to reconnect to the telegram server in the background).
How is this best done? Is it even possible with Origamibot? Is the above behavior a bug? Or am I doing something wrong?
My code looks about as this (edited for brevity):
Funny: The bot seems to reconnect, and commands I type in the telegram channel do get through to the system. But messages my systems send to the telegram channel via the bot (see above example) are lost.