Hello, today we make simple Telegram bot on Ruby. We’ll find user (or sites) by IP address and will use
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.
- Start dialog with @BotFather
/newbotfor creating new bot
- Choose name and login for bot
- Get API KEY for further actions
Create and configure new bot
I choose name
IpInfoBot, but now we must choose login name.
After of all changes we have our API KEY and working 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:
Notice: Always use
message.chat.id 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 000.000.000.000 message. Change our ‘engine’ of our bot:
and make simple method for sending request to
We convert result of using
ip_info gem, because we have result:
Set comands for our bots:
And now we have fully working bot. Try in work our bot:
Find user by IP:
Find info about site:
Find country of 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