Barfinex

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

WhereWhat to do
TelegramCreate a bot in @BotFather, get the token.
TelegramSend /start to the bot (for private chat) or add the bot to a channel/group as an admin with “Post messages” permission.
TelegramGet your chat_id via getUpdates or from the channel/group.
ProjectIn .env set TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID (and optionally DETECTOR_TELEGRAM_CHAT_ID, DETECTOR_TELEGRAM_ENABLED=true).
ProjectEnsure 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)

  1. Open @BotFather in Telegram.
  2. Send the command: /newbot.
  3. Enter the bot name (e.g. “Barfinex Alerts”).
  4. Enter the bot username (e.g. barfinex_alerts_bot; must end with bot).
  5. 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.png and use ![BotFather token](/images/docs/telegram-botfather.png)).

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

  1. Find your bot in Telegram and send it: /start.

  2. In a browser, open (replace <TOKEN> with your bot token):

    https://api.telegram.org/bot<TOKEN>/getUpdates
    
  3. 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

  1. Add the bot to the channel or group.

  2. Make the bot an administrator with the right “Post messages” (or “Publish messages”).

  3. Send a message in the channel/group (or have the bot post once).

  4. Call the same URL again:

    https://api.telegram.org/bot<TOKEN>/getUpdates
    
  5. In the response, find chat.id for 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 getUpdates response in the browser (with chat.id highlighted) helps when you return to the setup later. Save it e.g. as public/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

  1. Telegram: Create a bot in BotFather → get token.
  2. Telegram: Get chat_id (private: /start + getUpdates; channel/group: add bot as admin + getUpdates or @userinfobot).
  3. Project: In .env set TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, and optionally DETECTOR_TELEGRAM_CHAT_ID, DETECTOR_TELEGRAM_ENABLED=true.
  4. Project: Ensure the detector’s ConfigModule loads this .env.
  5. Restart the detector; with DETECTOR_TELEGRAM_ENABLED=true and 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.

Let’s Get in Touch

Have questions or want to explore Barfinex? Send us a message.