tg-builder
v0.1.17
Published
Builder library for the organisation of a lot of telegram bots.
Downloads
8
Maintainers
Readme
🤖TG Builder
tg-builder provides an intuitive builder pattern that allows developers to:
- Combine Multiple Bots: Run and manage several bots from a single codebase, each with their individual or shared functionalities.
- Shared Logic: Easily reuse logic across different bots, making your code more DRY (Don't Repeat Yourself).
- Modularity: Break down complex bot functionalities into manageable pieces, ensuring clean and readable code.
- Scalability: As your bot ecosystem grows, tg-builder scales with you, making it effortless to add or modify existing bots.
By adopting the builder pattern, tg-builder ensures your bots are more maintainable, organized, and efficient.
📦 Installation
Using npm:
npm install tg-builder
Using yarn:
yarn add tg-builder
⚙️ Configuration
Before you start, you need to create a configuration file named tg.json in your project's root. This file should contain the token and name of the bot you want to set up.
Replace xxxxxxxxxxxxxxxxxxxx with your actual bot tokens.
🛑 Remember, always keep your bot tokens secret and never expose them in publicly accessible places or repositories.
📖 Getting Started
1. Importing Modules
Begin by importing the essential modules:
import { BotsLoader, CommandBuilder, ActionBuilder } from 'tg-builder'
2. Defining Commands
Leverage the CommandBuilder to define the commands for your bot:
3. Defining Actions
Utilize the ActionBuilder to define telegram callback actions:
4. Loading and Launching the Bot
Make use of BotsLoader to add your bot and get it running:
🚀 Example
Here's a glimpse of a bot providing a text-based RPG game experience:
📄 Definitions
1. Command
2. Action
With tg-builder, bot development becomes a structured, readable, and maintainable endeavor. Dive in to explore more functionalities and elevate your bot development journey!