curl --request POST \
--url https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--data '
{
"receiver": "<string>",
"muid": "<string>",
"category": "message",
"type": "text",
"data": {
"text": "<string>",
"metadata": {},
"attachments": [
{
"url": "<string>",
"name": "<string>",
"mimeType": "<string>",
"extension": "<string>",
"size": "<string>"
}
]
},
"multipleReceivers": {
"uids": [
"<string>"
],
"guids": [
"<string>"
]
},
"tags": [
"<string>"
]
}
'import requests
url = "https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages"
payload = {
"receiver": "<string>",
"muid": "<string>",
"category": "message",
"type": "text",
"data": {
"text": "<string>",
"metadata": {},
"attachments": [
{
"url": "<string>",
"name": "<string>",
"mimeType": "<string>",
"extension": "<string>",
"size": "<string>"
}
]
},
"multipleReceivers": {
"uids": ["<string>"],
"guids": ["<string>"]
},
"tags": ["<string>"]
}
headers = {
"apikey": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {apikey: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
receiver: '<string>',
muid: '<string>',
category: 'message',
type: 'text',
data: {
text: '<string>',
metadata: {},
attachments: [
{
url: '<string>',
name: '<string>',
mimeType: '<string>',
extension: '<string>',
size: '<string>'
}
]
},
multipleReceivers: {uids: ['<string>'], guids: ['<string>']},
tags: ['<string>']
})
};
fetch('https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'receiver' => '<string>',
'muid' => '<string>',
'category' => 'message',
'type' => 'text',
'data' => [
'text' => '<string>',
'metadata' => [
],
'attachments' => [
[
'url' => '<string>',
'name' => '<string>',
'mimeType' => '<string>',
'extension' => '<string>',
'size' => '<string>'
]
]
],
'multipleReceivers' => [
'uids' => [
'<string>'
],
'guids' => [
'<string>'
]
],
'tags' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"apikey: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages"
payload := strings.NewReader("{\n \"receiver\": \"<string>\",\n \"muid\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"<string>\",\n \"metadata\": {},\n \"attachments\": [\n {\n \"url\": \"<string>\",\n \"name\": \"<string>\",\n \"mimeType\": \"<string>\",\n \"extension\": \"<string>\",\n \"size\": \"<string>\"\n }\n ]\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"<string>\"\n ],\n \"guids\": [\n \"<string>\"\n ]\n },\n \"tags\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("apikey", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"receiver\": \"<string>\",\n \"muid\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"<string>\",\n \"metadata\": {},\n \"attachments\": [\n {\n \"url\": \"<string>\",\n \"name\": \"<string>\",\n \"mimeType\": \"<string>\",\n \"extension\": \"<string>\",\n \"size\": \"<string>\"\n }\n ]\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"<string>\"\n ],\n \"guids\": [\n \"<string>\"\n ]\n },\n \"tags\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"receiver\": \"<string>\",\n \"muid\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"<string>\",\n \"metadata\": {},\n \"attachments\": [\n {\n \"url\": \"<string>\",\n \"name\": \"<string>\",\n \"mimeType\": \"<string>\",\n \"extension\": \"<string>\",\n \"size\": \"<string>\"\n }\n ]\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"<string>\"\n ],\n \"guids\": [\n \"<string>\"\n ]\n },\n \"tags\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "1",
"conversationId": "cometchat-uid-3_user_cometchat-uid-5",
"sender": "cometchat-uid-3",
"receiverType": "user",
"receiver": "cometchat-uid-5",
"category": "message",
"type": "text",
"data": {
"text": "test hello",
"metadata": {
"key1": "val1"
},
"entities": {
"sender": {
"entity": {
"uid": "cometchat-uid-3",
"name": "Nancy Grace",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
"status": "offline",
"role": "default",
"createdAt": 1638361550
},
"entityType": "user"
},
"receiver": {
"entity": {
"uid": "cometchat-uid-5",
"name": "John Paul",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-5.webp",
"status": "offline",
"role": "default",
"createdAt": 1638361550,
"conversationId": "cometchat-uid-3_user_cometchat-uid-5"
},
"entityType": "user"
}
}
},
"sentAt": 1638423490,
"updatedAt": 1638423490
}
}Send Bot Message
Send a CometChat message from a bot UID with REST API to post bot-authored text, media, or custom content.
curl --request POST \
--url https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--data '
{
"receiver": "<string>",
"muid": "<string>",
"category": "message",
"type": "text",
"data": {
"text": "<string>",
"metadata": {},
"attachments": [
{
"url": "<string>",
"name": "<string>",
"mimeType": "<string>",
"extension": "<string>",
"size": "<string>"
}
]
},
"multipleReceivers": {
"uids": [
"<string>"
],
"guids": [
"<string>"
]
},
"tags": [
"<string>"
]
}
'import requests
url = "https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages"
payload = {
"receiver": "<string>",
"muid": "<string>",
"category": "message",
"type": "text",
"data": {
"text": "<string>",
"metadata": {},
"attachments": [
{
"url": "<string>",
"name": "<string>",
"mimeType": "<string>",
"extension": "<string>",
"size": "<string>"
}
]
},
"multipleReceivers": {
"uids": ["<string>"],
"guids": ["<string>"]
},
"tags": ["<string>"]
}
headers = {
"apikey": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {apikey: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
receiver: '<string>',
muid: '<string>',
category: 'message',
type: 'text',
data: {
text: '<string>',
metadata: {},
attachments: [
{
url: '<string>',
name: '<string>',
mimeType: '<string>',
extension: '<string>',
size: '<string>'
}
]
},
multipleReceivers: {uids: ['<string>'], guids: ['<string>']},
tags: ['<string>']
})
};
fetch('https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'receiver' => '<string>',
'muid' => '<string>',
'category' => 'message',
'type' => 'text',
'data' => [
'text' => '<string>',
'metadata' => [
],
'attachments' => [
[
'url' => '<string>',
'name' => '<string>',
'mimeType' => '<string>',
'extension' => '<string>',
'size' => '<string>'
]
]
],
'multipleReceivers' => [
'uids' => [
'<string>'
],
'guids' => [
'<string>'
]
],
'tags' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"apikey: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages"
payload := strings.NewReader("{\n \"receiver\": \"<string>\",\n \"muid\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"<string>\",\n \"metadata\": {},\n \"attachments\": [\n {\n \"url\": \"<string>\",\n \"name\": \"<string>\",\n \"mimeType\": \"<string>\",\n \"extension\": \"<string>\",\n \"size\": \"<string>\"\n }\n ]\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"<string>\"\n ],\n \"guids\": [\n \"<string>\"\n ]\n },\n \"tags\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("apikey", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"receiver\": \"<string>\",\n \"muid\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"<string>\",\n \"metadata\": {},\n \"attachments\": [\n {\n \"url\": \"<string>\",\n \"name\": \"<string>\",\n \"mimeType\": \"<string>\",\n \"extension\": \"<string>\",\n \"size\": \"<string>\"\n }\n ]\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"<string>\"\n ],\n \"guids\": [\n \"<string>\"\n ]\n },\n \"tags\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appId}.api-{region}.cometchat.io/v3/bots/{uid}/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"receiver\": \"<string>\",\n \"muid\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"<string>\",\n \"metadata\": {},\n \"attachments\": [\n {\n \"url\": \"<string>\",\n \"name\": \"<string>\",\n \"mimeType\": \"<string>\",\n \"extension\": \"<string>\",\n \"size\": \"<string>\"\n }\n ]\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"<string>\"\n ],\n \"guids\": [\n \"<string>\"\n ]\n },\n \"tags\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "1",
"conversationId": "cometchat-uid-3_user_cometchat-uid-5",
"sender": "cometchat-uid-3",
"receiverType": "user",
"receiver": "cometchat-uid-5",
"category": "message",
"type": "text",
"data": {
"text": "test hello",
"metadata": {
"key1": "val1"
},
"entities": {
"sender": {
"entity": {
"uid": "cometchat-uid-3",
"name": "Nancy Grace",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
"status": "offline",
"role": "default",
"createdAt": 1638361550
},
"entityType": "user"
},
"receiver": {
"entity": {
"uid": "cometchat-uid-5",
"name": "John Paul",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-5.webp",
"status": "offline",
"role": "default",
"createdAt": 1638361550,
"conversationId": "cometchat-uid-3_user_cometchat-uid-5"
},
"entityType": "user"
}
}
},
"sentAt": 1638423490,
"updatedAt": 1638423490
}
}Authorizations
API Key with fullAccess scope(i.e. Rest API Key from the Dashboard).
Path Parameters
An UID of the Bot.
Body
- Message
- Custom
The receiver of the message.
The muid will be a unique Identifier of the message.
The receiverType of the message. either user or group
user, group Category of the message. The available categories are message and custom.
message Type of the message. The available values are text, image, file, audio, video.
text, image, file, audio, video JSON containing message attributes.
Show child attributes
Show child attributes
JSON containing array of UIDs and GUID for whom the message must be sent. Format for multiple receivers - {"uids": ["uid1","uid2"], "guids":["guid1"]}
Show child attributes
Show child attributes
A list of tags to identify specific messages.
Response
Send Bot Message
Was this page helpful?