Introduction
Telegraf-CLI is a command-line interface tool designed to simplify the development process for developers who are working with the Telegraf library. The Telegraf library is a popular framework for building Telegram bots, and Telegraf-CLI provides developers with a streamlined way to generate boilerplate code for their projects and to generate bot commands.
With Telegraf-CLI, developers can save time and effort by automating the creation of basic project structures and boilerplate code. This means they can focus more on the development of their Telegram bots rather than spending time setting up their development environment.
Features
Generate Basic Project Structures
JavaScript Template/Boilerplate (TypeScript coming soon)
Work out of the box with different Node.js servers (Express, Koa, Fastify)
Development and Production Ready
More Coming...
Installation
# through npm
$ npm i telegraf-cli -g
# through yarn
$ yarn add telegraf-cli -g
Usage
Telegraf CLI can be used using telegraf-cli
longhand or tcli
shorthand.
$ telegraf-cli [command]
$ tcli [command]
Available Commands
-y, --yes Create new telegraf template (default)
-n, --new [name] Create new telegraf template
-c, --create:command [name] Create new telegraf bot command
-v, --version Output the version number
-h, --help Output usage information
-u, --update Update telegraf-cli version
Example Usage
Example 1
# bootstrap project using the default template/boilerplate
$ tcli --yes
Generating Bot-f13038...
√ #1 Generate telegraf bot project
√ #2 Initialize a git repository
√ #3 Install dependencies
STEP 1: Run the following command(s)
1. cd Bot-f13038
STEP 2: Configure Bot-f13038 project
1. For development - create `dev.env` file and paste the content inside `example.dev.env` into it.
2. For production - create `prod.env`` file and paste the content inside `example.prod.env` into it.
Open `dev.env` and `prod.env` and update your environments variables.
STEP 3: Start Telegraf bot
1. For development - npm run dev:bot
2. For production - npm run prod:bot
DONE
Example 2
# bootstrap project using one's preferred choice
$ tcli --new PizzaBot
Generating PizzaBot...
? Please choose which telegraf template to use? Simple
? Please choose which Node.js server to use? None
? Please choose which language to use? JavaScript
? Initialize a git repository? No
? Install dependencies? No
√ #1 Generate telegraf bot project
STEP 1: Run the following command(s)
1. cd PizzaBot
2. git init
3. npm i
STEP 2: Configure PizzaBot project
1. For development - create `dev.env` file and paste the content inside `example.dev.env` into it.
2. For production - create `prod.env`` file and paste the content inside `example.prod.env` into it.
Open `dev.env` and `prod.env` and update your environments variables.
STEP 3: Start Telegraf bot
1. For development - npm run dev:bot
2. For production - npm run prod:bot
DONE
Example 3
# create bot command
$ tcli --create:command orderPizza
Creating orderPizza command...
[INFO] Command orderPizza successfully generated.
DONE
Configuration
Configure Telegraf CLI Project
For development - create
dev.env
file and paste the content insideexample.dev.env
into it.For production - create
prod.env
file and paste the content insideexample.prod.env
into it.
Open dev.env
and prod.env
and update your environment variables.
Start Bot
Start Telegraf CLI Bot
# for development
npm run dev:bot
# for production
npm run prod:bot
Register Commands
To register a new command created using tcli --create:command
, open registerCommands.js
and register it as below.
// assuming the new command is orderPizza
// import the new command
const { orderPizza } = require('./src/commands/orderPizza')
/**
* @description
*
* @param {*} bot
* @returns {void}
*/
exports.registerCommands = (bot) => {
// register commands
start(bot)
// register the new command here
orderPizza(bot)
}
Contributors
Many thanks to all our contributors.
- Obafunso Ridwan Adebayo
To contribute to this project, please check CONTRIBUTING.md
on GitHub
Useful Links
GitHub: https://github.com/0xridwanobafunso/telegraf-cli
NPM: https://www.npmjs.com/package/telegraf-cli
Thanks for reading ❤️