-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorker.cs
36 lines (32 loc) · 1.01 KB
/
Worker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using MiscellaneousGibs.TasmotaBot.Models;
using MQTTnet;
using Serilog;
using Telegram.Bot;
using Telegram.Bot.Types.Enums;
namespace MiscellaneousGibs.TasmotaBot;
#warning Missing docs
public class Worker : BackgroundService
{
private readonly IConfiguration _config;
private readonly ITelegramBotClient _bot;
private readonly MqttFactory _mqttFactory;
private readonly ITelegramUpdateHandler _updateHandler;
public Worker(IConfiguration config, ITelegramBotClient bot, MqttFactory mqttFactory, ITelegramUpdateHandler updateHandler)
{
_config = config;
_bot = bot;
_mqttFactory = mqttFactory;
_updateHandler = updateHandler;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_bot.StartReceiving(
updateHandler: _updateHandler.HandleUpdateAsync,
pollingErrorHandler: _updateHandler.HandlePollingErrorAsync,
receiverOptions: new Telegram.Bot.Polling.ReceiverOptions() {
AllowedUpdates = new[] { UpdateType.Message }
},
cancellationToken: stoppingToken
);
}
}