using BotFramework; using BotFramework.Attributes; using Kruzya.TelegramBot.CustomChatAddOns.Data; using Kruzya.TelegramBot.CustomChatAddOns.Data.WebhookCommand; using Kruzya.TelegramBot.CustomChatAddOns.Options; using Kruzya.TelegramBot.CustomChatAddOns.Service; namespace Kruzya.TelegramBot.CustomChatAddOns.Handler { public class MessageHandler : BotEventHandler { private readonly CustomChatHandler _option; private readonly InteropService _interopService; public MessageHandler(CustomChatHandler option, InteropService interopService) { _option = option; _interopService = interopService; } [Message] [Priority(short.MinValue + 10)] public async Task DeliverMessage() { var message = RawUpdate.Message; if (message == null) { return; } var url = await _option.GetValueAsync(Chat.Id); if (string.IsNullOrWhiteSpace(url)) { return; } var commands = await _interopService.PostMessage>(url, new() { Message = message }); foreach (var command in commands) { await command.Execute(Bot, message); } } } }