The Human in the loop (HITL) interface allows you to implement human agent intervention in your integration.
Terminology
Throughout this document, we will use the following terms:External service requirements
The providing HITL functionality must support the following:- An API that allows creating .
- An API that allows creating .
- An API that allows adding messages to .
- An API that allows closing .
- Webhooks that can notify your of the following events:
- closure.
- assignment.
- reply.
Updating your package.json file
Finding the current interface version
The current version of thehitl interface is:
You will need this version number for the next steps.
Adding the interface as a dependency
Once you have the version, you can add it as a dependency to your :Add the dependencies section
bpDependencies section in your ‘s package.json file, create one:Add the interface as a dependency
bpDependencies section, add the as a dependency. For example, for version 2.0.0, you would add the following:Install the interface
bp add command to install it. This command will:- Download the interface from Botpress.
- Install it in a directory named
bp_modulesin your ‘s root directory.
Adding a helper build script
To keep your up to date, we recommend adding a helper build script to yourpackage.json file:
Add the build script
scripts section, add the following script:build script already exists in your package.json file, please replace it.npm run build, it will automatically install the and build your .
Editing your integration definition file
Adding the interface to your integration definition file
Now that the is installed, you must add it your integration definition file in order to implement it.Add an empty entity
new IntegrationDefinition() statement, add an empty entity:ticket or hitlTicket.Configuring the interface
The.extend() function takes two arguments:
- The first argument is a reference to the interface you want to implement. In this case, it’s
hitl. - The second argument is a configuration object. Using this object, you can override interface defaults with custom names, titles, and descriptions.
Renaming actions
Thehitl interface defines three actions that are used to interact with the :
createUser- Used by the to request the creation of a user in the and on Botpress.startHitl- Used by the to request the creation of a in the .stopHitl- Used by the to request the closure of a in the .
createUser to hitlCreateUser, you can do it like this:
Renaming events
Thehitl interface defines these events to notify the plugin of changes in the external service:
hitlAssigned- Emitted by your to notify the that a has been assigned to a .hitlStopped- Emitted by your to notify the that a has been closed.
hitlAssigned to agentAssigned, you can do it like this:
Renaming channels
Thehitl interface defines these channels:
hitl- Used by the to send and receive messages from the . This represents the communication channel for the , like a support ticket on Zendesk or a direct message thread on Slack.
hitl to supportTicket, you can do it like this:
Implementing the interface
Implementing the actions
Implementing createUser
The createUser action is used by the to request the creation of an (a requester) in the .
createUser in the “Configuring the interface” section, please use the new name instead of createUser.Create a Botpress user
client.createUser() method.Map the external user to the Botpress user
Map the Botpress user to the external user
Implementing startHitl
The startHitl action is used by the to request the creation of a (typically a ticket) in the .
startHitl in the “Configuring the interface” section, please use the new name instead of startHitl.Fetch the Botpress user
input.userId that was passed in the input parameters.Create a Botpress conversation
client.getOrCreateConversation() method.Map the Botpress conversation to the HITL session
ticketId tag on the Botpress conversation.Map the HITL session to the Botpress conversation
Relaying the conversation history
The input parameters of thestartHitl action contain a messageHistory parameter. This parameter contains the conversation history that should be relayed to the to provide the with context about the conversation. This parameter is an array of every message that was sent in the conversation prior to the being started.
If you decide to relay the conversation history to the , you can do so by iterating over the messageHistory array and sending each message to the using its API or SDK. However, doing so might cause a significant number of notifications being sent to the . To alleviate this, you can choose to send only the last few messages in the conversation history, or to concatenate the messages into a single message. For example you could combine messages like this:
Adding extra parameters to the startHitl action
If the requires extra parameters when starting a , you can add them to the hitlSession entity, or whichever name you chose for the entity in the Adding the interface to your integration definition file section. For example, if the requires a priority parameter, you can add it like this:
priority parameter in the “Start HITL” card within the Botpress Studio, allowing the bot authors to set it. The value of this parameter will then be passed to the startHitl action as part of the hitlSession input parameter:
Implementing stopHitl
The stopHitl action is used by the to request the closure of a (typically a ticket) in the .
stopHitl in the “Configuring the interface” section, please use the new name instead of stopHitl.Fetch the Botpress conversation
input.conversationId that was passed in the input parameters.Close the HITL session
reason parameter. Please ignore it. This parameter will be removed in future versions of the .Implementing the channel
Thehitl channel is used by the relay messages to the , which is usually a ticket or thread in the .
hitl in the “Configuring the interface” section, please use the new name instead of hitl.Retrieve the external user's ID
- If the payload contains a
userIdparameter, the message has been sent by the . Retrieve the ‘s ID from the tags of the Botpress userpayload.userId. - If the payload doesn’t contain a
userIdparameter, the message has been sent by the bot. Retrieve the ‘s ID from the tags of the attached Botpress user.
Implementing the events
You should set up webhooks so that the receives notifications about these events:- A new message is added to the (usually a ticket).
- A has been assigned to the .
- The was closed.
Incoming messages
When notified by the that a new message has been added to the , you should relay the message to the Botpress conversation:Retrieve the Botpress conversation's ID
Implementing hitlAssigned
When notified by the that a has been assigned to the , you should notify the by emitting the hitlAssigned event:
Retrieve the Botpress conversation's ID
hitlAssigned in the “Configuring the interface” section, please use the new name instead of hitlAssigned.Implementing hitlStopped
When notified by the that the was closed, you should notify the by emitting the hitlStopped event:
Retrieve the Botpress conversation's ID
hitlStopped in the “Configuring the interface” section, please use the new name instead of hitlStopped.