I
I
iliaaaaaaaaaaaaaa2021-06-14 21:13:40
Python
iliaaaaaaaaaaaaaa, 2021-06-14 21:13:40

How to reply to a message through the tg bot?

It is required to implement the following.
It is necessary that the user to whom the message was sent by

chat_id = ''
, was able to use the command (reply) to respond through the bot to this message.

import config
import telebot



bot = telebot.TeleBot(config.TOKEN)


chat_id = ''


@bot.message_handler(commands=["start"])
def start(message):
    message_text = 'Здравствуйте, '  + message.from_user.first_name + "!" + '\nЯ Бот-отзовик.\nГотов принять ваш отзыв. \n/feedback - оставить отзыв'
    bot.send_message(message.chat.id, message_text)


@bot.message_handler(commands=["feedback"])
def feedback(message):
    msg = bot.send_message(message.chat.id, "Готов принять ваш отзыв: ")
    # устанавливаем следующий шаг обработки сообщения
    bot.register_next_step_handler(msg, feedback_second) # передаем старое сообщение и функцию, в которой будем обрабатывать

    
def feedback_second(message):
    bot.forward_message(chat_id = chat_id, from_chat_id=message.chat.id, message_id=message.message_id)
    bot.send_message(message.chat.id, "Спасибо, отзыв был отправлен ")


if __name__ == '__main__':
    bot.polling(none_stop = True)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question