22This is a detailed example using almost every command of the API
33"""
44
5+ import time
6+
57import telebot
68from telebot import types
7- import time
89
910TOKEN = '<token_string>'
1011
1112knownUsers = [] # todo: save these in a file,
1213userStep = {} # so they won't reset every time the bot restarts
1314
1415commands = { # command description used in the "help" command
15- 'start' : 'Get used to the bot' ,
16- 'help' : 'Gives you information about the available commands' ,
17- 'sendLongText' : 'A test using the \' send_chat_action\' command' ,
18- 'getImage' : 'A test using multi-stage messages, custom keyboard, and media sending'
16+ 'start' : 'Get used to the bot' ,
17+ 'help' : 'Gives you information about the available commands' ,
18+ 'sendLongText' : 'A test using the \' send_chat_action\' command' ,
19+ 'getImage' : 'A test using multi-stage messages, custom keyboard, and media sending'
1920}
2021
2122imageSelect = types .ReplyKeyboardMarkup (one_time_keyboard = True ) # create the image selection keyboard
@@ -33,7 +34,7 @@ def get_user_step(uid):
3334 else :
3435 knownUsers .append (uid )
3536 userStep [uid ] = 0
36- print "New user detected, who hasn't used \" /start\" yet"
37+ print ( "New user detected, who hasn't used \" /start\" yet" )
3738 return 0
3839
3940
@@ -45,7 +46,7 @@ def listener(messages):
4546 for m in messages :
4647 if m .content_type == 'text' :
4748 # print the sent message to the console
48- print str (m .chat .first_name ) + " [" + str (m .chat .id ) + "]: " + m .text
49+ print ( str (m .chat .first_name ) + " [" + str (m .chat .id ) + "]: " + m .text )
4950
5051
5152bot = telebot .TeleBot (TOKEN )
@@ -128,4 +129,5 @@ def command_default(m):
128129 # this is the standard reply to a normal message
129130 bot .send_message (m .chat .id , "I don't understand \" " + m .text + "\" \n Maybe try the help page at /help" )
130131
132+
131133bot .polling ()
0 commit comments