Automating AI Chatbots Inquiry with Webhooks

Learn how to integrate webhooks with your AI chatbot to receive real-time inquiry notifications.


Webhook Feature Overview

The Webhook feature allows your chatbot to send real-time notifications to your systems whenever a user submits an inquiry. This powerful integration enables you to connect your chatbot with your existing customer support systems, CRMs, or custom applications.

How it Works

When a user submits an inquiry through your chatbot, the system can automatically send a webhook notification to a URL you specify. The webhook contains all the relevant information about the inquiry, including:

  1. The user's email address
  2. The inquiry message
  3. The complete conversation thread leading up to the inquiry
  4. Metadata about the chatbot and inquiry

This allows you to:

  • Automatically create support tickets in your helpdesk system
  • Log customer inquiries in your CRM
  • Trigger custom workflows based on user inquiries
  • Maintain a complete record of the conversation context

Setting Up Webhooks

To configure webhooks for your chatbot:

  1. Navigate to your chatbot's settings in the dashboard
  2. Go to the "Inquiry Settings" section
  3. Enable the "Webhook Notifications" toggle
  4. Enter your webhook URL - this is the endpoint where inquiry data will be sent
  5. (Optional) Set a webhook secret for security verification
  6. (Optional) Customize the header name for your webhook secret
  7. Save your changes

Webhook Security

To ensure the security of your webhook integration, we provide a simple authentication mechanism:

  1. When you configure a webhook, you can set a secret key
  2. This secret key will be included in the X-Webhook-Secret header (or your custom header name)
  3. When your system receives a webhook request, verify that the header value matches your configured secret

This approach ensures that only systems with knowledge of your secret can verify the authenticity of webhook requests.

Webhook Payload Format

The webhook sends a JSON payload with the following structure:

{
  "inquiry": {
    "inquiry": {
      "id": "inq_123456789",
      "email": "user@example.com",
      "message": "I need help with my account",
      "threadId": "thread_987654321",
      "createdAt": "2023-06-15T14:32:21Z"
    },
    "chatbot": {
      "id": "chat_123456789",
      "name": "Support Assistant"
    },
    "thread": [
      {
        "message": "How do I reset my password?",
        "response": "You can reset your password by clicking on the 'Forgot Password' link on the login page.",
        "createdAt": "2023-06-15T14:30:15Z"
      },
      {
        "message": "I don't see that link anywhere",
        "response": "I apologize for the confusion. The 'Forgot Password' link should be located directly below the login form. If you're still having trouble, would you like to speak with our support team?",
        "createdAt": "2023-06-15T14:31:45Z"
      }
    ]
  }
}

Handling Webhook Requests

When implementing a webhook receiver, follow these best practices:

  1. Verify the webhook secret to ensure the request is authentic
  2. Respond quickly with a 200 status code to acknowledge receipt
  3. Process webhooks asynchronously if the processing might take time
  4. Implement retry logic in case your endpoint is temporarily unavailable
  5. Log webhook payloads for debugging and auditing purposes

Example Webhook Receiver (Node.js)

Here's a simple example of a webhook receiver implemented in Node.js with Express:

const express = require('express');
const app = express();
app.use(express.json());
 
const WEBHOOK_SECRET = 'your-webhook-secret';
 
app.post('/webhook', (req, res) => {
  // Verify the webhook secret
  const secret = req.headers['x-webhook-secret'];
  if (secret !== WEBHOOK_SECRET) {
    return res.status(401).send('Unauthorized');
  }
  
  // Acknowledge receipt immediately
  res.status(200).send('OK');
  
  // Process the webhook asynchronously
  const { inquiry } = req.body;
  processInquiry(inquiry).catch(console.error);
});
 
async function processInquiry(inquiry) {
  // Your logic to handle the inquiry
  console.log('New inquiry received:', inquiry.inquiry.message);
  console.log('From:', inquiry.inquiry.email);
  console.log('Conversation history:', inquiry.thread);
  
  // Example: Create a ticket in your support system
  // await createSupportTicket(inquiry);
}
 
app.listen(3000, () => {
  console.log('Webhook receiver listening on port 3000');
});

Troubleshooting Webhooks

If you're experiencing issues with your webhook integration:

  1. Check your webhook URL - ensure it's correct and publicly accessible
  2. Verify your server is accepting POST requests with JSON content
  3. Check your logs for any errors in processing the webhook
  4. Ensure your endpoint responds with a 200 status code to acknowledge receipt
  5. Test your webhook endpoint with a tool like Postman or curl

For additional assistance, contact our support team.

Webhook Limitations

  • Webhooks are only triggered for user inquiries, not for regular chat messages
  • The webhook URL must be publicly accessible from the internet
  • Webhook delivery may be delayed during periods of high system load
  • Webhook requests will timeout after 10 seconds

By leveraging webhooks, you can create powerful integrations between your chatbot and your existing business systems, providing a seamless experience for your users and your support team.