D
D
DaniPyzinski2019-04-08 22:28:44
Python
DaniPyzinski, 2019-04-08 22:28:44

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

1 answer(s)
P
photozoom, 2019-04-09
@photozoom

After clicking on an inline button, the callback_data value of the buttons goes into the msg['callback_query']['data'] array and not into msg['text'].

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question