Files
NemesisAI/TelegramBot/Program.cs
Samuele Lorefice 0ba298b955 Base commit
2024-12-24 23:08:08 +01:00

31 lines
1.0 KiB
C#

using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using var cts = new CancellationTokenSource();
var bot = new TelegramBotClient(Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN"), cancellationToken:cts.Token);
var me = bot.GetMe();
bot.OnMessage += OnMessage;
Console.ReadLine();
cts.Cancel();
async Task OnMessage(Message msg, UpdateType type)
{
//Discard any message that is not a text message
if (msg.Type != MessageType.Text) return;
//Check if the message contains the bot's username
if (msg.Text!.Contains(me.Result.Username!, StringComparison.OrdinalIgnoreCase))
await bot.SendMessage(msg.Chat, "You mentioned me!");
//Check if the message is a reply to a message sent by the bot
else if(msg.ReplyToMessage != null && msg.ReplyToMessage.From!.Id == me.Result.Id){
await bot.SendMessage(msg.Chat, "You replied to a message!");
}
//We can safely return otherwise
}
HttpClient AiClient = new HttpClient();
string getNemesisMsg() {
//AiClient.GetAsync()
return "";
}