-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelloWorld.cs
33 lines (28 loc) · 1009 Bytes
/
HelloWorld.cs
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
using System;
using System.Threading.Tasks;
using RxTelegram.Bot.Interface.BaseTypes;
using RxTelegram.Bot.Interface.BaseTypes.Requests.Messages;
namespace RxTelegram.Bot.Examples.HelloWorld;
public static class HelloWorld
{
private static TelegramBot Bot { get; set; }
private const string BotToken = "<PASTE YOUR BOT TOKEN HERE>";
public static async Task Main()
{
Bot = new TelegramBot($"{BotToken}");
var me = await Bot.GetMe();
Console.WriteLine($"Bot name: @{me.Username}");
var subscription = Bot.Updates.Message.Subscribe(HandleReceivedMessage);
Console.ReadLine();
subscription.Dispose();
}
private static void HandleReceivedMessage(Message message)
{
Console.WriteLine($"{message.From.Username}: {message.Text}");
Bot.SendMessage(new SendMessage
{
ChatId = message.Chat.Id,
Text = $"Hello World, {message.From.FirstName ?? message.From.Username}"!
});
}
}