ORARI CENTRO e CONTATTI

Martedì: 9:00-19:00

Mercoledì: 13:00-22:00

Giovedì: 9:00-19:00

Venerdì: 9:00-19:00

Sabato: 8:30-16:00

Domenica e Lunedì: Chiuso

Estetica Sima

With this in position, let’s progress. Install the Telegram app for pc

With this in position, let’s progress. Install the Telegram app for pc

Telegram is mostly a mobile software, however for developing needs you’re gonna want it mounted on the same machine you are really utilizing for creating code. In this manner, possible easily check it out without unlocking your own telephone whenever. And, you’ll be able to replicate and paste their Telegram bot’s API crucial into their book publisher.

Time for you seize that API key!

Step two: speak to the BotFather to obtain their API key

Telegram bot design try an unique proce because much of truly centered around your very own connections with a Telegram robot. That bot could be the BotFather. As part of your Telegram desktop app, you ought to query their username and start a conversation with him.

Allow the beginning demand to BotFather by typing /start .

You’ll discover a summary of directions that can help you create, revise, and regulate their bots. As it’s very first opportunity, you’ll wish /newbot .

When compared to proce for design a-twitter bot, a Mastodon robot, or just about any other variety of bot I’ve tried, Telegram makes the preliminary set-up a breeze. We gue that shows just what a fantastic tool Telegram bots tends to be!

After providing the /newbot order, you get to select a reputation and username for your robot. Title is really what their users might find the robot as with their contacts number, therefore the login name try how they’ll think it is. Think about the login name like a-twitter handle; it has to be special, therefore’s most readily useful whether or not it’s brief and unforgettable.

With that complete, you’ll be provided with your bot’s API secret. The API trick are exactly how Telegram understands the code you create try aociated with this particular bot. Every robot features its own API trick, and you ought ton’t promote they with anybody or they could hijack the bot and also have they complete their wicked deeds.

That concludes our very own chat with BotFather for the time being — on the rule!

Step three: installing the bot’s gems and directory site

Start terminal, and would mkdir telegram-bot . This brings a service for your bot’s records. it is best to have them confined to 1 folder so it’s simple to regulate. Demand directory site with cd telegram-bot immediately after which do the utilizing:

touch Gemfile touch bot.rb atom .

This produces two empty records, one for indicating the gems you’ll demand and something where bot’s laws will reside. The very last demand starts both these data files in Atom.

Click on the Gemfile in Atom’s sidebar, and paste this amazing in:

This says to Bundler to seize the Ruby program to your Telegram API from rubygems.

To complete the jewel setup, go back to your own terminal and kind package . Here’s what you ought to read:

That’s they your gem setup, now we’re at long last getting onto the code.

Coding the first Telegram bot

The actual laws which is going to getting working constantly on host is inside bot.rb. It’s empty today, but here we’re browsing link inside Telegram jewel we simply included and produce a bot.

It’s very little rule to publish. By the point you’re done, this is exactly what you’ll posses:

In Telegram, it’s this that the rule above do:

Let’s examine what every section of the laws does and create it as we run.

(swap the TOKEN utilizing the API token you copied from BotFather)

Ruby will make it rather easy to gue exactly what laws is going to do. The three outlines above create the Telegram bot efficiency towards file right after which make a new robot object through the Telegram robot cla, authenticated along with your token and so the program knows where to deliver the info.

The following component is certainly one big loop. It looks perplexing at first, but it’s easy to select apart.

Initial line informs the bot to help keep listening for instructions. And, whenever it get a command to pa they on meage varying. The throws line logs the order your terminal in order to discover what’s going on whilst bot operates.

The bot’s feedback actions include stored in an instance declaration. The scenario report’s input was provided through from the meage changeable after it’s already been washed right up because of the gem’s get_command_for system. The bot’s answer book is placed with regards to the order stored right after which finally sent with send_with prior to the circle restarts.

With this create, anybody can come across the bot on Telegram and send the /start and /greet directions, and see they in action.

To do this, save yourself the alterations in Atom and operated ruby bot.rb from inside the terminal. Assuming that that terminal try open and running, the robot will be sending answers!

Personalizing your own shiny new bot

Post a Comment