# 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 `MultiBot` module is compatible with Node.js versions 14.x and above.

**Installation**

1. **Install the `multibot-telegram` Package**:

   To install the `MultiBot` module, use npm to add it to your project:

   ```bash
   npm install multibot-telegram
   ```

   This command will add `multibot-telegram` to your project's dependencies and install all required packages.

**Configuration**

1. **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.

   ```javascript
   // 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' }
           ]
       }
   };
   ```
2. **Initialize MultiBot**:

   Import and initialize the `MultiBot` class using the configuration:

   ```javascript
   // 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 bots
   ```
3. **Set Up Global Manager**:

   If your module uses `global-manager` to store global state, ensure it's set up correctly. This setup might be included in the `MultiBot` initialization or managed separately.

   ```javascript
   // 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:

```javascript
// 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.js` file.
* **Configuration Errors**: Double-check your configuration file for correctness, including bot IDs, tokens, and options.
* **Missing Dependencies**: Verify that `multibot-telegram` and 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.

{% hint style="info" %}

#### How to Obtain Bot ID

To get your bot ID from the token, locate the numeric part before the colon (`:`). For example, in the token `1234567890:ABCDE12345FGHIJKLMNOPQRSTUVWX`, the bot ID is `1234567890`. Use this ID for configuring your bot.
{% endhint %}
