eternnoir / pyTelegramBotAPI

Python Telegram bot api.
GNU General Public License v2.0
8.02k stars 2.02k forks source link

How we should set callback query handler for inline buttons? #563

Closed kingofnull closed 6 years ago

kingofnull commented 6 years ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using? Version: 3.6.5
  2. What OS are you using? Windows 10 April 2018
  3. What version of python are you using? Python 2.7.14

this show the inline buttons:

msg = bot.reply_to(m, "Send me your url:")
markup = types.InlineKeyboardMarkup()
itembtna = types.InlineKeyboardButton('a', callback_data="ds")
itembtnv = types.InlineKeyboardButton('v', callback_data="sds")
itembtnc = types.InlineKeyboardButton('c', callback_data="sdss")
markup.row(itembtna)
markup.row(itembtnv, itembtnc)

but how we should set callback query handler for inline buttons?

Badiboy commented 6 years ago

Read the doc here: https://github.com/eternnoir/pyTelegramBotAPI#callback-query-handler

You can also use anything of the query within the lambda to distinct callback processing methods. For example:

@bot.callback_query_handler(lambda query: query.data == "sdss")
def process_callback_1(query):
  pass

@bot.callback_query_handler(lambda query: query.data in ["ds", "sds"])
def process_callback_2(query):
  pass
kingofnull commented 6 years ago

Thanks but how to update the message?

Badiboy commented 6 years ago

bot.edit_message_text(chat_id, message_id, new_text, ...) or any other edit_message_xxx.

See details here: https://core.telegram.org/bots/api#updating-messages

kingofnull commented 6 years ago

I know but where are chat id and message id in query ?

Badiboy commented 6 years ago

Bro, spend 10 minutes to read the docs! Bot API doc is really small and well structured.

https://core.telegram.org/bots/api#callbackquery

query.message.chat.id query.message.message_id

kingofnull commented 6 years ago

Thanks I done it before but in another way, I found chat_id in json property of message not directly in message property. I think documentation of pyTelegramBotAPI is not complete and should cover this. Also there are other function in telegram bot API which didn't mention in pyTelegramBotAPI's documentation and I don't know how to use them.

SL-Hydra commented 1 year ago

bot.edit_message_text(chat_id, message_id, new_text, ...) or any other edit_message_xxx.

See details here: https://core.telegram.org/bots/api#updating-messages

bro how to delete a message?

kingofnull commented 1 year ago

bot.edit_message_text(chat_id, message_id, new_text, ...) or any other edit_message_xxx. See details here: https://core.telegram.org/bots/api#updating-messages

bro how to delete a message?

call this method: https://pytba.readthedocs.io/en/latest/sync_version/index.html#telebot.TeleBot.delete_message

GodHand226 commented 2 weeks ago

Thanks to this thread.