> For the complete documentation index, see [llms.txt](https://crypto-chief.gitbook.io/chief-event-stream/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://crypto-chief.gitbook.io/chief-event-stream/sinks/telegram.md). Agents can also search and read this documentation through its [MCP server](https://crypto-chief.gitbook.io/chief-event-stream/~gitbook/mcp).

# Telegram

## Telegram

A `telegram` sink sends each matched event to a Telegram private chat, group, supergroup or channel through the Bot API method `sendMessage`. Each message is escaped plain text of up to `3,500` characters, with link previews off.

### Before you start

1. Create a bot with `@BotFather` in Telegram and copy the bot token (`<bot_id>:<secret>`).
2. Let the bot post to the chat: send `/start` to it in a private chat, add it to the group, or make it a channel administrator with permission to post messages.
3. Get the `chat_id`. Send `/start` to the bot in a private chat, `/start@<bot_username>` in a group, or any post in the channel. Open `https://api.telegram.org/bot<bot_token>/getUpdates` (the bot must have no webhook set) and copy `chat.id` from `message`, or from `channel_post` for a channel. A public channel or supergroup can also be addressed as `@username`. When a group becomes a supergroup, its `chat_id` changes to a `-100…` ID and delivery fails with `400`: update `config.chat_id`. In forum groups, messages go to the General topic.

#### **Create a Telegram Sink**

<mark style="color:green;">`POST`</mark> `https://api-eventstream.crypto-chief.com/v1/sinks/create`

**Headers**

| Name            | Value                                                                                                                        |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Content-Type    | `application/json`                                                                                                           |
| Merchant        | Your Merchant ID                                                                                                             |
| X-CC-Timestamp  | Unix time in seconds                                                                                                         |
| X-CC-Nonce      | A new random value for every request                                                                                         |
| X-CC-Signature  | [Request signature](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/authentication.md)                    |
| Idempotency-Key | **Required.** [Format](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/authentication.md#idempotency-key) |

**Body**

Unknown fields return `400` `UNKNOWN_FIELD`.

| Name                     | Type    | Required | Description                                                                                                                                                                                                                                                        |
| ------------------------ | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `kind`                   | string  | true     | `"telegram"`.                                                                                                                                                                                                                                                      |
| `config`                 | object  | true     | Configuration.                                                                                                                                                                                                                                                     |
| `config.chat_id`         | string  | true     | Target Telegram chat ID or `@username`. Trimmed at delivery; must be `1`–`128` non-whitespace characters.                                                                                                                                                          |
| `config.format`          | string  | true     | Message layout; must be `"compact"`.                                                                                                                                                                                                                               |
| `config.label`           | string  | false    | Optional display label, `0`–`100` characters. No default stored.                                                                                                                                                                                                   |
| `config.rate_per_second` | integer | false    | Events per second for this sink, `1`–`20`, default `20`. A project's notification sinks send one request at a time; see [Ordering, retries, and auto-pause](https://crypto-chief.gitbook.io/chief-event-stream/sinks/overview.md#ordering-retries-and-auto-pause). |
| `config.enabled`         | boolean | false    | Default `true`. With `false`, unsent deliveries stay `"queued"` and `status` stays `"active"`; see [`config.enabled`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md#create-a-sink).                                                    |
| `credentials`            | object  | true     | Write-only; never returned. `credentials_meta.bot_token.last4` in `sinks/get` is `null`.                                                                                                                                                                           |
| `credentials.bot_token`  | string  | true     | Bot token from `@BotFather`. Validated at delivery: `6`–`256` characters from `A-Za-z0-9:_-` containing `:`. A leading `bot` prefix is removed.                                                                                                                    |

```json
{
  "kind": "telegram",
  "config": {
    "chat_id": "-1001987654321",
    "format": "compact",
    "label": "Treasury alerts",
    "rate_per_second": 5
  },
  "credentials": {
    "bot_token": "123456789:AAExampleBotTokenString_0123456789"
  }
}
```

**Response**

{% tabs %}
{% tab title="201" %}

```json
{
  "ok": true,
  "data": {
    "sink_id": "019a0000-0000-7000-8000-000000000001",
    "kind": "telegram",
    "config": {
      "chat_id": "-1001987654321",
      "format": "compact",
      "label": "Treasury alerts",
      "rate_per_second": 5
    },
    "status": "active",
    "secret": null,
    "secret_version": 0
  },
  "request_id": "019a0000-0000-7000-8000-000000000099"
}
```

{% endtab %}

{% tab title="422" %}

```json
{
  "ok": false,
  "error": "VALIDATION_ERROR",
  "msg": "request does not match the contract",
  "request_id": "019a0000-0000-7000-8000-000000000099",
  "details": {
    "field": "config.format",
    "reason": "required property is missing"
  }
}
```

{% endtab %}

{% tab title="429" %}

```json
{
  "ok": false,
  "error": "PROJECT_LIMIT_EXCEEDED",
  "msg": "sink limit reached",
  "request_id": "019a0000-0000-7000-8000-000000000099",
  "details": {}
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
`sinks/create` checks only the JSON schema. The `bot_token` format, the bot's permissions and the `chat_id` are checked at delivery. Call `sinks/test` after creating the sink and check that [`deliveries/info`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/deliveries.md#get-delivery-info) returns `"status": "succeeded"` for the returned `delivery_id`.
{% endhint %}

### What arrives

EventStream sends `POST https://api.telegram.org/bot<bot_token>/sendMessage` with `Content-Type: application/json; charset=utf-8` and `disable_web_page_preview: true`.

* **Lines:** follow the [message layout](https://crypto-chief.gitbook.io/chief-event-stream/sinks/overview.md#message-layout).
* **Escaping:** control characters and Unicode bidirectional override characters are removed from field values; `\n` and `\t` inside values become spaces. `&`, `<`, `>`, `[`, `]`, `(`, `)`, `*`, `_`, `` ` ``, and `~` inside values are escaped as `&amp;`, `&lt;`, `&gt;`, `\[`, `\]`, `\(`, `\)`, `\*`, `\_`, `` \` ``, `\~`. Messages are sent without `parse_mode`, so the chat shows the escapes as they are, for example `ETH\_MAINNET`.
* **Truncation:** if the text exceeds `3,500` characters, its end is replaced with `\n...\npayload_in_journal: true` and the `journal` line, and `text` stays within `3,500` characters. Fetch the full event with [`events/get`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/events.md) by `event_id`.

Example Bot API request body sent for a confirmed `ETH_MAINNET` `USDC` `transfer.token` event:

```json
{
  "chat_id": "-1001987654321",
  "text": "[CryptoChief EventStream] transfer.token (confirmed)\nevent_id: 019a0000-0000-7000-8000-000000000011\nnetwork: ETH\\_MAINNET\nsubscription_id: 019a0000-0000-7000-8000-000000000003\nsequence: 42\noccurred_at: 2026-10-27T00:00:00.000Z\ntx_hash: 0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\ntransfer: 0x0000000000000000000000000000000000000002 -> 0x0000000000000000000000000000000000000001\namount: 125.5 USDC\ndata: amount={\"decimals\":6,\"raw\":\"125500000\",\"scale\":null}, asset={\"contract\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"decimals\":6,\"id\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"kind\":\"token\",\"standard\":\"erc20\",\"symbol\":\"USDC\",\"token\\_id\":null}, direction=in, from=0x0000000000000000000000000000000000000002, source={\"destination\\_tag\":null,\"kind\":\"log\",\"memo\":null,\"path\":\"log/7/erc20\",\"source\\_tag\":null,\"success\":true}, to=0x0000000000000000000000000000000000000001, utxo=null\njournal: https://app-data.crypto-chief.com/project/3f2a1b4c-5d6e-7f80-9a1b-2c3d4e5f6071/event-stream?event_id=019a0000-0000-7000-8000-000000000011",
  "disable_web_page_preview": true
}
```

### Retries and errors

A delivery succeeds only when Telegram responds with HTTP `200`–`299` and a JSON body containing `"ok": true` and a non-zero `result.message_id`.

* **Retried (`transient`, up to `12` attempts over `24` hours):** network or timeout errors (`10`-second attempt limit), HTTP `408`, `425`, `429`, `500`–`599`, interrupted or `> 16 KiB` responses, and HTTP `200` responses with `"ok": false` where `error_code` is `429` or `>= 500`. See [Retries and Ordering](https://crypto-chief.gitbook.io/chief-event-stream/webhooks/retries-and-ordering.md).
* **`Retry-After`:** on HTTP `429` and `503`, EventStream takes the delay from the `Retry-After` header, or from `parameters.retry_after` in Telegram's JSON body when the header is missing. The delay is clamped to `[1s, 21600s]`, and the next attempt waits `max(jittered_backoff, Retry-After)`.
* **Permanent failures (no retries; delivery moves to `dead`):**
  * HTTP `401` (`Unauthorized`: invalid or revoked `bot_token`) or `403` (`Forbidden`: the user blocked the bot, or the bot was removed from the chat or channel): pauses the **entire sink** with `pause_reason: "destination_auth"`.
  * HTTP `404` or `410`: pauses the **entire sink** with `pause_reason: "destination_gone"`.
  * HTTP `400` or `422` (for example, `Bad Request: chat not found`): pauses **only that `(subscription_id, sink_id)` lane** (`"destination_rejected"`), unless repeated failures across attempts trigger whole-sink `"failures"`.
  * A `chat_id` or `bot_token` in an invalid format, HTTP `300`–`399`, or HTTP `200` without `"ok": true` and `result.message_id` (other than `error_code` `429` or `>= 500`): pauses the **entire sink** with `pause_reason: "destination_rejected"`.
* **How to resume:** fix bot permissions in Telegram, or change `bot_token` or `chat_id` with [`sinks/update`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md#update-a-sink), then call [`sinks/resume`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md#resume-a-sink) with `mode: "drain"` (or `mode: "skip"` with `acknowledged_gap: true`).

### Duplicates

Telegram `sendMessage` does not deduplicate requests. If the connection drops after Telegram posts the message and before EventStream gets the response, the retry posts a second message with the same `event_id`. A bot or parser that reads the chat should deduplicate by the `event_id: <uuidv7>` line.

### Test delivery

Calling [`sinks/test`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md) with `{"sink_id": "<uuidv7>", "sample_type": "system.test"}` sends a message with `network: SYSTEM`, `stage: confirmed`, `message: EventStream test`, and no `subscription_id` or `sequence` lines (`event_id` equals the test `delivery_id`):

```
[CryptoChief EventStream] system.test (confirmed)
event_id: 019a0000-0000-7000-8000-000000000002
network: SYSTEM
occurred_at: 2026-10-27T00:00:00.000Z
message: EventStream test
data: generated\_at=2026-10-27T00:00:00.000Z, message=EventStream test, sink\_id=019a0000-0000-7000-8000-000000000001
journal: https://app-data.crypto-chief.com/project/3f2a1b4c-5d6e-7f80-9a1b-2c3d4e5f6071/event-stream?event_id=019a0000-0000-7000-8000-000000000002
```

### What it costs

An acknowledged Telegram message costs a channel fee of `1,000` credits (`$0.0001`) on top of the base event fee. Failed attempts, throttled events and `sinks/test` cost `0` credits. See [Billing](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/billing.md).

### Example

`request()` is defined in [Authentication](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/authentication.md). Both `sinks/create` and `sinks/test` require an `Idempotency-Key`.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
import crypto from "node:crypto";

const sink = await request(
  "sinks/create",
  {
    kind: "telegram",
    config: {
      chat_id: "-1001987654321",
      format: "compact",
      label: "Treasury alerts",
      rate_per_second: 5,
    },
    credentials: {
      bot_token: "123456789:AAExampleBotTokenString_0123456789",
    },
  },
  crypto.randomUUID()
);

const test = await request(
  "sinks/test",
  {
    sink_id: sink.sink_id,
    sample_type: "system.test",
  },
  crypto.randomUUID()
);

console.log(sink.sink_id, test.delivery_id);
```

{% endtab %}

{% tab title="PHP" %}

```php
$sink = request(
    'sinks/create',
    [
        'kind' => 'telegram',
        'config' => [
            'chat_id'         => '-1001987654321',
            'format'          => 'compact',
            'label'           => 'Treasury alerts',
            'rate_per_second' => 5,
        ],
        'credentials' => [
            'bot_token' => '123456789:AAExampleBotTokenString_0123456789',
        ],
    ],
    bin2hex(random_bytes(16))
);

$test = request(
    'sinks/test',
    [
        'sink_id'     => $sink['sink_id'],
        'sample_type' => 'system.test',
    ],
    bin2hex(random_bytes(16))
);

echo $sink['sink_id'] . ' ' . $test['delivery_id'] . "\n";
```

{% endtab %}

{% tab title="GO" %}

```go
sink, err := request("sinks/create", map[string]any{
	"kind": "telegram",
	"config": map[string]any{
		"chat_id":         "-1001987654321",
		"format":          "compact",
		"label":           "Treasury alerts",
		"rate_per_second": 5,
	},
	"credentials": map[string]any{
		"bot_token": "123456789:AAExampleBotTokenString_0123456789",
	},
}, rand.Text())
if err != nil {
	panic(err)
}

test, err := request("sinks/test", map[string]any{
	"sink_id":     sink["sink_id"],
	"sample_type": "system.test",
}, rand.Text())
if err != nil {
	panic(err)
}

fmt.Println(sink["sink_id"], test["delivery_id"])
```

{% endtab %}

{% tab title="Python" %}

```python
import secrets

sink = request(
    "sinks/create",
    {
        "kind": "telegram",
        "config": {
            "chat_id": "-1001987654321",
            "format": "compact",
            "label": "Treasury alerts",
            "rate_per_second": 5,
        },
        "credentials": {
            "bot_token": "123456789:AAExampleBotTokenString_0123456789",
        },
    },
    secrets.token_hex(16),
)

test = request(
    "sinks/test",
    {
        "sink_id": sink["sink_id"],
        "sample_type": "system.test",
    },
    secrets.token_hex(16),
)

print(sink["sink_id"], test["delivery_id"])
```

{% endtab %}

{% tab title="curl" %}

```bash
sink=$(request sinks/create \
  '{"kind":"telegram","config":{"chat_id":"-1001987654321","format":"compact","label":"Treasury alerts","rate_per_second":5},"credentials":{"bot_token":"123456789:AAExampleBotTokenString_0123456789"}}' \
  "$(openssl rand -hex 16)")

sink_id=$(jq -r '.sink_id' <<< "$sink")

request sinks/test \
  "{\"sink_id\":\"$sink_id\",\"sample_type\":\"system.test\"}" \
  "$(openssl rand -hex 16)"
```

{% endtab %}
{% endtabs %}
