Skip to content

Commit 301a45f

Browse files
committed
using new button constructors
1 parent 1c509d3 commit 301a45f

6 files changed

Lines changed: 15 additions & 13 deletions

File tree

Console.Advanced/Services/UpdateHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async Task<Message> SendInlineKeyboard(Message msg)
9999
.AddNewRow("1.1", "1.2", "1.3")
100100
.AddNewRow()
101101
.AddButton("WithCallbackData", "CallbackData")
102-
.AddButton(InlineKeyboardButton.WithUrl("WithUrl", "https://github.com/TelegramBots/Telegram.Bot"));
102+
.AddButton(new InlineKeyboardButton("WithUrl", "https://github.com/TelegramBots/Telegram.Bot"));
103103
return await bot.SendMessage(msg.Chat, "Inline buttons:", replyMarkup: inlineMarkup);
104104
}
105105

@@ -119,14 +119,14 @@ async Task<Message> RemoveKeyboard(Message msg)
119119
async Task<Message> RequestContactAndLocation(Message msg)
120120
{
121121
var replyMarkup = new ReplyKeyboardMarkup(true)
122-
.AddButton(KeyboardButton.WithRequestLocation("Location"))
123-
.AddButton(KeyboardButton.WithRequestContact("Contact"));
122+
.AddButton(new("Location", requestLocation: true))
123+
.AddButton(new("Contact", requestContact: true));
124124
return await bot.SendMessage(msg.Chat, "Who or Where are you?", replyMarkup: replyMarkup);
125125
}
126126

127127
async Task<Message> StartInlineQuery(Message msg)
128128
{
129-
var button = InlineKeyboardButton.WithSwitchInlineQueryCurrentChat("Inline Mode");
129+
var button = new InlineKeyboardButton("Inline Mode", InlineButtonType.SwitchInlineQueryCurrentChat);
130130
return await bot.SendMessage(msg.Chat, "Press the button to start Inline Query\n\n" +
131131
"(Make sure you enabled Inline Mode in @BotFather)", replyMarkup: new InlineKeyboardMarkup(button));
132132
}

Console/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ await bot.SendMessage(msg.Chat, """
8888
case "/inline_buttons":
8989
await bot.SendMessage(msg.Chat, "Inline buttons:", replyMarkup: new InlineKeyboardButton[][] {
9090
["1.1", "1.2", "1.3"],
91-
[("WithCallbackData", "CallbackData"), ("WithUrl", "https://github.com/TelegramBots/Telegram.Bot")]
91+
[("WithCallbackData", "CallbackData", KeyboardButtonStyle.Primary),
92+
("WithUrl", "https://github.com/TelegramBots/Telegram.Bot", KeyboardButtonStyle.Success, "5447410659077661506")]
9293
});
9394
break;
9495
case "/keyboard":
95-
await bot.SendMessage(msg.Chat, "Keyboard buttons:", replyMarkup: new[] { "MENU", "INFO", "LANGUAGE" });
96+
await bot.SendMessage(msg.Chat, "Keyboard buttons:", replyMarkup: new KeyboardButton[]
97+
{ "MENU", "INFO", ("LANGUAGE", KeyboardButtonStyle.Primary, "5411091492204716695") });
9698
break;
9799
case "/remove":
98100
await bot.SendMessage(msg.Chat, "Removing keyboard", replyMarkup: new ReplyKeyboardRemove());

MiniApp/MiniApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Telegram.Bot" Version="*" />
12+
<PackageReference Include="Telegram.Bot" Version="22.*" />
1313
</ItemGroup>
1414

1515
</Project>

MiniApp/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async void OnUpdate(TelegramBotClient bot, Update update, ILogger<Program> logge
5252
case { Message.Text: "/start" }:
5353
await bot.SendMessage(update.Message.Chat, "<b>Let's get started</b>\n\nTry our Razor Webapp or order your perfect lunch! 🍟",
5454
parseMode: Telegram.Bot.Types.Enums.ParseMode.Html,
55-
replyMarkup: (InlineKeyboardMarkup)InlineKeyboardButton.WithWebApp("Launch Mini-App", webappUrl));
55+
replyMarkup: new InlineKeyboardButton("Launch Mini-App", InlineButtonType.WebApp, webappUrl));
5656
break;
5757
case { PreCheckoutQuery: { } pcq }:
5858
await bot.AnswerPreCheckoutQuery(pcq.Id, Cafe.OnPreCheckoutQuery(pcq));
@@ -79,7 +79,7 @@ async Task<object> OnDemoApi(TelegramBotClient bot, IConfiguration config, [From
7979
var user = JsonSerializer.Deserialize<User>(query["user"], JsonBotAPI.Options)!;
8080
await bot.SendMessage(user.Id, "Hello, World!",
8181
replyMarkup: with_webview == "0" ? new ReplyKeyboardRemove() :
82-
new ReplyKeyboardMarkup(true).AddButton(KeyboardButton.WithWebApp("Open WebApp", webappUrl + "/demo")));
82+
new ReplyKeyboardMarkup(true).AddButton(new("Open WebApp", webappUrl + "/demo")));
8383
return new { response = new { ok = true } };
8484
default:
8585
return new { ok = false, error = "Unsupported method: " + method };

Webhook.Controllers/Services/UpdateHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ async Task<Message> RemoveKeyboard(Message msg)
109109
async Task<Message> RequestContactAndLocation(Message msg)
110110
{
111111
var replyMarkup = new ReplyKeyboardMarkup(true)
112-
.AddButton(KeyboardButton.WithRequestLocation("Location"))
113-
.AddButton(KeyboardButton.WithRequestContact("Contact"));
112+
.AddButton(new("Location", requestLocation: true))
113+
.AddButton(new("Contact", requestContact: true));
114114
return await bot.SendMessage(msg.Chat, "Who or Where are you?", replyMarkup: replyMarkup);
115115
}
116116

117117
async Task<Message> StartInlineQuery(Message msg)
118118
{
119-
var button = InlineKeyboardButton.WithSwitchInlineQueryCurrentChat("Inline Mode");
119+
var button = new InlineKeyboardButton("Inline Mode", InlineButtonType.SwitchInlineQueryCurrentChat);
120120
return await bot.SendMessage(msg.Chat, "Press the button to start Inline Query\n\n" +
121121
"(Make sure you enabled Inline Mode in @BotFather)", replyMarkup: new InlineKeyboardMarkup(button));
122122
}

Webhook.Controllers/Webhook.Controllers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Telegram.Bot" Version="*" />
17+
<PackageReference Include="Telegram.Bot" Version="22.*" />
1818
</ItemGroup>
1919

2020
</Project>

0 commit comments

Comments
 (0)