# Настройка Telegram Bot

### Создание телеграм бот&#x20;

1. В вашем аккаунте нужно написать контакту [@BotFather](https://t.me/BotFather)
2. Нажать кнопку Start если бот еще не запущен&#x20;
3. Написать команду `/newbot` и следовать инструкциям в боте для получение токена

### **Установить полученный токен**&#x20;

1. Подключится к вашему серверу по SSH или FTP
2. Иницилизировать проект

```bash
cd /var/www/exchanger-bot
git pull
npm i
npm run configure
```

&#x20; 3\. Нужно настроить **token** и **username** в файле\
&#x20;      `/var/www/exchanger-bot/config/app_config.json`

{% hint style="info" %}
**username** это имя бота в системе телеграм, \
пожалуйста имя бота **указывайте без @**
{% endhint %}

{% code title="config/app\_config.json" %}

```json
...
"bot": {
   "username": "usernamebot", 
   "token": "12345567:TOKEN"
}
...
```

{% endcode %}

&#x20; 4\. Настроить домен в конфигурации `/var/www/exchanger-bot/config/app_config.json`

{% hint style="info" %}
**Домен:** `www.exchanger.domain` предоставлен как пример **замените его на домен вашего сайта!** Eсли обменник у вас установлен на субдомен `www` пожалуйста указывайте домен с `www`

\
**baseUrl**: формируется по принципу <https://ваш\\_доме&#x43D;**/tg>\*\*
{% endhint %}

&#x20;     Пример заполнения конфига:

{% code title="config/app\_config.json" %}

```json
"http": {
...
    "baseUrl": "https://www.exchanger.domain/tg",
...
},
"exchanger": {  
  "baseUrl": "https://www.exchanger.domain", 
  "exchangerUrl": "https://www.exchanger.domain", 
  ... 
},
...
```

{% endcode %}

&#x20; 5\. Доступ к MongoDB:&#x20;

{% hint style="info" %}
**Требуется наличие MongoDB на сервере.** \
\
Если вы устанавливаете бота на тотже сервер где у вас установлено exchanger-api возьмите **mongo:uri** с файла **exchanger-api/config/app\_config.json**
{% endhint %}

&#x20;   Укажите в файле конфигурации `/var/www/exchanger-bot/config/app_config.json`  \
&#x20;   доступы к базе данныx MongoDB

{% code title="config/app\_config.json" %}

```json
...
"mongodb": {  
  "uri": "mongodb://localhost:27017/exchanger-bot"
},
...
```

{% endcode %}

&#x20; 6\.  Применить изменения конфигурации (перезапустить сервис)

{% hint style="info" %}
Требуется наличие диспетчер процессов **PM2**. Установить можно командой \
`npm install pm2 -g`
{% endhint %}

```bash
npm run start
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.boxexchanger.net/dlya-razrabotchikov/nastroika-telegram-bot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
