Webhooks¶
Webhooks enable real-time event notifications from Unique AI to your application, allowing you to respond to user interactions and system events as they happen.
Overview¶
A core functionality of Unique AI is the ability for users to engage in an interactive chat feature. SDK developers can hook into this chat to provide new functionalities.
Your App (refer to app-id in Configuration) must be subscribed to each individual Unique event in order to receive a webhook.
Webhook Headers¶
Each webhook sent by Unique includes a set of headers:
Success & Retry Logic¶
- Success: Webhooks are considered successfully delivered if your endpoint returns a status code between
200and299. - Retry: If your endpoint returns a status code of
300-399,429, or500-599, Unique will retry the delivery of the webhook with an exponential backoff up to five times. - Expired: If your endpoint returns any other status (e.g.,
404), it is marked as expired and will not receive any further requests.
Signature Verification¶
The webhook body, containing a timestamp of the delivery time, is signed with HMAC-SHA256. Always verify the signature to ensure the webhook is authentic and from Unique AI.
Basic Verification¶
Custom Tolerance¶
The construct_event method will compare the signature and raise a unique_sdk.SignatureVerificationError if the signature does not match. It will also raise this error if the createdAt timestamp is outside of a default tolerance of 5 minutes.
Adjust the tolerance by passing a fifth parameter to the method (tolerance in seconds):
Available Events¶
User Message Created¶
Event Name: unique.chat.user-message.created
This webhook is triggered for every new chat message sent by the user. This event occurs regardless of whether it is the first or a subsequent message in a chat.
Payload Structure:
Use Cases:
- Log user interactions
- Trigger custom workflows
- Integrate with external systems
- Monitor chat activity
Example Handler:
External Module Chosen¶
Event Name: unique.chat.external-module.chosen
This webhook is triggered when the Unique AI selects an external module as the best response to a user message. The module must be marked as external and available for the assistant used in the chat to be selected by the AI.
Unique's UI will create an empty assistantMessage below the user message and update this message with status updates.
⚠️ Important: The SDK is expected to modify this assistantMessage with its answer to the user message.
Payload Structure:
Example Handler:
Best Practices¶
Use Async Processing for Long Operations
For long-running operations, acknowledge the webhook quickly and process asynchronously:
Related Resources¶
- Message API - Modify assistant messages
- Message Log API - Update execution steps
- Message Execution API - Track long-running operations
- Configuration Guide - Set up your app credentials
- Tutorials - Step-by-step tutorials and guides