Exemplo n.º 1
0
 private async void OnCallback(object?sender, CallbackEventArgs callbackEventArgs)
 {
     try
     {
         await ProcessCallback(sender, callbackEventArgs);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "{Time}: OnChatMessage - Error {Exception}", DateTime.UtcNow, ex.Message);
     }
 }
Exemplo n.º 2
0
        private async Task ProcessCallback(object?sender, CallbackEventArgs callbackEventArgs)
        {
            if (sender is IChatService chatService)
            {
                var commandText = callbackEventArgs.Command?.Split(' ').First();
                var command     = _serviceProvider.GetServices <IBotCommand>().SingleOrDefault(x => $"/{x.Command}".Equals(commandText, StringComparison.InvariantCultureIgnoreCase));

                if (command != null && !string.IsNullOrEmpty(commandText))
                {
                    await command.Execute(chatService,
                                          callbackEventArgs.ChatId,
                                          callbackEventArgs.UserId,
                                          callbackEventArgs.MessageId,
                                          callbackEventArgs.Command?.Replace(commandText, string.Empty).Trim());
                }
                else
                {
                    _logger.LogCritical("Invalid callback data was provided: {CallbackData}", callbackEventArgs);
                }
            }
        }