How Should i implement hitl in the botpress how user will swtich to the hitl module plz provide a roadmap for it

How Should i implement hitl in the botpress how user will swtich to the hitl module
plz provide a roadmap for it

Just want to get your question clear. Do you want to implement a functionality where the bot pauses and sends a message to a human agent (on the users request of course). Then the human finds the conversation thread in hitl and talks to the user.

yes that only i want to implement

how to implement above functionality

Step 1: Open the bot config file from data\global\bot.config.json

Step 2: Just enter true as shown belo

image

Step 3: Restart your BP.exe

Step 4: Now you can see HITL module

Step 5: Use this Toggle icon to turn off/ on bot response

Hi Manoj,
Can we able to pause the conversation via API request?
i have gone through document , we can able to pause conversation through api request as well, but when i access the provided API. It is not working

  • POST /mod/hitl/sessions/{$id}/pause

Response :
Cannot POST /hitl/sessions/156085638552453280/pause

Please help me out

Is it possible to also automate this, instead of the admin physically pausing/unpausing ?
For example :
user has a choice option to talk to an agent
when the button is clicked, the conversation is paused automatically and the agent gets a notification then proceeds to chat with agent.

You can pause a conversation by performing an API-request :

POST /mod/hitl/channel/{$channel}/user/{$userId}/pause
POST /mod/hitl/sessions/{$id}/pause

Take a look at the Human In The Loop tutorial in documentation.

How are you doing your POST call ?

I have never done it myself but I guess you need to perfom a POST in an action using axios.

Here is a tutorial from Botpress team to call an API in an action.

Alternatively, you can use the Call API Skill to do the POST directly from UI.

Thanks for your help.

Now i am getting " Unauthorized: Authorization header is missing ", How to get token to call API ?

Try to use header as
{
“Content-Type”: “application/json”
}

Is it possible to replace the id numbers with a user name?

Thanks guys… it worked… We require bearer token to access hitl service.
To get bearer token :
[App Login details]
let params = {
“email”: "XXXX@iopex.com",
“password”: “XXXXX”
}
// Call the below link to get bearer token
const login = await axios.post(‘APPURL/api/v1/auth/login’,params)
let token=login.data.payload.token

var headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer '+token
    }

var pauseurl=‘APPURL/api/v1/bots/’+event.botId+’/mod/hitl/sessions/’+event.threadId+’/pause’
const data = await axios.post(pauseurl,params,{headers: headers})

[maniskec] hi can you give more information on hitl above code in which file we should add it , we have to make a javascript function for that ?

Yes… i have tried to pause bot conversation by my program.

For few intents , i have created a flow and i have executed a JS file to pause bot conversation and notify admin .

how could you do that did you make a function in action.js file ?

Here is my custom JS file. I have tried to push notification in admin panel and pause the conversation thread in hitl.

“use strict”;
/**

Connect to the real agents
@title To Connect to the real agents
@category Bots
@author Manikandan K - mani.skec@gmail.com
*/
const axios = require(‘axios’);
const callApi = async () => {
#This will create notification in admin panel
const message = user.nickname + ’ wants to talk to a real agent’
bp.notifications.create(event.id,{
message: message,
level: ‘info’,
url: ‘/mod/hitl’
})
#login details of botpress admin
let params = {
“email”: “XXXXXX”,
“password”: “XXXXX”
}

#We call the below login url to get token
const login = await axios.post(‘http://XXXXX:3000/api/v1/auth/login’,params)
if(login.status && login.status==200){
let token=login.data.payload.token
var headers = {
‘Content-Type’: ‘application/json’,
‘Authorization’: ‘Bearer ‘+token
}
#to pause conversation
var pauseurl=‘http://XXXXX:3000/api/v1/bots/’+event.botId+’/mod/hitl/sessions/’+event.threadId+’/pause’
console.log(pauseurl);
const data = await axios.post(pauseurl,params,{headers: headers})
console.log(data)
}
}

// Actions are async, so make sure to return a promise
return callApi()

1 Like

@sylvain , currently i am working in HITL module. Initially it was worked perfectly , it pauses the right conversation via program.

Now i have a problem , I am using postgres to store all logs and when i try pause conversation using programtically . It is pausing different conversation.

Any idea, How should i overcome this issue. Please let me know for more clarification.

@maniskec
I am trying to use the HITL API but I am getting a 401 Unauthorized error for both the /mod/hitl/ and auth/login.
Do I need a Pro licence to use this?

Pro version is not required.

First you required to get token using below:

#login details of botpress admin
let params = {
“email”: “XXXXXX”,
“password”: “XXXXX”
}
#We call the below login url to get token
const login = await axios.post('http://XXXXX:3000/api/v1/auth/login’,params)
let token=login.data.payload.token

use the token as header for /mod/hitl/ API’s
Note: All Botpress API requires token for security reasons.