mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-25 00:27:46 +01:00
Merge branch 'master' of github.com:leandrotoledo/python-telegram-bot into boteventhandler
This commit is contained in:
commit
cccd6e5baf
2 changed files with 14 additions and 4 deletions
|
@ -261,6 +261,8 @@ Here follows some examples to help you to get your own Bot up to speed:
|
|||
|
||||
- `DevOps Reaction Bot <https://github.com/leandrotoledo/gae-devops-reaction-telegram-bot>`_ sends latest or random posts from `DevOps Reaction <http://devopsreactions.tumblr.com/>`_. Running on `Google App Engine <https://cloud.google.com/appengine>`_ (billing has to be enabled for fully Socket API support).
|
||||
|
||||
- `TwitterForwarderBot <https://github.com/franciscod/telegram-twitter-forwarder-bot>`_ forwards you tweets from people that you have subscribed to.
|
||||
|
||||
================
|
||||
_`Documentation`
|
||||
================
|
||||
|
|
|
@ -29,14 +29,19 @@ except ImportError:
|
|||
|
||||
|
||||
def main():
|
||||
update_id = None
|
||||
# Telegram Bot Authorization Token
|
||||
bot = telegram.Bot('TOKEN')
|
||||
|
||||
# get the first pending update_id, this is so we can skip over it in case
|
||||
# we get an "Unauthorized" exception.
|
||||
try:
|
||||
update_id = bot.getUpdates()[0].update_id
|
||||
except IndexError:
|
||||
update_id = None
|
||||
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Telegram Bot Authorization Token
|
||||
bot = telegram.Bot('TOKEN')
|
||||
|
||||
while True:
|
||||
try:
|
||||
update_id = echo(bot, update_id)
|
||||
|
@ -44,6 +49,9 @@ def main():
|
|||
# These are network problems with Telegram.
|
||||
if e.message in ("Bad Gateway", "Timed out"):
|
||||
sleep(1)
|
||||
elif e.message == "Unauthorized":
|
||||
# The user has removed or blocked the bot.
|
||||
update_id += 1
|
||||
else:
|
||||
raise e
|
||||
except URLError as e:
|
||||
|
|
Loading…
Reference in a new issue