Skip to main content
 首页 » 编程设计

python之如何获取 Telegram 用户位置

2024年10月01日7tuyile006

我正在制作 Telegram Bot api 包装器,想知道如何获取用户的位置。我试过这个:

def test(chat): 
    reply_markup = { 
        "chat_id" : chat, 
        "text": "your message", 
        "reply_markup": 
        {"keyboard": 
         [ 
             [{"text": "Send Your Mobile", "request_contact": True}], 
             [{"text": "Send Your Location", "request_location": True}] 
         ] 
        } 
        } 

和:

def func(): 
    keyboard = [{"text":"Hello", "request_location":True}] 
    reply_markup = {"keyboard":keyboard, "one_time_keyboard":True} 
    return json.dumps(reply_markup) 

做一个东西提交给我的 send_messages func,我从:https://www.codementor.io/garethdwyer/building-a-telegram-bot-using-python-part-1-goi5fncay

我该怎么做?

请您参考如下方法:

首先,您只能在私聊中使用request_location,确保它不会发送到群组。

如果成功,用户会将位置作为消息发送,就像 sendLocation 方法一样,您需要处理新消息才能获取位置。