Webhooks and Callbacks
Set up a webhook server to generate a callback URL that receives event notifications from Tavus API.
Conversation Callbacks
If a callback_url
is provided in the Create Conversation API Request, callbacks will provide insight into the conversation’s state. These can be system-related (e.g. replica joins and room shutdowns) or application-related (e.g. final transcription parsing and recording-ready webhooks). Additional webhooks coming soon.
Structure
All Conversation callbacks share the following basic structure. Differences will occur in the properties
object.
Types
Our callbacks are split into two main categories:
System Callbacks
These callbacks are to provide insight into system-related events in a conversation. They are:
- system.replica_joined: This is fired when the replica becomes ready for a conversation.
- system.shutdown: This is fired when the room shuts down, for any of the following reasons:
max_call_duration reached
participant_left_timeout reached
participant_absent_timeout reached
bot_could_not_join_meeting_it_was_probably_ended
daily_room_has_been_deleted
exception_encountered_during_conversation_startup
end_conversation_endpoint_hit
internal error occurred at step x
Examples:
Application Callbacks
These callbacks are to inform developers about logical events that take place. They are:
- application.transcription_ready: This is fired after ending a conversation, where the chat history is saved and returned.
- application.recording_ready: This is fired if you had enabled recording on, set up a custom S3 bucket for recording and started a recording inside the room at any point. This will point to the key at which your new recording lies, useful for serving recordings through a CDN.
- application.perception_analysis: This is fired after ending a conversation, when the replica has finished summarizing the visual artifacts that were detected throughout the call. This is a feature that is only available when the persona has
raven-0
specified in the Perception Layer.
Examples:
Replica Training Callbacks
If a callback_url
is provided in the POST /replicas
call, you will receive a callback on replica training completion or on replica training error.
On error, the error_message
parameter will contain the error message. You can learn more about API Errors and Status Details here
Video Generation Callbacks
If a callback_url
is providing in the POST /videos
call, you will receive callbacks on video generation completed and on video error.
On error, the status_details
parameter will contain the error message. You can learn more about API Errors and Status Details here
Sample Webhook Setup
Create a sample webhook endpoint using Python Flask, and expose it publicly with ngrok.
Prerequisites
Install Python Dependencies
Install the Python dependencies needed to create the server.
Make a Webhook Server
Set up a webhook server and save it as server.py
.
The server will receive and process webhook callbacks from Tavus, handle different event types, store transcripts in memory, and analyze conversation data for each session.
Run the Server
Run the app using the following command in the terminal:
The server should run on port 5000
.
Forward the Port Using Ngrok
Open a terminal in the folder containing ngrok.exe
, then use Ngrok to forward the port.
The command will generate a forwarding link (e.g., https://1234567890.ngrok-free.app), which can be used as the callback URL.
Use the callback URL
Include the callback URL in your request to Tavus by appending /webhook
to the forwarding link and setting it in the callback_url
field.