Conversation Webhook
The webhook will process the data for the chatbot. The webhook will daily publish the chat log history records to your CRM in JSON format.
Configuring a Webhook
To configure a webhook, you must have access to app.neoagent.co (contact app.neoagent.co support if you do not already have this access):
- Log in to app.neoagent.co and click on Workspace.
- Enter the configured endpoint webhook URL in the Webhook tab.
- Click Save.
Once the webhook URL is entered, the webhook signing key is automatically generated.
Receiving Endpoint
Trust the authenticity of your webhooks using the above-mentioned webhook signing key, a unique secret shared between your application and app.neoagent.co, to verify events sent to your endpoints. The webhook signing key will produce the X-Webhook-Signature, which you can use to compare against an expected webhook signature, to verify events coming from app.neoagent.co.
X-Webhook-Signature
When app.neoagent.co sends a webhook to your app, it will include the X-Webhook-Signature header in the following format:
X-Webhook-Signature: t=1492774577,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
Compare the X-Webhook-Signature, prefixed by v1=, with the expected signature. If they match, you can be sure that the event payload was issued by app.neoagent.co and has not been tampered with.
const crypto = require('crypto');
// Application webhook signing key
const webhookSigningKey = ({}).WEBHOOK_SIGNING_KEY;
// Extract the timestamp and signature from the header
const newoaksSignature = req.get('X-Webhook-Signature');
const { t, signature } = newoaksSignature.split(',').reduce((acc, currentValue) => {
const [key, value] = currentValue.split('=');
if (key === 't') {
// UNIX Timestamp
acc.t = value;
}
if (key === 'v1') {
acc.signature = value
}
return acc;
}, {
t: '',
signature: ''
});
if (!t || !signature) throw new Error('Invalid signature');
// Create the signed payload by concatenating the timestamp (t), the '.' character, and the JSON payload of the request body.
const data = t + '.' + JSON.stringify(req.body);
const expectedSignature = crypto.createHmac('sha256', webhookSigningKey).update(data, 'utf8').digest('hex');
// Determine the expected signature by calculating an HMAC using the SHA256 hash function.
if (expectedSignature !== signature) {
// The signature is invalid!
throw new Error('Invalid signature');
}
Listening for Chat Log Events
When an event occurs, it will be notified to the configured webhook URL. It sends all chat logs from all chatbots owned by users for the previous day at 2:00 AM every day (UTC time).
Notification details - HTTP POST request
Method: POST
Content-Type: application/json
Additional request headers
X-Webhook-Signature: Signature of the JSON body request
JSON Body
Example:
{
"Collection": [
{
"SerialNumber": "59001dd73709417321c58b11693183a2",
"Name": "test...",
"StartTime": "2023-11-21T00:00:00Z",
"EndTime": "2023-11-22T00:00:00Z",
"Conversations": [
{
"SessionID": 31302,
"CreateTime": "2023-11-21T16:22:42.264484Z",
"URI": "www.google.com",
"Messages": [
{
"Type": "AI",
"Content": "Hi What can I help you with?"
},
{
"Type": "User",
"Content": "make an appointment"
},
{
"Type": "AI",
"Content": "Please select the date and time..."
}
]
}
]
}
]
}
JSON Body Description:
- SerialNumber string Chatbot ID
- Name string Chatbot Name
- StartTime string Start Time (UTC time)
- EndTime string End Time (UTC time)
- Conversations Object array
- SessionID int Session ID
- CreateTime string Creation Time (UTC time)
- URI string Source URI
- Messages Object array
- Type string There are two types of messages, User and AI
- Content string Message content
Error retry
Response data: {"status":"success"} or {"status":"Success: test request received"} (case-sensitive, the required return value for a successful callback); returning other values is considered an error. In case of an error, retry within 1 minute and 3 minutes.