2017-11-29 9 views
0

私はgithub.com/go-telegram-bot-apiを使用してボットを作成しています。私はクライアントの位置を尋ねたい。どうすればいいのですか?これまでのところ、私はこれをしなかった:GoLang Telegram-bot-api場所の問い合わせ方法は?

updates, err := bot.GetUpdatesChan(u) 

for update := range updates { 
    if update.Message == nil { 
     continue 
    } 

    switch update.Message.Text { 
    case "/shop": 
     msg := tgbotapi.NewMessage(update.Message.Chat.ID,"Send me your location") 
     //I need to make this message ask for the location 
     msg.Text = tgbotapi.ChatFindLocation 
     bot.Send(msg) 
     continue 
    } 
} 

答えて

1

は、残念ながら彼らのリポジトリに、このための例がありません。どのようにして行うのかを理解するためのコードを少し読んだ。

これは、取得したすべてのメッセージの場所を要求するサンプルボットです。クリックしたときに場所を共有するワンボタン仮想キーボードを作成しました。

package main 

import (
    "gopkg.in/telegram-bot-api.v4" 
    "log" 
) 

const botToken = "Put your bot token here!" 

func main() { 
    bot, err := tgbotapi.NewBotAPI(botToken) 
    if err != nil { 
     log.Panic(err) 
    } 

    bot.Debug = true 
    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.Message == nil { 
      continue 
     } 

     log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) 

     msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Hi") 
     //msg.ReplyToMessageID = update.Message.MessageID 
     btn := tgbotapi.KeyboardButton{ 
      RequestLocation: true, 
      Text: "Gimme where u live!!", 
     } 
     msg.ReplyMarkup = tgbotapi.NewReplyKeyboard([]tgbotapi.KeyboardButton{btn}) 
     bot.Send(msg) 
    } 
} 
関連する問題