如何获取电报用户位置
问题描述:
我正在制作一个电报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方法一样,您需要处理新消息以获取位置。