X Tutup
Skip to content

Commit 92ca923

Browse files
committed
Merge pull request python-telegram-bot#43 from rahiel/master
confirm processed message in examples
2 parents 8746222 + 0691b1e commit 92ca923

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

examples/echobot.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,19 @@ def main():
4949
def echo(bot):
5050
global LAST_UPDATE_ID
5151

52-
# Request updates from last updated_id
52+
# Request updates after the last updated_id
5353
for update in bot.getUpdates(offset=LAST_UPDATE_ID):
54-
if LAST_UPDATE_ID < update.update_id:
55-
# chat_id is required to reply any message
56-
chat_id = update.message.chat_id
57-
message = update.message.text.encode('utf-8')
58-
59-
if (message):
60-
# Reply the message
61-
bot.sendMessage(chat_id=chat_id,
62-
text=message)
63-
64-
# Updates global offset to get the new updates
65-
LAST_UPDATE_ID = update.update_id
54+
# chat_id is required to reply any message
55+
chat_id = update.message.chat_id
56+
message = update.message.text.encode('utf-8')
57+
58+
if (message):
59+
# Reply the message
60+
bot.sendMessage(chat_id=chat_id,
61+
text=message)
62+
63+
# Updates global offset to get the new updates
64+
LAST_UPDATE_ID = update.update_id + 1
6665

6766

6867
if __name__ == '__main__':

examples/roboed.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ def main():
3838
chat_id = update.message.chat.id
3939
update_id = update.update_id
4040

41-
if LAST_UPDATE_ID < update_id: # If newer than the initial
42-
# LAST_UPDATE_ID
43-
if text:
44-
roboed = ed(text) # Ask something to Robô Ed
45-
bot.sendMessage(chat_id=chat_id, text=roboed)
46-
LAST_UPDATE_ID = update_id
41+
if text:
42+
roboed = ed(text) # Ask something to Robô Ed
43+
bot.sendMessage(chat_id=chat_id, text=roboed)
44+
LAST_UPDATE_ID = update_id + 1
4745

4846

4947
def ed(text):

0 commit comments

Comments
 (0)
X Tutup