forked from mymmrac/telego
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (63 loc) · 1.98 KB
/
Copy pathmain.go
File metadata and controls
73 lines (63 loc) · 1.98 KB
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
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"context"
"fmt"
"os"
"github.com/mymmrac/telego"
tu "github.com/mymmrac/telego/telegoutil"
)
func main() {
ctx := context.Background()
botToken := os.Getenv("TOKEN")
// Note: Please keep in mind that default logger may expose sensitive information, use in development only
bot, err := telego.NewBot(botToken, telego.WithDefaultDebugLogger())
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Set chat button to open Web App
_ = bot.SetChatMenuButton(ctx, &telego.SetChatMenuButtonParams{
ChatID: 123,
MenuButton: &telego.MenuButtonWebApp{
Type: telego.ButtonTypeWebApp,
Text: "Example",
WebApp: telego.WebAppInfo{
URL: "https://www.example.com/main",
},
},
})
// Also from @BotFather you can set Main Mini App
// (https://core.telegram.org/bots/webapps#launching-the-main-mini-app)
// Use keyboard buttons to open Mini App
_, _ = bot.SendMessage(ctx, tu.Message(tu.ID(123), "Hello, World!").
WithReplyMarkup(tu.Keyboard(
tu.KeyboardRow(
tu.KeyboardButton("Example").WithWebApp(tu.WebAppInfo("https://www.example.com/inline")),
),
)),
)
// In similar way inline keyboard button can also be used
_, _ = bot.SendMessage(ctx, tu.Message(tu.ID(123), "Hello, World!").
WithReplyMarkup(tu.InlineKeyboard(
tu.InlineKeyboardRow(
tu.InlineKeyboardButton("Example").WithWebApp(tu.WebAppInfo("https://www.example.com/inline")),
),
)),
)
// Button in inline query results
_ = bot.AnswerInlineQuery(ctx, &telego.AnswerInlineQueryParams{
InlineQueryID: "some-id",
Results: []telego.InlineQueryResult{
&telego.InlineQueryResultArticle{
// ...
},
},
Button: &telego.InlineQueryResultsButton{
Text: "Example",
WebApp: &telego.WebAppInfo{URL: "https://www.example.com/inline-query"},
},
})
// When receiving data from Mini Apps you MUST validate data received from client, you can use helper function
values, _ := tu.ValidateWebAppData(bot.Token(), "window.Telegram.WebApp.initData")
fmt.Println(values)
}