Skip to main content

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

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);

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 history
  • Version - string - Version of the API used
  • Success - boolean - Indicates whether the operation was successful
  • Code - integer - HTTP status code
  • Message - 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:

  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 information about the error

Possible Errors

CodeDescriptionSuggested Action
400Missing or invalid SerialNumberCheck the format of the SerialNumber
401Invalid API keyCheck authentication credentials
404Chatbot not foundVerify that the chatbot exists
429Rate limit exceededImplement 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.