The Human in the loop (HITL) interface allows you to implement human agent intervention in your integration.
startHitl
action. This is useful to provide extra information about the HITL session, such as a ticket priority or customer identification number.package.json
filehitl
interface is:
You will need this version number for the next steps.
Open the package.json file
package.json
file.Add the bpDependencies section
bpDependencies
section in your integration‘s package.json
file, create one:Add the interface as a dependency
bpDependencies
section, add the HITL interface as a dependency. For example, for version 2.0.0
, you would add the following:"<interface-name>": "interface:<interface-name>@<version>"
.Save the package.json file
package.json
file.Install the interface
bp add
command to install it. This command will:bp_modules
in your integration‘s root directory.package.json
file:
Open the package.json file
package.json
file.Add the build script
scripts
section, add the following script:build
script already exists in your package.json
file, please replace it.Save the package.json file
package.json
file.npm run build
, it will automatically install the HITL interface and build your integration.
Open the integration.definition.ts file
integration.definition.ts
file.Import the interface
Add an empty entity
new IntegrationDefinition()
statement, add an empty entity:ticket
or hitlTicket
.Extend your definition
.extend()
function at the end of your new IntegrationDefinition()
statement:.extend()
will be explained in the next section..extend()
function takes two arguments:
hitl
.hitl
interface defines three actions that are used to interact with the external service:
createUser
- Used by the HITL plugin to request the creation of a user in the external service and on Botpress.startHitl
- Used by the HITL plugin to request the creation of a HITL session in the external service.stopHitl
- Used by the HITL plugin to request the closure of a HITL session in the external service.createUser
to hitlCreateUser
, you can do it like this:
startHitl
to createTicket
and stopHitl
to closeTicket
. These systems use tickets to represent help requests, so renaming actions to match their terminology makes your integration clearer and easier to understand.hitl
interface defines these events to notify the plugin of changes in the external service:
hitlAssigned
- Emitted by your integration to notify the HITL plugin that a human agent has been assigned to a HITL session.hitlStopped
- Emitted by your integration to notify the HITL plugin that a HITL session has been closed.hitlAssigned
to agentAssigned
, you can do it like this:
hitl
interface defines these channels:
hitl
- Used by the HITL plugin to send and receive messages from the external service. This represents the communication channel for the HITL session, like a support ticket on Zendesk or a direct message thread on Slack.hitl
to supportTicket
, you can do it like this:
createUser
createUser
action is used by the HITL plugin to request the creation of an external user (a requester) in the external service.
createUser
in the “Configuring the interface” section, please use the new name instead of createUser
.Create a Botpress user
client.createUser()
method.Create an external user
Map the external user to the Botpress user
Map the Botpress user to the external user
Yield control back to the plugin
startHitl
startHitl
action is used by the HITL plugin to request the creation of a HITL session (typically a ticket) in the external service.
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.Retrieve the external user's ID
Create a Botpress conversation
client.getOrCreateConversation()
method.Create the HITL session
Map the Botpress conversation to the HITL session
ticketId
tag on the Botpress conversation.Map the HITL session to the Botpress conversation
Yield control back to the plugin
startHitl
action contain a messageHistory
parameter. This parameter contains the conversation history that should be relayed to the external service to provide the human agent with context about the conversation. This parameter is an array of every message that was sent in the conversation prior to the HITL session being started.
If you decide to relay the conversation history to the external service, you can do so by iterating over the messageHistory
array and sending each message to the external service using its API or SDK. However, doing so might cause a significant number of notifications being sent to the external service. 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:
startHitl
actionhitlSession
entity, or whichever name you chose for the entity in the Adding the interface to your integration definition file section. For example, if the external service 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:
stopHitl
stopHitl
action is used by the HITL plugin to request the closure of a HITL session (typically a ticket) in the external service.
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.Retrieve the HITL session's ID
Close the HITL session
Yield control back to the plugin
reason
parameter. Please ignore it. This parameter will be removed in future versions of the HITL interface.hitl
channel is used by the HITL plugin relay end user messages to the HITL session, which is usually a ticket or thread in the external service.
hitl
in the “Configuring the interface” section, please use the new name instead of hitl
.Retrieve the HITL session's ID
Retrieve the external user's ID
userId
parameter, the message has been sent by the end user. Retrieve the external user‘s ID from the tags of the Botpress user payload.userId
.userId
parameter, the message has been sent by the bot. Retrieve the external user‘s ID from the tags of the attached Botpress user.Send the message to the HITL session
Retrieve the Botpress conversation's ID
Retrieve the external user's ID
Add a message to the Botpress conversation
client.createMessage()
method.hitlAssigned
hitlAssigned
event:
Retrieve the Botpress conversation's ID
Retrieve the external user's ID
Emit the hitlAssigned event
hitlAssigned
event by calling the client.createEvent()
method.hitlAssigned
in the “Configuring the interface” section, please use the new name instead of hitlAssigned
.hitlStopped
hitlStopped
event:
Retrieve the Botpress conversation's ID
Retrieve the external user's ID
Emit the hitlStopped event
hitlStopped
event by calling the client.createEvent()
method.hitlStopped
in the “Configuring the interface” section, please use the new name instead of hitlStopped
.