static TelegramBotClient _TelegramBotClient;
static CancellationTokenSource cts = new CancellationTokenSource();
public static void InitTelegramBotClient()
{
_TelegramBotClient = new TelegramBotClient("1234567890:AAD98dMandhVhEW4jDEu-LTm6fX9MYL9PKU4",httpClient:default,cts.Token);
_TelegramBotClient.OnMessage += _TelegramBotClient_OnMessage;
}
private static Task _TelegramBotClient_OnMessage(Telegram.Bot.Types.Message message, Telegram.Bot.Types.Enums.UpdateType type)
{
if (message.Text is not { } text) {
Console.WriteLine($"Received a message of type {message.Type}");
_TelegramBotClient.SendMessage(message.Chat, $"Echo: Your Message Type is {message.Type}", replyMarkup: new ReplyKeyboardRemove());
}
else if (text.StartsWith('/'))
{
Console.WriteLine($"Command:" + message.Text);
_TelegramBotClient.SendMessage(message.Chat, $"Echo: Your Command is {message.Text}", replyMarkup: new ReplyKeyboardRemove());
}
else
{
Console.WriteLine($"純文字:" + message.Text);
_TelegramBotClient.SendMessage(message.Chat, $"Echo: Your Text is {message.Text}", replyMarkup: new ReplyKeyboardRemove());
}
return Task.FromResult