all repos — telegram-bot-api @ 14727677a55632b87aa17b9795d09b4681d37be9

Golang bindings for the Telegram Bot API

Add example for responding to inline queries.
Syfaro syfaro@foxpaw.in
Sun, 28 Feb 2016 10:14:08 -0600
commit

14727677a55632b87aa17b9795d09b4681d37be9

parent

585057e7dead4feefae21d8c58f624ae62d1460e

1 files changed, 34 insertions(+), 0 deletions(-)

jump to
M bot_test.gobot_test.go

@@ -436,3 +436,37 @@ for update := range updates {

log.Printf("%+v\n", update) } } + +func ExampleAnswerInlineQuery() { + bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") // create new bot + if err != nil { + log.Panic(err) + } + + log.Printf("Authorized on account %s", bot.Self.UserName) + + u := tgbotapi.NewUpdate(0) + u.Timeout = 60 + + updates, err := bot.GetUpdatesChan(u) + + for update := range updates { + if update.InlineQuery.Query == "" { // if no inline query, ignore it + continue + } + + article := tgbotapi.NewInlineQueryResultArticle(update.InlineQuery.ID, "Echo", update.InlineQuery.Query) + article.Description = update.InlineQuery.Query + + inlineConf := tgbotapi.InlineConfig{ + InlineQueryID: update.InlineQuery.ID, + IsPersonal: true, + CacheTime: 0, + Results: []interface{}{article}, + } + + if _, err := bot.AnswerInlineQuery(inlineConf); err != nil { + log.Println(err) + } + } +}