forked from mymmrac/telego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (43 loc) · 1.26 KB
/
main.go
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
package main
import (
"fmt"
"os"
"github.com/mymmrac/telego"
tu "github.com/mymmrac/telego/telegoutil"
)
func main() {
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)
}
updates, _ := bot.UpdatesViaLongPolling(nil)
defer bot.StopLongPolling()
for update := range updates {
// Receive inline query
if update.InlineQuery != nil {
iq := update.InlineQuery
name := iq.From.FirstName
// Answer inline query request
_ = bot.AnswerInlineQuery(tu.InlineQuery(
iq.ID,
tu.ResultArticle(
"hello",
"Hello",
tu.TextMessage( // Hello message with an inline query
fmt.Sprintf("Hello %s\n\nYour query:\n```%#+v```", name, iq),
).WithParseMode(telego.ModeMarkdownV2),
).WithDescription(fmt.Sprintf("Query: %q", iq.Query)),
tu.ResultArticle(
"bey",
"Bye",
tu.TextMessage( // Bye message with an inline query
fmt.Sprintf("Bye %s\n\nYour query:\n```%#+v```", name, iq),
).WithParseMode(telego.ModeMarkdownV2),
).WithDescription(fmt.Sprintf("Query: %q", iq.Query)),
).WithIsPersonal())
}
}
}