Y
Y
Yevgeni2018-05-18 18:21:45
Python
Yevgeni, 2018-05-18 18:21:45

How to call a function and pass chat id to it after clicking on InlineKeyboardButton?

There is a code:

def listener(messages):
    for message in messages:
        if message.content_type == 'text':
            print(str(message.chat.first_name) +
                  " [" + str(message.chat.id) + "]: " + message.text)


bot = TeleBot(TOKEN)
bot.set_update_listener(listener)


@bot.message_handler(commands=['hot_news'])
def send_hot_news(message):
    chat_id = message.chat.id
    for i in range(1):
        keyboard = types.InlineKeyboardMarkup()
        button = types.InlineKeyboardButton(
            'Получить полный текст статьи', callback_data='get_full_text')
        keyboard.add(button)
        txt = open('text.txt', 'rb').read()
        bot.send_message(
            chat_id, txt, parse_mode='HTML', reply_markup=keyboard)

@bot.callback_query_handler(func=lambda call: True)
def callbacks(call):
    if call.data == "get_full_text":
        # тут мне хотелось бы вызвать функцию отправик полного текста статьи
        # отдельным сообщением
        bot.send_message(
            chat_id, 'это не работает потому что функция не принимает chat id')

Help me to understand

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilyas, 2018-05-18
@Yevgeni

if this is about the callbacks function, then before bot.send_message
chat_id = call.message.chat.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question