work on commands

This commit is contained in:
2024-05-29 01:48:45 +03:00
parent 56296843f3
commit db5cd93977
9 changed files with 170 additions and 0 deletions
@@ -0,0 +1,44 @@
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);
}
}
}
}