-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkerBot.cs
More file actions
45 lines (42 loc) · 1.63 KB
/
WorkerBot.cs
File metadata and controls
45 lines (42 loc) · 1.63 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Extensions.Polling;
using Telegram.Bot.Types;
using Telegram.Bot.Exceptions;
using System.Threading;
namespace TelegramBot
{
internal class WorkerBot
{
public static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
{
// Некоторые действия
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(update));
if (update.Type == Telegram.Bot.Types.Enums.UpdateType.Message)
{
var message = update.Message;
var link = ParserLink.AngleSharp(message.Text);
if (message.Text.ToLower() == "/start")
{
await botClient.SendTextMessageAsync(message.Chat, $"Добро пожаловать, {message.Chat.Username}");
return;
}
if (message.Text.ToLower().Contains("https"))
{
await botClient.SendPhotoAsync(message.Chat, link[0]);
return;
}
await botClient.SendTextMessageAsync(message.Chat, "Привет!");
}
}
public static async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
{
// Некоторые действия
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(exception));
}
}
}