Skip to content

Instantly share code, notes, and snippets.

@r1d3rzz
Created July 11, 2025 14:54
Show Gist options
  • Save r1d3rzz/d8a7a6ae51595cf4b5d6544bf5b900e9 to your computer and use it in GitHub Desktop.
Save r1d3rzz/d8a7a6ae51595cf4b5d6544bf5b900e9 to your computer and use it in GitHub Desktop.
using TelegramBot.Helpers;
Console.WriteLine("Sending Start...");
DateTime startTime = DateTime.Now;
Console.Write("Type your Message: ");
string message = Console.ReadLine()!;
await TelegramBotHandler.SendTelegramMessage(message!);
DateTime endTime = DateTime.Now;
TimeSpan duration = endTime - startTime;
Console.WriteLine("Sending End");
Console.WriteLine($"⏱️ Duration: {duration.TotalSeconds:F2} seconds");
public class TelegramBotHandler
{
/*
check for userId [/getMe for bot id]
https://api.telegram.org/bot<token>/getUpdates
*/
public static async Task SendTelegramMessage(string text)
{
try
{
string token = "<token>";
string chatId = "<userId>";
using (HttpClient client = new HttpClient())
{
string url = $"https://api.telegram.org/bot{token}/sendMessage";
var data = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("chat_id", chatId),
new KeyValuePair<string, string>("text", text),
new KeyValuePair<string, string>("parse_mode", "Markdown")
});
await client.PostAsync(url, data);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment