Files
telegram-bot/modules/CustomChatAddOns/Handler/MessageHandler.cs
T

45 lines
1.3 KiB
C#
Raw Normal View History

2024-05-29 01:48:45 +03:00
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<NewMessage, List<IWebhookCommand>>(url, new() { Message = message });
foreach (var command in commands)
{
await command.Execute(Bot, message);
}
}
}
}