μ-bot
🤖 Zero-configuration Telegram bot runner
Documentation
micro-bot
was built on top of Telegraf
library.
Installation
Install from NPM:
$ npm install micro-bot
Scaffolding
If you have installed latest yarn
or npm
you can use create-bot
scaffolding tool:
$ npm init bot smart-bot$ cd smart-bot
Or using yarn
:
$ yarn create bot smart-bot$ cd smart-bot
Quick start
The following example will answer with important information about everything.
$ mkdir smart-bot$ cd smart-bot$ npm init$ npm install micro-bot --save
Then write your index.js
.
module
Then in your package.json
:
"main": "index.js""scripts": "start": "micro-bot"
To run the bot, use the micro-bot
command:
$ BOT_TOKEN='TOKEN' npm start
or
$ micro-bot -t TOKEN index.js
To run the bot with webhook support, provide webhook domain name:
$ micro-bot -t TOKEN -d yourdomain.tld echo.js
Supported environment variables:
process.env.BOT_TOKEN
- Bot tokenprocess.env.BOT_DOMAIN
- Webhook domain
now
Deployment to Let's deploy your micro-bot
with Realtime global deployments by Zeit.
First, install now
$ npm install now -g$ now login
Finally use now
to deploy:
$ now -e BOT_TOKEN='YOUR BOT TOKEN'
Congratulations, your bot is alive! 🎉
Deployment to Heroku
Okay, now we will deploy our micro-bot
to Heroku. Why not?!
First, install heroku binaries
and login via console.
Then, init new git repo:
$ git init$ heroku create
Afterwards, update Heroku config:
$ heroku config:set --app YourAppId BOT_TOKEN='YOUR BOT TOKEN'$ heroku config:set --app YourAppId BOT_DOMAIN='https://YourAppId.herokuapp.com'
Then add Procfile
into the root of your project, with one line:
web: micro-bot -p $PORT
Finally use git to deploy:
$ git add index.js package.json$ git commit -m 'initial commit'$ git push heroku master
Example μ-bots
- 🔥 Glitch example
@uncover_bot
- Source code@epub2mobi_bot
- Source code@gorchichkabot
- Source code@aloudbot
- Source code
Advanced Examples
const mount reply = moduleexports =
const readFileSync = const Composer = const bot = botstart ctxbotbotbot // Export bot handlermoduleexports = bot // Or you can export hash with handlers and optionsmoduleexports = bot: bot { console } { console } options: telegram: agent: 'proxy url' tlsOptions: key: cert: ca: // This is necessary only if the client uses the self-signed certificate.
Stages & Scenes
const Composer Stage Scene session = // Greeter sceneconst greeter = 'greeter'greetergreetergreetergreeter const stage = stage const bot = botbotbotbotmoduleexports = bot
Credits
micro-bot
is highly inspired by Micro