Skip to content

A Simple Telegram Bot written in Ruby to search for nearby restaurants

License

Notifications You must be signed in to change notification settings

barbaramartina/ruby-telegram-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GiveMeFoodBot for Telegram

Disclaimer

I'm not mantaining this project for a longggg while, feel free to fork or do a PR if you spot any issue. I hope it helps anybody out there who need a quick detailed guide to start with Telegram Bots.

A simple Telegram bot written in Ruby to search for nearby restaurants.

This is an initial pilot project to create Telegram bots.
I'd like to share the project so it can help anybody else interested in getting into the development of bots for Telegram or any other platform.
I share my project under GPL License, so everybody can reuse and modify it.

Important note

This Bot is LIVE for Telegram under the name @GiveMeFoodBot.
But it's not intented to be used widely, due to the limitations on the implementation and deployment server I've choosen.
The Bot is running using a FREE Dyno on Heroku, which means it won't be up always, because FREE Dynos like sleeping .
In addition, it's in my plans to extend the bot further, so it will be for sure unstable in several moments.

All contributions and ideas are welcomed.

Step by Step project explanations

For the persons new to Ruby and BOTs, like me, here are some explanations about how I created the project from scratch.

I'll cover the following points, giving examples taken from this project:

  1. Creating your bot in Telegram.

  2. Creating the first ruby file for your bot.

  3. Requiring and installing external ruby gems.

  4. Generating Gemfile.

  5. Generating Gemfile.lock.

  6. Completing your first ruby file with meaningful code for running bot services.

  7. Deploying your bot.

    a. Registering to HEROKU.

    b. Installing Heroku Command Line Interface (CLI), formerly HEROKU Toolbelt.

    c. Creating your bot app in HEROKU using Toolbelt from the command line.

1. Creating your bot in Telegram

The first thing you need to do is to contact BotFather.
You can follow the link above for detailed explanations from the Telegram docs about how to create your app.
This will register your bot app with Telegram. At this moment is not required to have any code or anything ready, you just will tell BotFather that you want a new bot to be created, he'll register the name you've choosen and will give you a TOKEN that is the first thing you need to connect from your code to Telegram Bot API.

Here I'll present the minimum steps you need to perform at least.

  1. Start the bot tipying @BotFather in Telegram.

BotFather

Or alternatively go to this URL and it will ask you if you want to start a conversation with botfather BOT FATHER URL

You can also start a new conversation, typing "botfather" as the name of the contact.

  1. Execute /newbot.

newbot

  1. Receive your TOKEN and save it.

token

  1. See more steps in the docs folder.

You can also query the bot father for more help with the /help command

morehelp

2. Creating the first ruby file for your bot

Create an empty file in any aproppiate folder in your system. As example from this project:

../src/GiveMeFood.rb

3. Requiring and installing external ruby gems

We need to say which ruby gems we'll be using. Add the following lines at the beginning of GiveMeFood.rb

require 'telegram/bot'
require 'google_places'

Current project dependencies

In the case of this project, I'm using:

Versions

gem 'google_places', '0.32.0'
gem 'telegram-bot-ruby', '~> 0.5.0.beta4'

Install RubyGems

RubyGems is a package management tool, if you don't have RubyGems installed in your system, follow this link and install it: https://rubygems.org/pages/download

After installing RubyGems, go ahead and install the gems required for this bot.

Open the terminal and type the following commands, one per time:

gem install google_places  
gem install telegram-bot-ruby

The previous commands will install the gems in your system.

4. Generating Gemfile

Go to the root folder of your ruby main file, GiveMeFoodBot.rb and execute:

bundle init

You will see a log like the next one:

bundleinit

5. Generating Gemfile.lock

In the same folder as the last step execute:

bundle install

You will see a log as the following:

bundleinstall

6. Completing your first ruby file with meaningful code for running bot services

See the code inside GiveMeFoodBot.rb as an example. Or check the github repos for the Ruby Telegram BOT API in Ruby I used to have an idea about what you can do.

7. Deploying your bot

These steps are specific to the server I've used for deploying my bot.

You can choose to deploy your bot anywhere else, on your personal PC is a good idea until you have it running, but you could also choose another server or a Raspberry Pi for example. Check out the useful links at the end of the README.

a. Registering to HEROKU.

Go to HEROKU and sign up for a FREE account.

b. Installing Heroku Command Line Interface (CLI), formerly HEROKU Toolbelt

Go to Heroku Command Line Interface (CLI), download and install in your computer.

I did everything in OSX El Capitan with the command

brew install heroku

c. Creating your bot app in HEROKU using CLI from the command line

Here are the steps you need to follow using the Heroku CLI.

1. From the root folder of your bot project execute in the terminal:

heroku login

login

The previous will install the CLI and store your credentials to make any future change with heroku to be already authenticated. See more information in the section Getting Started

2. Execute create app command:

heroku create 'yourAppName'

create

3. Clone the repo created for you:

git clone 'yourRepoURLHerokuGAVEYou'

clone

4. Add the ruby buildpack required by HEROKU execute:

heroku buildpacks:set heroku/ruby

builpacks

5. Go to your repo main folder, add all your code if it was not added before and execute push to the main repo.

The main repo can be renamed to heroku (the name you will see in all the documentation) but you can keep it to origin or anything else you want.

push all code

6. Check the warnings if any.

In my case I had not set the Ruby version. So I added it to my Gemfile:

ruby '1.9.3'

And I had not created a VERY IMPORTANT FILE SO YOUR BOT CAN RUN ON HEROKU so I created the Procfile.

procfile 1 procfile 2

7. ALL SHOULD BE RUNNING AND READY ON HEROKU BY NOW

To check your app is running do the following:

 a. CHeck your app was created.  

created app

b. Check your app was recognized as a bot and the command you put in *Procfile* is OK.    

bot config

c.  Click EDIT and ENABLE your bot so it can start running.  

enable

d. CELEBRATE!! your bot is running.

Note about the docs folder

In the doc folder you will see screenshots for all the steps and errors I got while creating my app in HEROKU using ToolBelt and the troubleshooting I did for having my bot running in HEROKU.
Go there and check in order every image file you find. Are enumerated following the process I did.

#Useful links I've found in my way while creating the project

About

A Simple Telegram Bot written in Ruby to search for nearby restaurants

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages