Как запросить местоположение пользователя в реальном времени с помощью бота Telegram API? - PullRequest
0 голосов
/ 02 июня 2018

Я могу запросить одноразовое местоположение пользователя с помощью платформы 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)
)

Можно ли вместо этого запросить местоположение в реальном времени?

1 Ответ

0 голосов
/ 06 июня 2018

Надеюсь, это поможет:

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