Telegram.Bot.SpaceApi/Backend/TelegramBotClient.cs

25 lines
567 B
C#
Raw Normal View History

2023-04-08 14:47:05 +02:00
using System.Security.Authentication;
namespace Telegram.Bot.SpaceApi.Backend;
using TgBot = Telegram.Bot.TelegramBotClient;
public class TelegramBotClient {
private TgBot _bot;
public TelegramBotClient(string token) {
_bot = new TgBot(token);
try {
_ = _bot.GetMeAsync().Result;
}
catch {
throw new InvalidCredentialException("Invalid bot token.");
}
}
public void SendMessage(string chat, string message) {
2023-04-09 16:12:58 +02:00
Console.WriteLine($"Sent message to chat {chat}. Message ID: " + _bot.SendTextMessageAsync(chat, message).Result.MessageId);
2023-04-08 14:47:05 +02:00
}
}