Prerequisites
You will need:
- A Botpress Plus plan or higher
- The HITL integration and plugin configured so agents can join conversations
1. Create conversation variables
Create the following two variables in your bot, scoped as Conversation variables:| Variable Name | Type | Description |
|---|---|---|
hitlRequestTimestamp | number | Unix timestamp (ms) of when the HITL request was made |
hitlTimingDisplay | string | Formatted summary string of the timing result |
2. Capture the request timestamp
Before your Start HITL Card, insert an Execute Code Card that records when the user was handed off to HITL. Use the following code:The Unix Epoch is January 1, 1970 at 00:00:00 UTC. Timestamps in “milliseconds since the Unix epoch” are the number of milliseconds elapsed since that moment.
3. Calculate and format the wait time
After your Start HITL Card, insert another Execute Code Card that computes the time until an agent was assigned and formats the result. Use the following code:- Fetches the upstream conversation using the current conversation ID.
- Resolves the downstream HITL conversation via the
hitl#downstreamtag (set automatically by Botpress when a handoff is initiated). - Reads the
hitl:assignedAttag from the downstream conversation (timestamp of when an agent accepted and assigned). - Computes the wait time between the request and assignment.
- Formats and stores the result in
conversation.hitlTimingDisplay.
conversation.hitlTimingDisplay will contain a message in this format:
Times are displayed in the America/New_York timezone. Update the
timeZone value in the fmt function if your team operates in a different timezone.4. Use the data
Theconversation.hitlTimingDisplay variable is available for the rest of your Workflow. You can:
- Display it in chat: Add a Text Card and reference
{{conversation.hitlTimingDisplay}}to send the summary to the conversation (useful for testing and QA). - Log it to a Botpress Table: Use an Update Table Row or Insert Table Row Card to persist the data for reporting.
- Send it to an external system: Use an Execute Code Card with an
axiosorfetchcall to forward the values to your analytics platform, CRM, or data warehouse.
You can now measure Time to First Agent Response for HITL conversations and use the result in your bot Workflows, tables, or external systems.