skip to Main Content

I am making a telegram bot api wrapper and was wondering how to get the user’s location. I have tried this:

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}]
         ]
        }
        }

and:

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

to make a thing to submit to my send_messages func which I got from: https://www.codementor.io/garethdwyer/building-a-telegram-bot-using-python-part-1-goi5fncay

How would I do that?

2

Answers


  1. First, you can only use request_location in private chat, make sure it is not send to group.

    If succeeded, user will send location as message, just like sendLocation method, you need to handle new message to get location.

    Login or Signup to reply.
    • For pyTelegramBotAPI users
    • For python-telegram-bot users:

      dispatcher.add_handler(MessageHandler(Filters.location, location))
      
      def location(bot, update):
          print(update.message.location)
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search