M
M
mr_diablol2022-03-17 16:34:02
Python
mr_diablol, 2022-03-17 16:34:02

How to save the responses sent by the bot to the user on the local drive?

Good afternoon. I can't understand/understand/find in Google the answer to this question above.
I use telebot.

The goal is the following: the bot needs to write to the txt file on the local disk not only what the user writes, but also his answers to him.
message.text only returns messages sent by the user.
Maybe someone came across how to mark the messages sent by the bot?

@bot.message_handler(content_types=["text"])
def get_text_messages(message):
    if message.text.lower() == "привет":
        bot.send_message(message.from_user.id, "И тебе привет")
        doc = open( '.txt',  'a')
        doc.write("Сообщение от пользователя: {userone}\n".format(userone=message.text))
    else:
        bot.send_message(message.from_user.id, "Напиши привет")
        doc = open( '.txt',  'a')
        doc.write("Сообщение от пользователя: {userone}\n".format(userone=message.text))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-03-17
@mr_diablol

Similarly, in the text field of the message object.

bot_message = bot.send_message(message.from_user.id, "И тебе привет")
doc.write("Сообщение от бота: {userone}\n".format(userone=bot_message.text))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question