This page helps you setting up your agent webhooks.
The Webhook API guide allows you to set-up webhooks to receive a POST request when an event is triggered.
| Key | Type | Description |
|---|---|---|
| eventType | string | event type (eg. lead.submit) |
| agentId | string | Agent ID |
| payload | Object | Payload of the event |
1{
2 "eventType": "string", // event type (eg. lead.submit)
3 "agentId": "string", // Agent ID
4 "payload": { // Payload of the event
5 // ... event specific data
6 }
7}These are the list of events supported in webhooks.
When a customer submits their info (Name, Email, and Phone) to your agent.
1{
2 "conversationId": "string",
3 "customerEmail": "string",
4 "customerName": "string",
5 "customerPhone": "string"
6}Webhooks are used to receive events from all messaging channels your agent is connected to. Each channel delivers events to the same webhook URL with a channel field so you can route them appropriately.
Received when a user sends a message to your WhatsApp business number connected to the agent.
1{
2 "eventType": "message.received",
3 "channel": "whatsapp",
4 "agentId": "agent_abc123",
5 "payload": {
6 "from": "+1234567890",
7 "message": "Hello, I need help with my order",
8 "conversationId": "conv_xyz"
9 }
10}Received when a user messages your Telegram bot linked to the agent.
1{
2 "eventType": "message.received",
3 "channel": "telegram",
4 "agentId": "agent_abc123",
5 "payload": {
6 "chatId": 123456789,
7 "username": "john_doe",
8 "message": "What are your opening hours?",
9 "conversationId": "conv_xyz"
10 }
11}Received when a user sends a message to your Facebook Page linked to the agent.
1{
2 "eventType": "message.received",
3 "channel": "facebook",
4 "agentId": "agent_abc123",
5 "payload": {
6 "senderId": "fb_user_123",
7 "pageId": "fb_page_456",
8 "message": "Is this product still available?",
9 "conversationId": "conv_xyz"
10 }
11}Received when a user sends a DM to your Instagram account linked to the agent.
1{
2 "eventType": "message.received",
3 "channel": "instagram",
4 "agentId": "agent_abc123",
5 "payload": {
6 "senderId": "ig_user_789",
7 "message": "Do you ship internationally?",
8 "conversationId": "conv_xyz"
9 }
10}Received when an inbound email arrives at your agent's connected inbox.
1{
2 "eventType": "message.received",
3 "channel": "email",
4 "agentId": "agent_abc123",
5 "payload": {
6 "from": "customer@example.com",
7 "subject": "Order inquiry",
8 "message": "I placed an order yesterday and have not received a confirmation.",
9 "conversationId": "conv_xyz"
10 }
11}Received when a visitor sends a message through the embedded chat widget on your website.
1{
2 "eventType": "message.received",
3 "channel": "web",
4 "agentId": "agent_abc123",
5 "payload": {
6 "sessionId": "session_abc",
7 "message": "Hi, I need help!",
8 "conversationId": "conv_xyz",
9 "pageUrl": "https://yoursite.com/pricing"
10 }
11}Tip: Use the channel field in the webhook payload to route incoming events to different handlers in your backend.
You can receive the payload by accessing the body same as any request.
It is recommended to check the request header x-chatzuri-signature for securing your endpoint from spam.
You can achieve this by using SHA-1 (Secure Hash Algorithm 1) function to generate a signature for the request and compare it with x-chatzuri-signature found in the request headers. If they are identical then the request is from Chatzuri.
1import crypto from 'crypto'
2import { Request, Response } from 'express'
3
4export async function webhookHandler(req: Request, res: Response) {
5 if (req.method === 'POST') {
6 const { SECRET_KEY } = process.env
7
8 const receivedJson = req.body
9 const rawBody = Buffer.from(JSON.stringify(receivedJson))
10 const bodySignature = sha1(rawBody, SECRET_KEY)
11
12 if (bodySignature !== req.headers['x-chatzuri-signature']) {
13 return res.status(400).json({ message: "Signature didn't match" })
14 }
15
16 console.log('Received:', receivedJson)
17
18 res.status(200).json({ status: "accepted" })
19 } else {
20 res.setHeader('Allow', 'POST')
21 res.status(405).end('Method Not Allowed')
22 }
23}
24
25function sha1(data: Buffer, secret: string): string {
26 return crypto.createHmac('sha1', secret).update(data).digest('hex')
27}Return a JSON object with the following structure to indicate your endpoint has received the event webhook:
1{
2 "status": "accepted"
3}If there are any errors during the API request, appropriate HTTP status codes will be returned along with error messages in the response body.
That's it! You should now be able to retrieve list of agent's from your account using our API.