Find user by IP or simple bot for Telegram with Ruby

Hello, today we make simple Telegram bot on Ruby. We’ll find user (or sites) by IP address and will use ip_info

gem. Detail information about using gem you can read in github page

Create Telegram bot

Before of all you must create new telegram bot. It’s very simple, you can read more about it in official documentation.

Simple instruction:

  • Start dialog with @BotFather
  • Use /newbot for creating new bot
  • Choose name and login for bot
  • Get API KEY for further actions

Create and configure new bot

Write to @BotFather

New bot for Telegram

I choose name IpInfoBot, but now we must choose login name.

Set name for Telegram bot

After of all changes we have our API KEY and working bot.

Success created Telegram bot

For our bot we make simple Gemfile and we’ll use Telegram-bot-ruby it’s pretty awesome.

Simple usage of this gem:

If we’ll send /start message for our bot we have response: Hello, <your_name>

Notice: Always use for sending message, because your bot can used in group dialogs

I want make comands like /city <ip_address>. But I relly don’t know how to get <ip_address> from message in right way. For getting address form message we’ll use regex. Make simple method:

But we have /cite message. Change our ‘engine’ of our bot:

and make simple method for sending request to ipifodb site:

We convert result of using ip_info gem, because we have result:

Set comands for our bots:

Add comands for Telegram bot

And now we have fully working bot. Try in work our bot:

Find user by IP:

Telegram bot can find user by IP

Find info about site:

Telegram bot can find information about site

Find country of site:

Telegram bot can find information about site


We make simple bot for Telegram, it’s not hard but interesting. If you will try bot and it’s not available, maybe I was delete it 🙂 If you have another way to get address from message send pull request or send message.

Github Repo WScraping/ip_info_bot

Telegram bot: @ip_info_bot

Leave a Reply

Your email address will not be published. Required fields are marked *