node.js - 如何使用 Telegram bot API 请求用户的实时位置?

标签 node.js telegram telegram-bot telegraf

我可以使用 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)
)

有什么方法可以请求实时位置吗?

最佳答案

我希望它有帮助:

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(";"));
            })
        })
    })
})

关于node.js - 如何使用 Telegram bot API 请求用户的实时位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50658232/

相关文章:

php - 如何在 PHP Bot Telegram 中创建内联按钮

python - Telegram bot (pyTelegramBotAPI) 不处理新用户加入群组

node.js - 如何将 Mac OSX MIDI 与 node.js 连接?

c# - 我如何从 Telegram Bot 创建私有(private)消息?

javascript - 在react中导入和导出模块

telegram - 使用 php 的机器人 Telegram (发送消息和从用户获取消息的关系)

python - 如何让 Telegram 机器人与动画表情符号一起使用?

java - 如何使用java为电报机器人制作一个url按钮

node.js - 错误 TS2307 : Cannot find module 'app'

javascript - Node JS Javascript Class TypeError 不是函数