mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
|
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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|