Telegram.BotAPI
Telegram.BotAPI copied to clipboard
Сommon way to get the СhatId of any type message
if (update.Type == UpdateType.Message)
chatId = update.Message.Chat.Id;
but how handle all other types?
if (update.Type != UpdateType.Message)
{
chatId = ???;
await bot.SendMessageAsync(chatId, "Message is not a message-type");
}
Hi, it depends. In most cases you will have a copy of the message which you can use to obtain the chat id For example, you can get the message from a callback query>
if (update.Type == UpdateType.CallbackQuery)
{
var chatId = update.CallbackQuery.Message?.Chat.Id;
if (chatId != null)
{
await bot.SendMessage(chatId, "Yeah");
}
await bot.AnswerCallbackQueryAsync(update.CallbackQuery.Id);
}
But be careful, the message may not always be available. Try taking a look at the official documentation to see what properties you could use to get the Chat Id.