-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (49 loc) · 1.76 KB
/
Program.cs
File metadata and controls
55 lines (49 loc) · 1.76 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Telegram.Bot;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Polling;
using Telegram.Bot.Types;
namespace BotProject
{
internal class Program
{
static BotManager botManager = new BotManager();
const string token = "6994270115:AAEJmuUiC5Mj4OkcVnfLHO5td-FrHX5QZ-c";
static void Main(string[] args)
{
TelegramBotClient botClient = new TelegramBotClient(token);
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
ReceiverOptions receiverOptions = new ReceiverOptions()
{
AllowedUpdates = { }
};
botClient.StartReceiving(
updateHandler: UpdateHandlerAsync,
receiverOptions: receiverOptions,
cancellationToken: cancellationTokenSource.Token,
pollingErrorHandler: ErrorHandlerAsync);
Console.ReadKey();
}
static Task ErrorHandlerAsync(ITelegramBotClient client, Exception exception, CancellationToken token)
{
var ErrorMessage = exception switch
{
ApiRequestException apiRequestException
=> $"Telegram API Error:\n[{apiRequestException.ErrorCode}]\n{apiRequestException.Message}",
_ => exception.ToString()
};
Console.WriteLine(ErrorMessage);
return Task.CompletedTask;
}
static async Task UpdateHandlerAsync(ITelegramBotClient client, Update update, CancellationToken token)
{
if(update == null)
{
return;
}
else
{
await botManager.MessageTextAsync(client, update, token);
}
}
}
}