Skip to content

Commit b8d30ed

Browse files
committed
Refactored example bots
1 parent 5abc6ec commit b8d30ed

6 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎examples/echo_bot.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# This is a simple echo bot using the decorator mechanism.
22
# It echoes any incoming text messages.
33

4-
import telebot
4+
import telebot.listeners
55

66
API_TOKEN = '<api_token>'
77

88
bot = telebot.TeleBot(API_TOKEN)
99

10+
1011
# Handle '/start' and '/help'
1112
@bot.message_handler(commands=['help', 'start'])
1213
def send_welcome(message):

‎examples/inline_example.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# This example show how to write an inline mode telegramt bot use pyTelegramBotAPI.
2+
from __future__ import print_function
23
import telebot
34
import time
45
import sys
@@ -69,5 +70,5 @@ def main_loop():
6970
try:
7071
main_loop()
7172
except KeyboardInterrupt:
72-
print >> sys.stderr, '\nExiting by user request.\n'
73+
print('\nExiting by user request.\n')
7374
sys.exit(0)

‎examples/step_example.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def process_name_step(message):
3939
user_dict[chat_id] = user
4040
msg = bot.reply_to(message, 'How old are you?')
4141
bot.register_next_step_handler(msg, process_age_step)
42-
except Exception as e:
42+
except Exception:
4343
bot.reply_to(message, 'oooops')
4444

4545

‎examples/webhook_examples/webhook_cherrypy_echo_bot.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def index(self):
4646
length = int(cherrypy.request.headers['content-length'])
4747
json_string = cherrypy.request.body.read(length).decode("utf-8")
4848
update = telebot.types.Update.de_json(json_string)
49-
bot.process_new_messages([update.message])
49+
bot.process_new_updates([update])
5050
return ''
5151
else:
5252
raise cherrypy.HTTPError(403)

‎examples/webhook_examples/webhook_cpython_echo_bot.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def do_POST(self):
6060
self.end_headers()
6161

6262
update = telebot.types.Update.de_json(json_string)
63-
bot.process_new_messages([update.message])
63+
bot.process_new_updates([update.message])
6464
else:
6565
self.send_error(403)
6666
self.end_headers()

‎examples/webhook_examples/webhook_flask_echo_bot.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def webhook():
5050
if flask.request.headers.get('content-type') == 'application/json':
5151
json_string = flask.request.get_data().encode('utf-8')
5252
update = telebot.types.Update.de_json(json_string)
53-
bot.process_new_messages([update.message])
53+
bot.process_new_updates([update])
5454
return ''
5555
else:
5656
flask.abort(403)

0 commit comments

Comments
 (0)