2017-09-04 325 views
1

我正在製作一個電報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

我會怎麼做呢?

回答

0

首先,您只能在私人聊天中使用request_location,確保它不會發送給羣組。

如果成功,用戶將發送位置作爲消息,就像sendLocation方法一樣,您需要處理新消息以獲取位置。