mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
use long polling in examples
This commit is contained in:
parent
3658b4231c
commit
41eb45918c
3 changed files with 3 additions and 4 deletions
|
@ -14,6 +14,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
|||
- `JASON0916 <https://github.com/JASON0916>`_
|
||||
- `JRoot3D <https://github.com/JRoot3D>`_
|
||||
- `macrojames <https://github.com/macrojames>`_
|
||||
- `Rahiel Kasim <https://github.com/rahiel>`_
|
||||
- `sooyhwang <https://github.com/sooyhwang>`_
|
||||
- `wjt <https://github.com/wjt>`_
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
import logging
|
||||
import telegram
|
||||
import time
|
||||
|
||||
|
||||
LAST_UPDATE_ID = None
|
||||
|
@ -43,14 +42,13 @@ def main():
|
|||
|
||||
while True:
|
||||
echo(bot)
|
||||
time.sleep(3)
|
||||
|
||||
|
||||
def echo(bot):
|
||||
global LAST_UPDATE_ID
|
||||
|
||||
# Request updates after the last updated_id
|
||||
for update in bot.getUpdates(offset=LAST_UPDATE_ID):
|
||||
for update in bot.getUpdates(offset=LAST_UPDATE_ID, timeout=10):
|
||||
# chat_id is required to reply any message
|
||||
chat_id = update.message.chat_id
|
||||
message = update.message.text.encode('utf-8')
|
||||
|
|
|
@ -33,7 +33,7 @@ def main():
|
|||
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id # Get lastest update
|
||||
|
||||
while True:
|
||||
for update in bot.getUpdates(offset=LAST_UPDATE_ID):
|
||||
for update in bot.getUpdates(offset=LAST_UPDATE_ID, timeout=10):
|
||||
text = update.message.text
|
||||
chat_id = update.message.chat.id
|
||||
update_id = update.update_id
|
||||
|
|
Loading…
Reference in a new issue