With this set up, let’s progress. Download the Telegram app for desktop


With this set up, let’s progress. Download the Telegram app for desktop

Telegram was mainly a mobile software, but for development needs you’re gonna desire it mounted on the same maker you’re making use of for composing signal. That way, possible quickly test that without unlocking your cellphone each and every time. And, you’ll manage to replicate and paste the Telegram bot’s API key into your text editor.

For you personally to seize that API secret!

2: Chat with the BotFather to obtain their API trick

Telegram bot production is actually a novel proce because a lot of its concentrated around a relationships with a Telegram bot. That bot may be the BotFather. In your Telegram pc app, you ought to google search their username and commence a discussion with your.

Supply the begin order to BotFather by entering /start .

You’ll see a list of directions that will you make, modify, and manage your bots. As it’s your first time, you’ll want /newbot .

Set alongside the proce for design a-twitter bot, a Mastodon robot, or other kind of bot I’ve attempted, Telegram helps to make the initial build super easy. I gue that proves exactly what outstanding device Telegram bots are!

After providing the /newbot demand, you reach choose a reputation and username for your bot. Title is really what their people will dsicover the robot like in her associates number, as well as the username try how they’ll believe it is. Consider https://hookupwebsites.org/menchats-review/ the login name like a-twitter handle; it has to be special, and it also’s well when it’s small and memorable.

With this done, you’ll be given your own bot’s API key. The API secret is actually exactly how Telegram knows the rule your compose was aociated with this bot. Every bot features its own API secret, and you shouldn’t communicate it with any person or they are able to hijack their robot and possess it carry out their particular evil deeds.

That concludes our speak to BotFather for the present time — onto the code!

3: establishing the bot’s jewels and index

Start terminal, and do mkdir telegram-bot . This produces another directory to suit your bot’s data. it is far better have them restricted to 1 folder so it’s easy to handle. Demand index with cd telegram-bot after which do the utilizing:

touch Gemfile touch bot.rb atom .

This brings two blank files, one for indicating the gems you’ll want and something where in actuality the bot’s signal will live. The past order opens up both of these documents in Atom.

Click the Gemfile in Atom’s sidebar, and paste listed here in:

This informs Bundler to seize the Ruby interface for the Telegram API from rubygems.

To accomplish the gem setup, return to their terminal and type bundle . Here’s what you should read:

That’s they for any treasure build, now we’re eventually obtaining onto the rule.

Coding very first Telegram robot

The specific rule which will feel run consistently throughout the machine was inside bot.rb. It’s vacant at this time, but here we’re planning link within the Telegram jewel we simply bundled and produce a bot.

It’s not much rule to create. By the time you are really completed, this is exactly what you’ll bring:

In Telegram, this is what the code above do:

Let’s glance at exactly what every part of the rule do and compose it we get.

(exchange the TOKEN with all the API token you duplicated from BotFather)

Ruby helps it be really simple to gue just what signal perform. The 3 lines above add the Telegram bot features to your file right after which write a fresh robot object from the Telegram Bot cla, authenticated along with your token so that the program understands where you can deliver the data.

Another role is but one big cycle. It appears to be perplexing at first, it’s very easy to pick aside.

1st line says to the bot keeping paying attention for instructions. And, with regards to obtains a command to pa it to the meage adjustable. The places range logs the command towards terminal to discover what’s taking place even though the bot operates.

The bot’s reaction activities become kept in an incident report. The scenario report’s insight try given through through the meage varying after it’s started cleaned upwards of the gem’s get_command_for means. The bot’s reply book is placed with regards to the demand retained after which finally delivered with send_with before the circle restarts.

With this particular create, anybody can look for the bot on Telegram and deliver the /start and /greet directions, and watch they for action.

To work on this, rescue the changes in Atom and operate ruby bot.rb into the terminal. If that terminal is available and running, their robot will be sending feedback!

Customizing your glossy brand-new bot

With this set up, let’s progress. Download the Telegram app for desktop

Choose A Format
Story
Formatted Text with Embeds and Visuals
Video
Youtube, Vimeo or Vine Embeds
Image
Photo or GIF