I can easily respond to messages from users, but I’m having trouble replying to the messages that my bot sends out itself. It seems like I need to obtain the message ID of the bot’s own messages for that purpose.
This is the scenario I am facing:
- User sends: “hi”
- The bot replies with a message
- I wish to respond specifically to the bot’s reply rather than the user’s initial message.
Currently, my code for sending a message looks like this:
await telegramClient.SendTextMessageAsync(messageEvent.Message.Chat.Id, "Hello user!");
And when it comes to replying to the user’s messages, I have this:
await telegramClient.SendTextMessageAsync(123456789, "How are you?", replyToMessageId: messageEvent.Message.MessageId);
However, I want to respond to the “Hello user!” message that the bot sent. Do I need to somehow keep track of the bot’s message ID? What is the best way to obtain it?
class TelegramBot
{
private static ITelegramBotClient telegramClient = new TelegramBotClient("your_token_here");
static void Main(string[] args)
{
telegramClient.OnMessage += HandleIncomingMessage;
Console.Title = telegramClient.GetMeAsync().Result.FirstName;
telegramClient.StartReceiving();
Console.ReadLine();
}
private async static void HandleIncomingMessage(object sender, MessageEventArgs messageEvent)
{
await telegramClient.SendTextMessageAsync(messageEvent.Message.Chat.Id, "Hello user!");
await telegramClient.SendTextMessageAsync(123456789, "How are you?", replyToMessageId: messageEvent.Message.MessageId);
}
}