You must have heard or used telegram bots
now the deep question is how are they created
We are going to see to that get your ide ready cause we gonna create a bot in 5 minutes
Requirements
- A ready good ide with Ruby installed
- basic or advanced knowledge in Ruby
- bot token from @botfather
If you don’t know how to get your bot token check out this post 👉 telegram_token
After getting you token
Create a GEMFILE
source 'https://rubygems.org'
gem 'telegem', '~> 3.0.4'
gem 'dotenv', '~> 2.8'
#add any other gem you wish httparty nethttp json e.t.c
if using bundle use
$ bundle install
or gem if using gem
$ gem install
it’s pretty much recommended to use bundle but gem still works
- next let’s create our file create a .env file with your token
BOT_TOKEN=11234:445849489449
replace with your actual token
#bot.rb
require 'telegem'
require 'dotenv/load'
bot = Telegem.new(ENV['BOT_TOKEN'])
bot.command("start") do |ctx|
ctx.reply("welcome to test2bot")
end
bot.command("help") do |ctx|
ctx.reply("**u need help**", parse_mode: 'Markdown')
end
bot.start_polling
puts "bot has started"
$ bundle exec ruby bot.rb
this is all to a simple bot with /start command
/help
for more in-depth tutorial
check 👉 more-rut
Top comments (0)