Skip to main content

Send Twilio Message

The AI Agent API provides functionality to send messages via Twilio by sending a POST request to the /chat/Chatbot/SendTwilioMessage endpoint.

Endpoint

Request URL: https://usapi.hottask.com/chat/Chatbot/SendTwilioMessage

Method: POST

Request Headers

The API request must include the following headers:

  • Authorization: <Your-Secret-Key> - string, required - The secret key for authenticating the API request
  • Content-Type: application/json - string, required - The content type of the request payload (must be application/json)

Request Body

The request body should contain the following parameters:

{
// string, required - The ID of the chatbot (found on the chatbot settings -> general -> chatbot ID)
"SerialNumber": "3254a9d0424c4806b9ea3d0763xxxxxx",
// string, required - Target phone number to send the message to
"ToPhoneNumber": "+1234567890",
// string, required - Content of the message to be sent
"Message": "Hello!"
}
  • SerialNumber - string, required - The ID of the chatbot (found on the chatbot settings -> general -> chatbot ID)
  • ToPhoneNumber - string, required - Target phone number to send the message to
  • Message - string, required - Content of the message to be sent

Example Request

JavaScript (Fetch API)

const res = await fetch('https://usapi.hottask.com/chat/Chatbot/SendTwilioMessage', {
method: 'POST',
headers: {
"Authorization": "<Your-Secret-Key>",
"Content-Type": "application/json"
},
body: JSON.stringify({
"SerialNumber": "3254a9d0424c4806b9ea3d0763xxxxxx",
"ToPhoneNumber": "+1234567890",
"Message": "Hello!"
})
});

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

Python (Requests Library)

import requests
import json

url = 'https://usapi.hottask.com/chat/Chatbot/SendTwilioMessage'
headers = {
"Authorization": "<Your-Secret-Key>",
"Content-Type": "application/json"
}
data = {
"SerialNumber": "3254a9d0424c4806b9ea3d0763xxxxxx",
"ToPhoneNumber": "+1234567890",
"Message": "Hello!"
}

response = requests.post(url, headers=headers, json=data)
data = response.json()
print(data)

cURL

curl 'https://usapi.hottask.com/chat/Chatbot/SendTwilioMessage' \
-X POST \
-H 'Authorization: <Your-Secret-Key>' \
-H 'Content-Type: application/json' \
-d '{"SerialNumber":"3254a9d0424c4806b9ea3d0763xxxxxx","ToPhoneNumber":"+1234567890","Message":"Hello!"}'

HTTP Request

POST /chat/Chatbot/SendTwilioMessage HTTP/1.1
Host: usapi.hottask.com
Authorization: <Your-Secret-Key>
Content-Type: application/json

{
"SerialNumber": "3254a9d0424c4806b9ea3d0763xxxxxx",
"ToPhoneNumber": "+1234567890",
"Message": "Hello!"
}

Response

The API response will be a JSON object with the following structure:

{
// object - The response data
"Data": {
"Status": "True",
// string - Error message if any
"Message": "test",
"SessionID": 123123123123
},
// string - API version
"Version": "1.0.0",
// boolean - Operation success status
"Success": true,
// integer - HTTP status code
"Code": 200,
// string - Error message if any
"Message": ""
}

Error Handling

If the request fails, you should: 1. Check the HTTP status code for network-level errors 2. Examine the `Code` and `Message` fields in the response for business-level errors 3. The `Message` field will contain detailed error information