import { PeriskopeApi } from '@periskope/periskope-client';

const client = new PeriskopeApi({
  authToken: 'YOUR_API_KEY',
  phone: 'YOUR_PHONE_NUMBER', // e.g., '919876543210'
});

async function sendMessage() {
  const response = await client.message.send({
    chat_id: '919537851844',
    message: 'Hi from Periskope'
  });

  console.log(response);
}

sendMessage();
{
  "queue_id": "c2b892d5-2370-4a69-b844-aae5e2bfae92",
  "queue_position": 1
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Headers

x-phone
string

Please provide the number of the phone you want to call with this API in the header. The number must be in country code + number format without any characters or spaces, e.g. 919876543210; Alternatively, provide the phone_id (phone-xxxxxxxxxxxx) in the header

Example:

"{{orgPhone}}"

Body

application/json
chat_id
string
required
  • For groups, enter the chat_id of the group. This will be a string that ends with @g.us
  • For 1-1 chats, enter the country_code + number of the recipient e.g. 919537851844@c.us (The @c.us is optional)
Example:

"919537851844@c.us"

message
string

The text body or caption. You can use basic markdown formatting supported by WhatsApp e.g. * for bold, and _ for italic, etc.

media
object

Media object containing file information and content

Note: You must specify either filedata or url

reply_to
string

To reply to a message, add the message_id in this field

Response

200 - application/json
Text Message / Media Message / Reply Message / Poll Message

The response object contains the queue_id and the position in the queue

You can check the status of the sent message in the queue using the /queue/jobs endpoint

The queue_id can also be mapped in the message object against the sent_message_id