In this project, I build a Telegram bot that gives a bit of information about me and gives random quotes and jokes.
- Ruby
- The Telegram Bot API
-
First, you need to get a telegram account at Telegram
-
Once you have an account, search for @BotFather, the Telegram bot-making wizard. This should open a chat with the BotFather.
-
Now type '/newbot' and send to start a new bot and follow the instructions. The BotFather will ask you to choose a username and give you an API token. Keep this token secret. It can be used to control your bot.
-
Fork this repo and clone to your local machine.
-
Cd into the repo and create a file in the main directory called 'token.rb'
-
Inside token.rb, type 'TOKEN' and set it equal to the API token you got from the BotFather. Make sure the API token is in quotes to make it a string.
-
Make sure you have Bundler installed in your machine. Once in the project folder (top level director), enter the command
bundle install
in your terminal. This will install the basic dependencies in the Gemfile. -
Now the rest of the app should run. Go to your terminal, cd into the 'bin' directory of the repo, and enter the command
ruby main.rb
. -
The bot should run. If you search for your bot by its username in Telegram, it should be ready to receive commands.
-
Currently, the bot responds to the commands 'start', 'info', and 'quote'.
-
'Start' will prompt the bot to give some basic info about itself.
-
'Info' will prompt the bot to give some basic info about the creator (me in this case).
-
'Quote' will prompt the bot to give a random inspirational quote.
-
'Joke' will prompt the bot to give a random funny joke.
-
Of course, you can alter the messages and commands in bot.rb to something you prefer.
##More Information
- for more information you can watch this video
- If you ran
bundle install
, RSpec should be installed, along with all the other dependencies. To run the tests, cd into the top-level project folder and enter the commandrspec spec/test.rb
. This will run all tests. It should be noted that the #make_request method is a private method, so its test will naturally fail. To make it pass, temporarily comment out theprivate
keyword in thequotes.rb file
. The tests should now pass. Once satisfied, uncomment it so that the #make_request method is private again.
👤 Ari Karim
Contributions, issues and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
This project is MIT licensed.