With this in place, let’s get going. Download the Telegram app for desktop

Telegram is predominantly a cellular app, however for development reasons you’re likely to want it attached to alike device you are really using for creating rule. That way, you’ll be able to rapidly check it out without unlocking your telephone every time. And, you’ll be able to copy and paste your Telegram bot’s API crucial straight to the text editor.

Time to grab that API key!

2: talk with the BotFather getting the API key

Telegram bot design try a novel proce because most of it is concentrated around a relationships with a Telegram bot. That robot could be the BotFather. Within your Telegram desktop computer application, you will need to bing search their login name and start a discussion with your.

Supply the begin command to BotFather by typing /start .

You’ll read a list of instructions which help you create, change, and control your own bots. Because it’s your first opportunity, you’ll need /newbot .

When compared to proce for constructing a Twitter robot, a Mastodon robot, or any other types of robot I’ve tried, Telegram helps make the preliminary set-up a breeze. I gue that proves exactly what a good means Telegram spiders is!

After giving the /newbot order, you’re able to pick a reputation and login name for the bot. The name is what your own customers will dsicover the robot like in their particular connections checklist, together with username try how they’ll think it is. Think of the username like a Twitter handle; it has to end up being unique, therefore’s most useful in the event it’s short and remarkable.

With this finished, you’ll get your bot’s API trick. The API secret are how Telegram knows the rule you write is actually aociated with this particular bot. Every robot has its own API trick, and you need ton’t show it with https://hookupwebsites.org/oasisdating-review anyone or they could hijack your robot while having it carry out their evil deeds.

That concludes the talk to BotFather for the time being — on the rule!

Step 3: Setting up the bot’s gems and directory site

Open terminal, and manage mkdir telegram-bot . This produces another directory site to suit your bot’s data. It’s best to have them restricted to just one folder as a result it’s easy to handle. Demand directory site with cd telegram-bot and do the next:

touch Gemfile touch bot.rb atom .

This creates two blank documents, one for specifying the gems you’ll demand plus one where bot’s signal will living. The last order opens up both these data in Atom.

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

This tells Bundler to grab the Ruby user interface to your Telegram API from rubygems.

To accomplish the gem create, return to your own terminal and type bundle . Here’s what you should see:

That’s they when it comes to jewel set-up, today we’re eventually getting onto the rule.

Programming your first Telegram robot

The particular rule which is going to feel running consistently throughout the host is inside bot.rb. It’s vacant today, but right here we’re going to connect when you look at the Telegram gem we simply included and develop a bot.

It’s very little signal to write. By the point you’re complete, it’s this that you’ll posses:

In Telegram, this is what the laws above does:

Let’s check exactly what each part of the signal do and create it we run.

(substitute the TOKEN using API token you duplicated from BotFather)

Ruby makes it quite easy to gue exactly what laws will perform. The 3 outlines above add the Telegram robot efficiency towards file and build an innovative new robot object from the Telegram robot cla, authenticated along with your token therefore the regimen understands the best place to submit the information.

The next component is certainly one larger circle. It appears to be confusing to start with, but it’s an easy task to select apart.

The very first range says to the robot to help keep listening for directions. And, if it get a command to pa it towards the meage variable. The sets line logs the order your terminal so you can see what’s going on even though the bot runs.

The bot’s responses actions is kept in a situation declaration. The truth declaration’s feedback was provided through from meage adjustable after it’s been washed upwards by gem’s get_command_for method. The bot’s reply book is set with respect to the demand put after which eventually delivered with send_with ahead of the cycle restarts.

Using this set-up, you can now select your robot on Telegram and deliver the /start and /greet instructions, and watch it doing his thing.

To get this done, help save the alterations in Atom and operate ruby bot.rb for the terminal. So long as that terminal is open and run, their bot will be sending responses!

Customizing the glossy new bot

Related Posts

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée.