Merge pull request #45 from rahiel/master

use long polling in examples
This commit is contained in:
Leandro Toledo 2015-08-24 09:26:20 -03:00
commit 2f99b785b2
3 changed files with 3 additions and 4 deletions

View file

@ -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>`_

View file

@ -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')

View file

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