-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInlineKeyboard.cs
62 lines (56 loc) · 2.16 KB
/
InlineKeyboard.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Threading.Tasks;
using RxTelegram.Bot.Interface.BaseTypes;
using RxTelegram.Bot.Interface.BaseTypes.Requests.Callbacks;
using RxTelegram.Bot.Interface.BaseTypes.Requests.Messages;
using RxTelegram.Bot.Utils.Keyboard;
namespace RxTelegram.Bot.Examples.InlineKeyboard;
internal static class InlineKeyboard
{
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 subscriptionMessage = Bot.Updates.Message.Subscribe(HandleReceivedMessage,
exception => Console.WriteLine($"An error has occured: {exception.Message}"));
var subscriptionCallbackQuery = Bot.Updates.CallbackQuery.Subscribe(HandleCallbackQuery,
exception => Console.WriteLine($"An error has occured: {exception.Message}"));
Console.ReadLine();
subscriptionMessage.Dispose();
subscriptionCallbackQuery.Dispose();
}
private static void HandleCallbackQuery(CallbackQuery callbackQuery)
{
Bot.AnswerCallbackQuery(new AnswerCallbackQuery
{
Text = callbackQuery.Data,
CallbackQueryId = callbackQuery.Id
});
}
private static void HandleReceivedMessage(Message message)
{
if (message.Text.Length != 0)
{
Bot.SendMessage(new SendMessage
{
ChatId = message.Chat.Id,
Text = "Here is a inline keyboard!",
ReplyMarkup = new InlineKeyboardMarkup
{
InlineKeyboard = KeyboardBuilder.CreateInlineKeyboard()
.BeginRow()
.AddCallbackData("Abc", "You clicked on Abc")
.EndRow()
.BeginRow()
.AddCallbackData("1", "You clicked on 1")
.AddCallbackData("2", "You clicked on 2")
.EndRow()
.Build()
}
});
}
}
}