How Barfinex Works
Telegram notifications from detector and advisor
Get signals, position open/close events, and warnings in Telegram—without opening the app or checking logs. Set it up once and receive everything in your messenger.
Why use Telegram notifications?
With Telegram notifications you receive signals, position open/close events, and warnings from the detector or advisor directly in your messenger. No need to open the application or watch logs—configure once and everything is delivered to the chat or channel you choose.
Quick checklist
| Where | What to do |
|---|---|
| Telegram | Create a bot in @BotFather, get the token. |
| Telegram | Send /start to the bot (for private chat) or add the bot to a channel/group as an admin with “Post messages” permission. |
| Telegram | Get your chat_id via getUpdates or from the channel/group. |
| Project | In .env set TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID (and optionally DETECTOR_TELEGRAM_CHAT_ID, DETECTOR_TELEGRAM_ENABLED=true). |
| Project | Ensure the detector reads this .env (NestJS ConfigModule with the correct envFilePath). |
After that, restart the detector with DETECTOR_TELEGRAM_ENABLED=true and the variables set—notifications will be sent to the specified chat_id.
Step 1 — In Telegram
1.1 Create a bot (if you don’t have one)
- Open @BotFather in Telegram.
- Send the command:
/newbot. - Enter the bot name (e.g. “Barfinex Alerts”).
- Enter the bot username (e.g.
barfinex_alerts_bot; must end withbot). - BotFather will reply with a token like:
1234567890:AAH....
Save this token — you will use it as TELEGRAM_BOT_TOKEN.
Tip: You can add a screenshot of BotFather’s reply with the token here (e.g. save as
public/images/docs/telegram-botfather.pngand use).
1.2 Get the destination (where to send messages)
You can send notifications to:
- Private chat (only you see them), or
- Channel / group (e.g. for a team).
Option A — Private chat
Find your bot in Telegram and send it:
/start.In a browser, open (replace
<TOKEN>with your bot token):https://api.telegram.org/bot<TOKEN>/getUpdates
In the JSON response, find
message.chat.id. It is a number, e.g.987654321.
This is your chat_id for private messages.
Option B — Channel or group
Add the bot to the channel or group.
Make the bot an administrator with the right “Post messages” (or “Publish messages”).
Send a message in the channel/group (or have the bot post once).
Call the same URL again:
https://api.telegram.org/bot<TOKEN>/getUpdates
In the response, find
chat.idfor your channel/group. For channels it often looks like-1001234567890.
You can also use tools like @userinfobot or similar to get the chat id of a channel/group.
Tip: A screenshot of the
getUpdatesresponse in the browser (withchat.idhighlighted) helps when you return to the setup later. Save it e.g. aspublic/images/docs/telegram-getupdates.png.
Remember:
- TELEGRAM_BOT_TOKEN — the token from BotFather.
- TELEGRAM_CHAT_ID or DETECTOR_TELEGRAM_CHAT_ID — the number (or
-100...for a channel) where notifications should go.
Step 2 — In the project
2.1 Environment variables
In your project root, in .env (or .env.local / .env.production), add:
TELEGRAM_BOT_TOKEN=<token from BotFather> TELEGRAM_CHAT_ID=<your chat_id or channel chat_id>
For the detector you can use separate settings:
DETECTOR_TELEGRAM_CHAT_ID=<same or different chat_id> DETECTOR_TELEGRAM_ENABLED=true
- TELEGRAM_BOT_TOKEN — required for sending messages.
- TELEGRAM_CHAT_ID — default destination; the detector uses DETECTOR_TELEGRAM_CHAT_ID if set, otherwise TELEGRAM_CHAT_ID.
- DETECTOR_TELEGRAM_ENABLED=true — turns on sending detector alerts (signals, etc.) to Telegram via Redis events.
2.2 Detector: how it uses the token
In the detector app (apps/detector), the bot token is read from config: e.g. in alert.module.ts the code uses ConfigService.get('TELEGRAM_BOT_TOKEN').
Make sure NestJS loads your .env (e.g. ConfigModule.forRoot({ envFilePath: '.env' }) or your actual env file path) so that TELEGRAM_BOT_TOKEN is available.
2.3 Where messages are sent
The code already uses DETECTOR_TELEGRAM_CHAT_ID or TELEGRAM_CHAT_ID in AlertService.sendMessage. You do not need to change the code—only set the variables in the previous step.
2.4 Enable detector notifications
Set in the same .env:
DETECTOR_TELEGRAM_ENABLED=true
This enables sending detector signals (and other Redis-based events) to Telegram.
Summary
- Telegram: Create a bot in BotFather → get token.
- Telegram: Get
chat_id(private:/start+getUpdates; channel/group: add bot as admin +getUpdatesor @userinfobot). - Project: In
.envsetTELEGRAM_BOT_TOKEN,TELEGRAM_CHAT_ID, and optionallyDETECTOR_TELEGRAM_CHAT_ID,DETECTOR_TELEGRAM_ENABLED=true. - Project: Ensure the detector’s ConfigModule loads this
.env. - Restart the detector; with
DETECTOR_TELEGRAM_ENABLED=trueand variables set, notifications will appear in the chosen Telegram chat or channel.
For more details on the Bot API, see the Telegram Bot API documentation.