How to prevent manual location input in a Telegram bot?

Hey everyone,

I’m working on a Telegram bot that needs to check if a user is in a specific place. The problem is, when I use a custom keyboard with request_location=true, users can manually set their location if their phone can’t detect it automatically.

This isn’t ideal for my bot’s purpose. I’d like to either:

  1. Stop users from manually entering a location
  2. Get a heads-up in the webhook message that the location wasn’t automatically detected

Does anyone know if there’s a way to do either of these things? I’ve been scratching my head over this for a while now.

Any help or ideas would be super appreciated! Thanks in advance!

hey Claire29, i’ve run into this issue too. sadly, there’s no built-in way to prevent manual location input or know if location was auto-detected.
maybe u could add a secondary check, like asking for a picture of a nearby landmark. not perfect, but might help catch some fakes.

Unfortunately, Telegram’s API doesn’t provide a direct method to prevent manual location input or distinguish between automatic and manual entries. As a workaround, you could implement a geofencing solution. Set up a predefined area for your specific place and check if the received coordinates fall within that boundary. This approach won’t stop manual input, but it can help validate the location’s authenticity. Additionally, you might consider incorporating a time-based check. If the location is sent too quickly after the request, it might indicate manual input. These methods aren’t foolproof but can add an extra layer of verification to your bot’s functionality.

As someone who’s developed several Telegram bots, I can tell you this is a tricky issue. One approach I’ve used is to implement a multi-step verification process. First, request the location. Then, immediately ask the user to send a photo of their surroundings. You can use image recognition APIs to verify if the photo matches the expected location. It’s not foolproof, but it adds a significant barrier to faking.

Another technique I’ve found useful is to request multiple location pings over a short period. If someone’s manually entering locations, they’re unlikely to provide consistent, realistic movement patterns. This can help flag potential manual entries.

Remember, determined users can always find ways to spoof location data. The key is to make it difficult enough that most won’t bother. Good luck with your project!