Skip to content

Commit 2d7ad32

Browse files
committed
Add MenuWebApp
1 parent fb8fac6 commit 2d7ad32

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

MenuBuilder/Elements/MenuWebApp.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Telegram.Bot.Types.ReplyMarkups;
2+
3+
namespace Telegram.Bot.UI.MenuBuilder.Elements;
4+
5+
6+
public class MenuWebApp : MenuElement {
7+
public required string title { get; set; }
8+
public required string url { get; set; }
9+
public string temp { get; set; } = "{{ title }}";
10+
11+
12+
13+
public override async Task<List<InlineKeyboardButton>> BuildAsync() {
14+
if (hide) {
15+
return new();
16+
}
17+
18+
var models = await parrent.InheritedRequestModelAsync();
19+
models.Add(new {
20+
title = TemplateEngine.Render(title, models, botUser.localization),
21+
url = url
22+
});
23+
24+
return new() {
25+
InlineKeyboardButton.WithWebApp(
26+
text: TemplateEngine.Render(temp, models, botUser.localization),
27+
webApp: url
28+
)
29+
};
30+
}
31+
}

MenuBuilder/MessagePage.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ protected MenuOpenPege MenuOpenSubPege(MessagePage page, string? title = null) =
375375
protected MenuLink MenuLink(string url, string title) =>
376376
new() { url = url, botUser = botUser, title = title, parrent = this };
377377

378+
protected MenuWebApp MenuWebApp(string url, string title) =>
379+
new() { url = url, botUser = botUser, title = title, parrent = this };
380+
378381
protected MenuSplit MenuSplit() =>
379382
new() { botUser = botUser, parrent = this };
380383

Telegram.Bot.UI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>0.1.0</Version>
7+
<Version>0.1.1</Version>
88
<PackageId>Telegram.Bot.UI</PackageId>
99
<Authors>VeyDlin</Authors>
1010
<Description>Convenient creation and localization of bots in Telegram</Description>

0 commit comments

Comments
 (0)