# Publish

Publish text, photos, videos, documents and albums to a Telegram channel or group, and edit published messages.

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

Each post becomes one Telegram message or album, depending on its media:

- A plain post becomes a text message.
- One media item becomes a photo, video or document message with `content` as its caption.
- 2 to 10 items become an album with the caption on the first message.

Text is parsed as HTML unless `parseMode` says otherwise.

## Text message

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
const { data: published } = await zernio.posts.createPost({
  body: {
    content: '<b>Release 2.3 is out.</b>\n\nRead the <a href="https://example.com/changelog">changelog</a>.',
    platforms: [
      {
        platform: 'telegram',
        accountId: '66b2e19d8c3f5a7e9d0b1c2d',
        platformSpecificData: { parseMode: 'HTML' }
      }
    ],
    publishNow: true
  }
});

console.log(published.post.platforms[0].platformPostUrl);
```
</Tab>
<Tab value="Python">
```python
published = client.posts.create_post(
    content='<b>Release 2.3 is out.</b>\n\nRead the <a href="https://example.com/changelog">changelog</a>.',
    platforms=[
        {
            "platform": "telegram",
            "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
            "platformSpecificData": {"parseMode": "HTML"}
        }
    ],
    publish_now=True
)

print(published["post"]["platforms"][0]["platformPostUrl"])
```
</Tab>
<Tab value="curl">
```bash
curl -X POST https://zernio.com/api/v1/posts \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "<b>Release 2.3 is out.</b>\n\nRead the <a href=\"https://example.com/changelog\">changelog</a>.",
    "platforms": [
      {
        "platform": "telegram",
        "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
        "platformSpecificData": {"parseMode": "HTML"}
      }
    ],
    "publishNow": true
  }'
```
</Tab>
</Tabs>

Response (`201`):

```json
{
  "post": {
    "_id": "65f1c0a9e2b5af0012ab34cd",
    "status": "published",
    "platforms": [
      {
        "platform": "telegram",
        "status": "published",
        "platformPostUrl": "https://t.me/mychannel/42"
      }
    ]
  }
}
```

Every sample below changes only the `mediaItems` or the `platforms` entry of this request.

## Photo message

A single image with `content` as the caption (1,024 characters):

```json
"mediaItems": [
  { "type": "image", "url": "https://cdn.example.com/launch.jpg" }
]
```

## Video message

A single video with `content` as the caption:

```json
"mediaItems": [
  { "type": "video", "url": "https://cdn.example.com/demo.mp4" }
]
```

## Document message

Any file type, sent as a document:

```json
"mediaItems": [
  { "type": "document", "url": "https://cdn.example.com/report.pdf" }
]
```

## Album

Up to 10 items, images and videos mixed, sent as one album:

```json
"mediaItems": [
  { "type": "image", "url": "https://cdn.example.com/photo1.jpg" },
  { "type": "image", "url": "https://cdn.example.com/photo2.jpg" },
  { "type": "video", "url": "https://cdn.example.com/clip.mp4" },
  { "type": "image", "url": "https://cdn.example.com/photo3.jpg" }
]
```

## Formatting

`parseMode` selects how Telegram reads `content`. HTML is the default:

```html
<b>bold</b>
<i>italic</i>
<u>underline</u>
<s>strikethrough</s>
<code>inline code</code>
<pre>code block</pre>
<a href="https://example.com">link</a>
```

`"Markdown"` supports `*bold*`, `_italic_`, `[link](https://example.com)` and backtick-wrapped inline code. `"MarkdownV2"` adds `__underline__`, `~strikethrough~` and `||spoiler||`, and needs a backslash before every one of these characters:

```text
_ * [ ] ( ) ~ ` > # + - = | { } . !
```

An unescaped character fails the post with "Can't parse entities".

## Silent and protected messages

`disableNotification` delivers the message without a notification sound, `protectContent` stops recipients from forwarding or saving it, and `disableWebPagePreview` suppresses the link preview:

```json
{
  "platform": "telegram",
  "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
  "platformSpecificData": {
    "parseMode": "HTML",
    "disableWebPagePreview": true,
    "disableNotification": true,
    "protectContent": true
  }
}
```

## Channels and groups

| Destination | Shown as the author |
|-------------|---------------------|
| Channel | The channel's name and logo |
| Group | Social Media Connector (`@LateScheduleBot`) |

## Edit a published message

[Edit post](/posts/edit-post) replaces the text of a published Telegram message. The message id does not change.

Messages stay editable with no time window and no limit on the number of edits. What `content` replaces depends on the original post:

| Original post | What `content` replaces | Limit |
|---------------|-------------------------|-------|
| Text only | The message text | 4,096 characters |
| Single photo, video or document | The caption | 1,024 characters |
| Album | The caption on the album (its first message) | 1,024 characters |

The media itself cannot be swapped, added or removed. An edit with unchanged content is rejected with `400`.

Check which limit applies before sending: a 2,000-character edit fits a text message and is too long for a photo caption.

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
const { data: edited } = await zernio.posts.editPost({
  path: { postId: published.post._id },
  body: {
    platform: 'telegram',
    content: '<b>Updated.</b> The webinar starts at 18:00 CET.'
  }
});

console.log(edited.id, edited.url);
```
</Tab>
<Tab value="Python">
```python
edited = client.posts.edit_post(
    post_id=published["post"]["_id"],
    platform="telegram",
    content="<b>Updated.</b> The webinar starts at 18:00 CET."
)

print(edited["id"], edited["url"])
```
</Tab>
<Tab value="curl">
```bash
curl -X POST https://zernio.com/api/v1/posts/65f1c0a9e2b5af0012ab34cd/edit \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "telegram",
    "content": "<b>Updated.</b> The webinar starts at 18:00 CET."
  }'
```
</Tab>
</Tabs>

Response (`200`):

```json
{
  "success": true,
  "id": "42",
  "url": "https://t.me/mychannel/42"
}
```

If the post went to several Telegram channels or groups, pass `accountId` to pick which copy to edit. Without it, the first `telegram` entry on the post is edited.