In this project, I built a Telegram Bot that can search on Wikipedia/Google domains or get you 3 random Wikipedia articles. It also sends you random funny Gifs every time you write something else in the chat or you use the /start and /stop commands. The main goal is to make a massive use of external API`s by putting into practice the main concepts of Object Oriented Programming, classes, modules, objects and accessing their attributes.
The project is built using the TDD technique.
The Bot is live on Heroku, you can check him here: Master Search Bot
Live version of the code: REPL.it
/start
receive a greetings message, all available commands and a funny random Gif/stop
receive a farewell message, a nice joke and a funny random Gifsearch wiki <your query>
receive a loading message and maximum 3 Wikipedia articles related to your search querysearch wiki random
receive 3 random Wikipedia articlessearch google <your query>
receive a loading message and maximum 3 articles from the Google Domain Websites (not a regular google search)- Writed anything else in the chat and you will be informed about the available commands and receive a random funny Gif
Here is the video explanation of this project.
- Ruby
- Telegram API
- Wikipedia API
- Tenor Gif API
- RSpec
- Rubocop
- colorize
- dotenv
- httparty
- telegram-bot-ruby
To get this project up and running locally, you must have ruby installed on your computer.
To get this project set up on your local machine, follow these simple steps:
Step 1
Navigate through the local folder where you want to clone the repository and run
git clone git@github.com:cristianCeamatu/microverse-ruby-telegram-bot.git
. It will clone the repo to your local folder.
or with https
git clone https://github.com/cristianCeamatu/microverse-ruby-telegram-bot.git
.
Step 2
Run cd microverse-ruby-telegram-bot
Step 3
Run bundle install
to install the gems from the Gemfile
.
Step 4
Download the Telegram app, create an account and talk to the Botfather. Follow the instructions and create a bot, you will then receive an API Token that looks like this: 1347431199:AAH4hPt6PDiJB4swk23Lb4oOzwocjKpba0S4
and the link to your bot.
Step 5
Visit Tenor API page and follow the quickstart steps to get a Tenor API Key.
Step 6
Visit Google API page and follow the quickstart steps to get the API token.
Step 7
Run touch .env
on your terminal to create the .env
file. Then add your tokens in the required fields TELEGRAM_BOT_TOKEN=
and TENOR_API_TOKEN=
inside the file.
Step 8
Run ruby bin/bot.rb
to start the bot.
Step 9
Open the link to the bot that you received from the Botfather.
Step 10
You can use the commands defined in the Available commands section defined above.
The code for the project is divided into the following directories: ./bin, ./lib, and ./spec.
The ./bin folder contains the executable bot.rb file.
The ./lib folder contains subsidiary files that set up all of the classes and methods used in bin/main.rb
- search.rb, where the Search class is defined.
- utils.rb, where the Utils module is defined.
- responder.rb, the Responder class that takes the messages and delegates responses.
- bot_replies.rb, where the BotReplies module includes together all the other reply modules.
- bot_command_replies.rb, where the BotCommandReplies module is defined.
- bot_search_replies.rb, where the BotSearchReplies module is defined.
The ./spec folder contains all the relative spec tests
- search_spec.rb, where the tests for the Search class are defined.
- utils_spec.rb, where the tests for the Utils methods are defined.
- spec_helper.rb, initial file generated by the RSpec.
In addition to the above, the repo also contains .rubocop.yml for linting.
-
Open Terminal
-
Install RSpec on your system by running:
gem install rspec
-
Run the tests with the command:
rspec
👤 Cristian Viorel Ceamatu
- Email: cristian.ceamatu@gmail.com
- Github: https://github.com/cristianCeamatu
- Twitter: https://twitter.com/CristianCeamatu
- Linkedin: https://www.linkedin.com/in/ceamatu-cristian/
Our favourite contributions are those that help us improve the project, whether with a contribution, an issue, or a feature request!
Feel free to check the issues page to either create an issue or help us out by fixing an existing one.
If you've read this far....give us a ⭐️!
This project is licensed by Microverse and the Odin Project