Publish
Publish text, photos, videos, documents and albums to a Telegram channel or group, and edit published messages.
A plain post becomes a text message. One media item becomes a photo, video or document message with content as its caption, and 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
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);Response (201):
{
"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):
"mediaItems": [
{ "type": "image", "url": "https://cdn.example.com/launch.jpg" }
]Video message
A single video with content as the caption:
"mediaItems": [
{ "type": "video", "url": "https://cdn.example.com/demo.mp4" }
]Document message
Any file type, sent as a document:
"mediaItems": [
{ "type": "document", "url": "https://cdn.example.com/report.pdf" }
]Album
Up to 10 items, images and videos mixed, sent as one album:
"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:
<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:
_ * [ ] ( ) ~ ` > # + - = | { } . !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:
{
"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 | ZernioScheduleBot |
Edit a published message
Edit post replaces the text of a published Telegram message. Messages stay editable with no time window and no limit on the number of edits, and the message id does not change. 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, and 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.
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);Response (200):
{
"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.