【问题标题】:How to request user's live location using Telegram bot API?如何使用 Telegram bot API 请求用户的实时位置?
【发布时间】:2018-11-12 11:16:31
【问题描述】:
我可以使用 Telegraf 框架请求用户的一次性位置:
bot.start(ctx =>
const keyboard = Extra.markup(markup =>
markup
.resize()
.keyboard([
markup.contactRequestButton('Give phone number'),
markup.locationRequestButton('Give location')
])
)
ctx.replyWithMarkdown('a message to user', keyboard)
)
有什么方法可以请求实时位置吗?
【问题讨论】:
标签:
node.js
telegram
telegram-bot
telegraf
【解决方案1】:
希望对你有帮助:
bot.onText(/^\/place_order/, function (msg, match) {
var option = {
"parse_mode": "Markdown",
"reply_markup": {
"one_time_keyboard": true,
"keyboard": [[{
text: "My phone number",
request_contact: true
}], ["Cancel"]]
}
};
bot.sendMessage(msg.chat.id, "How can we contact you?", option).then(() => {
bot.once("contact",(msg)=>{
var option = {
"parse_mode": "Markdown",
"reply_markup": {
"one_time_keyboard": true,
"keyboard": [[{
text: "My location",
request_location: true
}], ["Cancel"]]
}
};
bot.sendMessage(msg.chat.id,
util.format('Thank you %s with phone %s! And where are you?', msg.contact.first_name, msg.contact.phone_number),
option)
.then(() => {
bot.once("location",(msg)=>{
bot.sendMessage(msg.chat.id, "We will deliver your order to " + [msg.location.longitude,msg.location.latitude].join(";"));
})
})
})
})