Chatbot Message Count
The Neoagent API allows you to obtain the number of messages in the history of a specific chatbot by sending a POST request to the /chat/Chatbot/GetMessageCountByChatbot endpoint.
Endpoint
Request URL: https://app.neoagent.co/chat/Chatbot/GetMessageCountByChatbot
Method: POST
Required Headers
Authorization: <Your-Secret-Key>- string, mandatory - The secret key to authenticate the API request
Request Body
{
"SerialNumber": "36XXGxiYDigrQgg5xz4n45bcBW7qeYyW35"
}
Parameters
SerialNumber- string, mandatory - The unique identifier of the chatbot
Request Examples
- JavaScript (Fetch API)
- Python (Requests)
- cURL
- HTTP Raw
const res = await fetch('https://app.neoagent.co/chat/Chatbot/GetMessageCountByChatbot', {
method: 'POST',
headers: {
"Authorization": "<Your-Secret-Key>"
},
body: JSON.stringify({
"SerialNumber": "36XXGxiYDigrQgg5xz4n45bcBW7qeYyW35"
})
});
const data = await res.json();
console.log(data);
import requests
import json
url = 'https://app.neoagent.co/chat/Chatbot/GetMessageCountByChatbot'
headers = {
"Authorization": "<Your-Secret-Key>"
}
data = {
"SerialNumber": "36XXGxiYDigrQgg5xz4n45bcBW7qeYyW35"
}
response = requests.post(url, headers=headers, json=data)
data = response.json()
print(data)
curl 'https://app.neoagent.co/chat/Chatbot/GetMessageCountByChatbot' \
-X POST \
-H 'Authorization: <Your-Secret-Key>' \
-d '{"SerialNumber":"36XXGxiYDigrQgg5xz4n45bcBW7qeYyW35"}'
POST /chat/Chatbot/GetMessageCountByChatbot HTTP/1.1
Host: app.neoagent.co
Authorization: <Your-Secret-Key>
{
"SerialNumber": "36XXGxiYDigrQgg5xz4n45bcBW7qeYyW35"
}
Response
The API response will be a JSON object with the following structure:
{
// int - Number of messages for the chatbot
"Data": 13,
// string - API version
"Version": "1.0.0",
// boolean - Success status of the operation
"Success": true,
// integer - HTTP status code
"Code": 200,
// string - Error message if present
"Message": ""
}
Response Fields
Data- integer - Total number of messages in the chatbot's historyVersion- string - Version of the API usedSuccess- boolean - Indicates whether the operation was successfulCode- integer - HTTP status codeMessage- string - Error message or additional information
Use Cases
📊 Analytics and Reporting
Use this API for:
- Activity tracking - Monitor conversation volume
- Periodic reporting - Generate monthly/weekly statistics
- Trend analysis - Identify usage peaks
- Billing and invoicing - Calculate costs based on usage
🔄 Automation
Integrate into your workflows for:
- Automatic alerts - Notifications for usage thresholds
- Dynamic scaling - Adjust resources based on traffic
- Maintenance scheduling - Schedule maintenance during low activity periods
Practical Example
async function getChatbotStats(serialNumber, apiKey) {
try {
const response = await fetch('https://app.neoagent.co/chat/Chatbot/GetMessageCountByChatbot', {
method: 'POST',
headers: {
'Authorization': apiKey
},
body: JSON.stringify({
'SerialNumber': serialNumber
})
});
const result = await response.json();
if (result.Success) {
const messageCount = result.Data;
console.log(`Chatbot ${serialNumber} has processed ${messageCount} messages`);
// Business logic based on count
if (messageCount > 1000) {
console.log('⚠️ High volume - consider upgrading the plan');
} else if (messageCount < 10) {
console.log('📈 New chatbot - monitor adoption');
}
return messageCount;
} else {
throw new Error(result.Message);
}
} catch (error) {
console.error('Error retrieving statistics:', error);
return null;
}
}
// Usage
getChatbotStats('36XXGxiYDigrQgg5xz4n45bcBW7qeYyW35', 'your-api-key');
Analytics Dashboard
Example of how to integrate into a dashboard:
async function buildChatbotDashboard(chatbotIds, apiKey) {
const stats = [];
for (const id of chatbotIds) {
const count = await getChatbotStats(id, apiKey);
stats.push({
chatbotId: id,
messageCount: count,
status: count > 100 ? 'active' : 'low-activity'
});
}
// Sort by activity
stats.sort((a, b) => b.messageCount - a.messageCount);
return stats;
}
Error Handling
If the request fails, you should:
- Check the HTTP status code for network level errors
- Examine the
CodeandMessagefields in the response for business level errors - The
Messagefield will contain detailed information about the error
Possible Errors
| Code | Description | Suggested Action |
|---|---|---|
| 400 | Missing or invalid SerialNumber | Check the format of the SerialNumber |
| 401 | Invalid API key | Check authentication credentials |
| 404 | Chatbot not found | Verify that the chatbot exists |
| 429 | Rate limit exceeded | Implement retry with backoff |
Error Handling Example
async function safeGetMessageCount(serialNumber, apiKey) {
try {
const response = await fetch(/* ... */);
const result = await response.json();
if (!result.Success) {
switch (result.Code) {
case 404:
console.error('Chatbot not found:', serialNumber);
break;
case 401:
console.error('Invalid credentials');
break;
default:
console.error('API error:', result.Message);
}
return null;
}
return result.Data;
} catch (error) {
console.error('Network error:', error);
return null;
}
}
Performance Tip
For dashboards with many chatbots, consider implementing batch requests or caching results to avoid exceeding rate limits.