reo7sp / tgbot-cpp

C++ library for Telegram bot API
http://reo7sp.github.io/tgbot-cpp
MIT License
996 stars 239 forks source link

Can't figure out about editing recently sent messages by bot #218

Closed Amirhan-Taipovjan-Greatest-I closed 2 years ago

Amirhan-Taipovjan-Greatest-I commented 2 years ago

I can't find any possible method to do that in C++.

Example: I have this part of code:

        bot.getApi().sendMessage(message->chat->id, "|", false, 0, 0, "Markdown", false);
        Sleep(5000);
        bot.getApi().editMessageText("/", message->chat->id, message->messageId, 0, "Markdown", false, 0);

Even if message->messageId isn't zero or something else, I still can't do that code because it sends me to This

llnulldisk commented 2 years ago

The fourth parameter of editMessageText() is a string and not an int: bot.getApi().editMessageText("/", message->chat->id, message->messageId, "", "Markdown", false, 0);

You are also trying to edit the command message from the user. You can only edit messages from the bot itself. You need to get the message id of the message "|" and then use this id in editMessageText()

Amirhan-Taipovjan-Greatest-I commented 2 years ago

You need to get the message id of the message "|" and then use this id in editMessageText()

I can't figure out how I can get it!

llnulldisk commented 2 years ago

Well, the sent message is returned on success with sendMessage()

Message::Ptr sentMessage = bot.getApi().sendMessage(message->chat->id, "|", false, 0, 0, "Markdown", false);
Sleep(5000);
bot.getApi().editMessageText("/", message->chat->id, sentMessage->messageId, "0", "Markdown", false, 0);
Amirhan-Taipovjan-Greatest-I commented 2 years ago

Thank you so much, it works!