https://discord.gg/botpress logo
Get the city according to the ip
# 🤝help
g
When the user starts the conversation with the bot, it makes an API call to ipinfo.io obtains the IP address and that data is saved in a table with the name of the requestor's city (In theory it should work like this) But... it registers me US IP's, such as: 3.235.40.22 52.90.95.114 3.85.203.182 I tried different devices, but I don't know what it could be. https://cdn.discordapp.com/attachments/1261392659935793193/1261392660124663909/image.png?ex=6692caf5&is=66917975&hm=71dccb5ccf7b346542052c8abe30006e1448b80a72ad842ac6569ac1a2f5d986& https://cdn.discordapp.com/attachments/1261392659935793193/1261392660371869857/image.png?ex=6692caf5&is=66917975&hm=8f4fc82b3ca783de5c875f821f450bad12cec6a6e1ccbe28793aa1efed9e8caa&
s
Hi, In general, it looks like you are running the code in the Execute Code. This means you run it on the server (cloud), so ipinfo gets the IP from the server because the bot runs inside the iFrame. When you open the you will see: ...return`<**iframe** id="${o(t.chatId)}"... To get the user's IP address and the location (network provider's IP address location), you must execute that code on your page as javascript (in the user's browser). Next, send the location info to your bot inside the payload when you start the chat - use Custom Trigger to start the chat and receive the payload.
g
Thanks for the clarification. For context: I get the user's data when they interact with the bot through WhatsApp, is there a way I can develop the above without having a website? Can I run the code elsewhere? Excuse me, I don't know a little about the subject
s
I'm not sure if it's possible to do it as you want. If you use WhatsApp API, it requires explicit user consent and interaction so he would have to share the location with you. It should not be possible to read his location without his action. As you know, Users can manually share their location through WhatsApp. This can be done using the "Share Location" feature in the WhatsApp app. Once the user shares their location, it is sent as a location message, which can be received and processed by the WhatsApp Business API - so you can read it and use it. I don't think there is a passive reading of his WhatsApp (mobile) location.
2 Views