visit
Preparation
In the preparation stage, developers ought to gather all of the code that will be deployed along with any other libraries, configuration files, or resources needed for the application to function. Together, these items can be packaged as a single software release. Verifying that the host server is correctly configured and running smoothly should also be considered here.Testing
Before an update is pushed to the live environment, it should be deployed to a test server where it will be subjected to a pre-configured set of automated tests. Developers should review the results and correct any bugs or errors before deploying the update to the live environment.Deployment
Once an application or an update has been fully tested, it can be deployed to the live environment. Developers may run a set of scripts to update relevant databases before changes can go live. The final step is to check for bugs or errors that could occur on the live server to ensure the best possible customer experience for users.STEP I:
Create a file named Procfile on the root directory of the project and add the following codes as follows:
In Procfile file;
web: ruby my_app.rb -p $PORT
worker: bundle exec ruby bin/main.rb
Within the project root directory, create another file called my_app.rb and add the following codes as follows:
STEP II:
In my_app.rb file;
require 'sinatra'
get '/' do
redirect '//bot_url_from_BotFather', 303
end
STEP III:
Go to Gemfile and add the snippets below:
In Gemfile, add gem sinatra;
gem 'sinatra'
STEP IV:
Then run bundle install
web: ruby my_app.rb -p $PORT
checks whether the app has been sent to the web. If the app is sent to the web, then it means the app has been deployed to Heroku.worker: bundle exec ruby bin/main.rb
checks whether the bot is sent to the worker. If the bot is sent worker, then it means the bot has been started automatically.Remember to replace
ruby bin/main.rb
with whatever command that starts your bot locally. ruby bin/main.rb
does the trick on my case.redirect
'
', 303
=> this line of course redirects the bot to Telegram.STEP V:
Now, let’s create an app on Heroku…Run
heroku create <name_of_your_bot>
from your terminal.NB: <name_of_your_bot> is actually optional. It’s required if you want your bot to have a unique url on Heroku since Heroku randomly assigns a weird url. <name_of_your_bot> could be anything but ensure the words are separated with a hyphen (-). An example is comic-telegram-bot.
STEP VI:
Then run
git push heroku master
to push your bot to Heroku.Run
git push heroku <current_branch>:master
instead if you’re currently not on the master branch.<current_branch> is the name of your current branch.STEP VII:
Once you’ve pushed successfully, run
heroku ps
to view your app's dyno settings i.e to check if the app is sent to the web and if the bot is sent to the worker.Remember: If the app is sent to the web, that means the app has been deployed to Heroku and if the bot sent the worker, then it means the bot has been started automatically. If everything works out fine, then both web and worker should be equal to 1.If the web isn't 1 and the worker isn't also 1, run
heroku ps:scale web=1 worker=1
to fix it.STEP VIII:
Remember to go to settings on your Heroku dashboard and add the ENV variable if there's any.
For instance, in my case, I have TOKEN = ‘my_telegram_API_key’ in dot.env file. So I'd want to login into . Then I’d click on the app name and go to settings on my dashboard. Then I’d click on Reveal Config Vars and of course, add TOKEN as the KEY and my_telegram_API_key as the VALUE. Then click on Add.
STEP IX:
Once the ENV variable is added successfully, go ahead and click on Open app. This should redirect you to Telegram, ensure you click Open when it’s prompted.
Now, you can interact with your bot live and have fun without having to start it locally.NB: You do not have to add ENV variable if your API key is not encrypted. In other words, it’s needless trying to add ENV variable in Heroku if your API key is hardcoded.
Take note of this also: The bot goes to sleep after some time, like 1 or 2 hours or so. To avert this issue, login into Heroku and click on Open app. This way, the bot would be live again.
There's actually a way to go around this, I'll definitely update this article as soon as I find a solution. If you wish you can check out my Telegram bot and the source code is .For questions, suggestions, and contributions, reach out to me on…Email: [email protected]
Also published at