Answer the question
In order to leave comments, you need to log in
Is a certain part of the bot code not working?
Can you please help with the bot this part of the code does not work. Can you help with solving this problem. The code is below
if inputMessage == 'press':
bot.sendMessage(chat_id, "Кнопка 1 .")
if inputMessage == 'press2':
bot.sendMessage(chat_id,'Кнопка 2.')
if inputMessage == 'press3':
bot.sendMessage(chat_id, 'Кнопка 2.')
import time
import telepot
from telepot.loop import MessageLoop
from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton
def on_chat_message(chat_id, inputMessage):
if inputMessage == '/start':
keyboard = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text='Кнопка 1', callback_data='press')],
[InlineKeyboardButton(text='Кнопка 2', callback_data='press2')],
[InlineKeyboardButton(text='Кнопка 3', callback_data='press3')],
])
bot.sendMessage(chat_id, 'Бот привет.', reply_markup=keyboard)
if inputMessage == 'press':
bot.sendMessage(chat_id, "Кнопка 1 .")
if inputMessage == 'press2':
bot.sendMessage(chat_id,'Кнопка 2.')
if inputMessage == 'press3':
bot.sendMessage(chat_id, 'Кнопка 2.')
def on_callback_query(msg):
query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
print('Callback Query:', query_id, from_id, query_data)
if query_data:
on_chat_message(from_id, query_data)
TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxx' # get token from command-line
def handler(msg):
context_type, chat_type, chat_id = telepot.glance(msg)
inputMessage = msg['text']
if inputMessage:
on_chat_message(chat_id, inputMessage)
bot = telepot.Bot(TOKEN)
MessageLoop(bot, {'chat': handler,
'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')
while 1:
time.sleep(10)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question