Skip to content

Send Message ​

POST /message

Zate's workhorse. Send a message to a username, user, group, channel, or phone number, in seven types: text, image, video, audio, document, location, and contact. Each type needs different fields, so check the tables below.

Endpoint Details ​

  • Base URL: https://api-zate.azickri.com
  • Headers: id, session-id, and Content-Type: application/json
  • Requirement: the session must be connected (isConnected: true)

Headers ​

HeaderTypeRequiredDescription
idstringYesid from Create Session.
session-idstringYessessionId from Create Session.

Request Body ​

FieldTypeRequiredDescription
groupstringOne of*Group ID, like -1001234567890, or a public group's username.
channelstringOne of*Channel ID, like -1001234567890, or a public channel's username. Your account must be allowed to post there.
userstringOne of*Telegram user ID, like 123456789.
usernamestringOne of*Recipient username: azickri, @azickri, or t.me/azickri.
phonestringOne of*Phone number in international format, like 6281234567890. Only works if the person's privacy allows it.
typestringYesMessage type: text, image, video, audio, document, location, or contact.
textstringFor textMessage text. For image, video, and document, it becomes the caption (optional).
parseModestringNomarkdown or html to format the text and caption. Leave it empty to send as is. See Text Formatting.
imageobjectFor imageSee the image object.
videoobjectFor videoSee the video object.
audioobjectFor audioSee the audio object.
documentobjectFor documentSee the document object.
locationobjectFor locationSee the location object.
contactobjectFor contactSee the contact object.

* Fill in one of group, channel, user, username, or phone. If more than one is filled in, they're used in this order: group, channel, user, username, then phone. The full explanation is in Receivers.

Media Objects ​

Media is sent by URL. Zate downloads the file, so the URL must be public and point straight at the file. See also Sending Media from a URL.

ObjectFieldTypeRequiredDescription
imageurlstringYesImage URL. Re-encoded as JPEG, at most 2560 pixels.
mimetypestringYesFor example image/jpeg.
thumbnailstringNoNot used for images. Telegram makes its own thumbnail.
videourlstringYesVideo URL. MP4 is the safest choice.
mimetypestringYesFor example video/mp4.
durationnumberYesVideo length in seconds, greater than 0. If the file's real duration can be read, that one is used.
thumbnailstringNoThumbnail image URL. If empty, Zate uses the video's first frame.
audiourlstringYesAudio URL. MP3 is the safest choice.
mimetypestringYesFor example audio/mpeg.
durationnumberYesAudio length in seconds, greater than 0.
documenturlstringYesDocument URL.
namestringYesFile name shown in the chat, like invoice.pdf. Its extension decides the file type in Telegram.
sizenumberYesFile size in bytes, greater than 0.
mimetypestringYesFor example application/pdf.

Audio isn't a voice note

Audio is sent as a regular audio file that plays in Telegram's music player, not as a voice note. Audio can't have a caption either, so text is ignored.

Location and Contact Objects ​

ObjectFieldTypeRequiredDescription
locationlatitudenumberYesLatitude, must not be 0.
longitudenumberYesLongitude, must not be 0.
namestringNoPlace name, like Monas.
addressstringNoPlace address.
contactnamestringYesName of the shared contact.
phonestringYesContact's phone number, like 6281234567890.

If name or address is filled in, the location is sent as a venue with its name and address. If both are empty, it's sent as a plain map pin.

Example Request ​

The simplest case: a text message to one username.

bash
curl -X POST "https://api-zate.azickri.com/message" \
  -H "id: YOUR_ID" \
  -H "session-id: YOUR_SESSION_ID" \
  -H "Content-Type: application/json" \
  -d '{"username":"@azickri","type":"text","text":"Hello from Zate! 👋"}'
javascript
import axios from 'axios';

const response = await axios.post(
  'https://api-zate.azickri.com/message',
  {
    username: '@azickri',
    type: 'text',
    text: 'Hello from Zate! 👋',
  },
  {
    headers: {
      'id': 'YOUR_ID',
      'session-id': 'YOUR_SESSION_ID',
    },
  },
);

console.log(response.data);
javascript
const response = await fetch('https://api-zate.azickri.com/message', {
  method: 'POST',
  headers: {
    'id': 'YOUR_ID',
    'session-id': 'YOUR_SESSION_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    username: '@azickri',
    type: 'text',
    text: 'Hello from Zate! 👋',
  }),
});

const data = await response.json();
console.log(data);

Example Body per Type ​

Swap the body in the example request above for one of these.

json
{
  "username": "@azickri",
  "type": "text",
  "text": "Hello from Zate! 👋"
}
json
{
  "username": "@azickri",
  "type": "text",
  "parseMode": "html",
  "text": "Order <b>#1024</b> is ready! Check it <a href=\"https://zate.azickri.com\">here</a> 🍢"
}
json
{
  "username": "@azickri",
  "type": "image",
  "text": "This is the caption, optional",
  "image": {
    "url": "https://example.com/image.jpg",
    "mimetype": "image/jpeg"
  }
}
json
{
  "username": "@azickri",
  "type": "video",
  "text": "Video caption",
  "video": {
    "url": "https://example.com/video.mp4",
    "mimetype": "video/mp4",
    "duration": 30,
    "thumbnail": "https://example.com/video-thumbnail.jpg"
  }
}
json
{
  "username": "@azickri",
  "type": "audio",
  "audio": {
    "url": "https://example.com/audio.mp3",
    "mimetype": "audio/mpeg",
    "duration": 30
  }
}
json
{
  "username": "@azickri",
  "type": "document",
  "text": "This month's invoice",
  "document": {
    "url": "https://example.com/invoice.pdf",
    "name": "invoice.pdf",
    "size": 102400,
    "mimetype": "application/pdf"
  }
}
json
{
  "username": "@azickri",
  "type": "location",
  "location": {
    "name": "Monas",
    "address": "Gambir, Central Jakarta",
    "latitude": -6.175392,
    "longitude": 106.827153
  }
}
json
{
  "username": "@azickri",
  "type": "contact",
  "contact": {
    "name": "Azickri",
    "phone": "6281234567890"
  }
}
json
{
  "group": "-1001234567890",
  "type": "text",
  "text": "Hi everyone! 👋"
}
json
{
  "channel": "-1001234567890",
  "type": "text",
  "text": "Fresh update!"
}
json
{
  "user": "123456789",
  "type": "text",
  "text": "Thanks for your order! 🙏"
}
json
{
  "phone": "6281234567890",
  "type": "text",
  "text": "Hi! This is from Zate."
}

Response ​

json
{
  "messageId": "1024"
}
json
// No receiver
{
  "statusCode": 400,
  "message": "invalid phone, username, user, group or channel"
}

// Username or ID not found
{
  "statusCode": 400,
  "message": "chat not found"
}

// Phone number can't be looked up
{
  "statusCode": 400,
  "message": "phone is not on telegram or hidden by its privacy settings"
}

// A required field for that type is empty
{
  "statusCode": 400,
  "message": "image should not be empty"
}
json
{
  "statusCode": 404,
  "message": "session not found"
}
json
// Session isn't connected
{
  "statusCode": 500,
  "message": "session not connected"
}

// Media couldn't be downloaded
{
  "statusCode": 500,
  "message": "error parser file from url 404 Not Found"
}

// Refused by Telegram
{
  "statusCode": 500,
  "message": "403: CHAT_WRITE_FORBIDDEN (caused by messages.SendMessage)"
}
FieldTypeDescription
messageIdstringID of the message in the receiving chat.

Messages from the API skip the webhook

Messages sent through this endpoint aren't echoed to your webhook, since the response already gives you the messageId.