TelegramBots/Telegram.Bot.Examples

use C# telegram.bot - get BotOnCallbackQueryReceived result in webhook (.net core)

pramirhossein opened this issue · 1 comments

Hello !

I can not implement the event OnCallbackQuery or OnMessage in telegram.bot webhook ! ( .net core )

  public async Task EchoAsync(Update update)
        {
                Message message = update.Message;
                _botService.Client.OnMessage += BotOnMessageReceived;
                _botService.Client.OnCallbackQuery += BotOnCallbackQueryReceived;            
        }
private async void BotOnCallbackQueryReceived(object sender, CallbackQueryEventArgs callbackQueryEventArgs)
{
                Telegram.Bot.Types.CallbackQuery callbackQuery = 
                callbackQueryEventArgs.CallbackQuery;
                await _botService.Client.AnswerCallbackQueryAsync(
               callbackQuery.Id,
               $"Received {callbackQuery.Data}");
}

This method works in ConsoleApplication C# but , does not work in webhook mode

If you're working with .NET Core 3+ you have to add JsonNet to deserialize Update object properly.

Please read https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#use-newtonsoftjson-in-an-aspnet-core-30-mvc-project