[Telegram Bot] Can I get the user ip address with telegram bot? #130528
Replies: 2 comments
-
Nope, telegram doesn't let you get ip address directly, However, you could just add a website for verification purposes before they use the bot. Like a cloudflare captcha (just saying) Then with that,
|
Beta Was this translation helpful? Give feedback.
-
While you can't directly get user IP addresses from the Telegram bot API, you can use external web services to approximate user locations and implement your banning logic based on that information. Telegram Bot Sends Link from telegram import Bot, Update
from telegram.ext import CommandHandler, Updater
def start(update: Update, context):
update.message.reply_text(
"Click this link to continue: http://your-web-service.com/capture_ip"
)
updater = Updater('YOUR_BOT_API_TOKEN', use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
updater.start_polling()
updater.idle() Web Service to Capture IP from flask import Flask, request, redirect
app = Flask(__name__)
@app.route('/capture_ip')
def capture_ip():
user_ip = request.remote_addr
# Store the IP address and perform the necessary action (e.g., logging or banning)
return redirect('https://t.me/your_bot')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000) |
Beta Was this translation helpful? Give feedback.
-
Body
I am an experienced blockchain & telegram bot developer and now in progress of developing a telegram bot.
I need to implement a feature that bans the users of specific locations with IP address.
Furthermore, I want to know it is possible to get the IP address with telegram bot.
Looking forward to your advice. Thanks.
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions