Installation and Setup
Installation and Setup
To get started with the MultiBot module, follow these steps to install and set it up in your Node.js project.
Prerequisites
Node.js: Ensure Node.js is installed on your system. The
MultiBotmodule is compatible with Node.js versions 14.x and above.
Installation
Install the
multibot-telegramPackage:To install the
MultiBotmodule, use npm to add it to your project:npm install multibot-telegramThis command will add
multibot-telegramto your project's dependencies and install all required packages.
Configuration
Prepare Your Configuration:
Create a configuration file or object with the necessary parameters. This should include details such as bot tokens, IDs, system type, and any additional options like commands.
// config.js module.exports = { type: 'multi', // or 'one' bots: [ { id: 1, token: 'your_bot_token_1', main: true }, { id: 2, token: 'your_bot_token_2', main: false } ], options: { commands: [ { command: 'start', description: 'Start command' }, { command: 'help', description: 'Help command' } ] } };Initialize MultiBot:
Import and initialize the
MultiBotclass using the configuration:// index.js const MultiBot = require('multibot-telegram'); const config = require('./config'); // Initialize MultiBot with the configuration const multiBot = new MultiBot(config); // Use the MultiBot instance to interact with your botsSet Up Global Manager:
If your module uses
global-managerto store global state, ensure it's set up correctly. This setup might be included in theMultiBotinitialization or managed separately.// globalManagerSetup.js (if needed) const globalManager = require('global-manager'); const { type, bots } = require('./config'); globalManager.set('type', type); globalManager.set('bots', bots);
Usage
Once initialized, you can interact with the MultiBot instance to manage your bots. For example:
// Retrieve the main bot instance
const mainBot = multiBot.getBot();
console.log('Main Bot:', mainBot);
// Retrieve a bot instance by its ID
const botById = multiBot.getBotById(1);
console.log('Bot By ID:', botById);Common Issues
Invalid Token: Ensure each bot token is valid and correctly configured in the
config.jsfile.Configuration Errors: Double-check your configuration file for correctness, including bot IDs, tokens, and options.
Missing Dependencies: Verify that
multibot-telegramand other dependencies are installed and correctly set up.
If you encounter any issues during installation or setup, refer to the troubleshooting guide or consult the module's documentation for further assistance.
Last updated