The fundamental bits are there, and that means you can swap them on and stretch them easily.
The section to pay attention to whenever modifying are the when /command/i traces, additionally the text between your estimates about reply.txt lines. These represent the inputs the robot allows, and also the meages they directs straight back as responses.
Therefore, any time you desired to state something different as an answer on the /greet order, you’d alter the worth of reply.text underneath the greet demand line ( whenever /greet/i ). Here’s a variation you could try:
Here, I’ve created an array with a few different ways to state hello, following included anyone to the meage randomly using the sample technique.
Switching the robot into something awesome
You can include as numerous directions, reactions, and features towards robot as you wish. Almost all of it is creative imagination, and lots of Googling as you run. If you’d like to learn many things which are relevant to the bot, start out with realize Ruby the difficult way of getting to grips together with the requirements of vocabulary. With a touch of application and an excellent reliance on StackOverflow, you’ll be able to:
- Connect more APIs to get data from means like Airtable, Slack, R, or Twitter. That is where the really interesting functionality comes in — it is possible to create a bot that acts as a conversational program to a couple of data or qualities, like a bot that returns google search results from Twitter or articles to Slack.
- Shop consumer input in a database. You could potentially develop a Telegram robot that offers automatic assistance to consumers or responds to question, and sites her e-mails addrees in a database. The follow up gem makes it simple to generate, write, edit, and study databases.
- Create a book adventure.Coloal Cave Adventure, one of the first terminal video games, is ported over to Telegram as a bot. Take a visit here, to see the origin right here.
If you need inspiration, you can read some other people’s bot origin rule, and look a list of Telegram spiders — just be sure to work out how they work and replicate them as application.
Working the bot 24/7
Immediately, your bot try working in your terminal on your desktop. That’s okay before you want to restart your pc, your wi-fi falls, or your pc goes toward rest. Whenever that happens, it terminates the bot’s proce and people won’t have a reply as a result.
The proce of move their robot from a development conditions (your desktop in which you made use of Atom to write the robot) to a creation atmosphere (a servers) is called deployment. There are a few alternatives for deploying their bot, however in both cases we’re attending start with publishing the data files to Bitbucket. Bitbucket lets you incorporate git, a version controls program that can help one safely make and track adjustment towards bot’s signal. By posting their bot’s documents to Bitbucket, you should use Bitbucket in an effort to grab the bot’s data when you’re signed into the variety.
Subscribe to Bitbucket and develop a repository.
With terminal available plus the same directory site as the bot’s source laws, kind the immediate following:
git init git combine . git commit -m ‘initial devote’
Today, follow the guidelines shown by Bitbucket after putting some latest repository. Mine is:
After getting into those two highlighted commands during my terminal and promoting my personal Bitbucket paword whenever requested, the documents become published. With your rule residing the affect, it’s for you personally to select a way to deploy.
Deploying with a Raspberry Pi
A Raspberry Pi is a great expense if you are considering creating and deploying bots — you can get one from only $7 as well as the price of a SD card. They makes use of little power, so you’re able to keep it on all the time and never be concerned with the cost. It might be tempting purchasing a bundle that accompanies a keyboard, mouse, and situation but you just need a USB charger, facts, ethernet cable tv therefore the computer by itself. You most likely have actually these types of circumstances in your office already.
Deploying with an affect server
You don’t must meet an inmate have the pc that your robot try operating on, you need the memory and energy of someone else’s equipment to perform the robot from another location. Well-known systems for deploying for the cloud integrate Amazon online solutions (AWS), DigitalOcean, and Heroku.
Outside of the three, many entry-level is DigitalOcean and Heroku. View here in order to get a DigitalOcean levels that comes with ten bucks of credit — adequate to operate a server for two several months whilst you test it out.
Once you join Digital Ocean and develop an innovative new droplet, you’ll learn to connect with the host via H and introduce the unit.
From this point, it is equivalent proce just like you did in your local machine regardle of this server you are really making use of. In the end, it’s simply a bash terminal. With some form of server created, let’s push onto the real deployment.
The implementation proce
On a brand new server — whether that’s a Raspberry Pi or an affect server like Digital Ocean — you’ll have to install Ruby, Bundler, and Git:
sudo apt-get improve sudo apt-get upgrade curl -L bring.rvm.io | bash -s stable –ruby sudo apt-get apply bundler sudo apt-get install git
And then make a new index for your bot, navigate there, and install the files from Bitbucket utilizing the following instructions:
mkdir bots cd bots git clone ://[email secured]/benjbrandall/telegram-bot.git
Make the time to replace the Address above (benjbran…) because of the Address of bot’s repository on Bitbucket. You’ll discover the entire clone command through Bitbucket, and that means you won’t have to do that bit by hand.
Following, means bundle to install the treasure dependencies, following ruby bot.rb to start out the robot running permanently.
Note: if you’re acceing your servers via H, you’ll must operated the robot with nohup ruby bot.rb & to make certain the robot does not are amiss whenever the H seion try ended. Now you’re free to close the terminal windows, safe within the facts that the bot is gently beep booping away from inside the credentials. ??
That concludes the first stab at a Telegram bot. Along the way, your learned about the terminal, Ruby, treasures, the Telegram API, and how to deploy a bot to a server. Any queries or recommendations? You can meage me on Twitter.