Reputation: 31
I am trying to make a DirectLine connection to Health bot and chose one of the pre-set scenarios. I plan to have several scenarios set up with HealthBot and want to be able to trigger them on demand.
The only example of triggering a scenario I could find was for WebChat which I am not using, you can find it here:
https://github.com/microsoft/HealthBotContainerSample/blob/master/public/index.js.
I also found https://www.linkedin.com/pulse/microsoft-healthcare-bot-covid-19-triage-scenario-up-ravichander/ which recommends doing:
dl.postActivity({
type: "invoke",
value: {
trigger: "covid19"
},
locale: 'en-US',
from: user,
name: "TriggerScenario"
})
I've tried to do this:
this.directLine.postActivity(
{
type: "event",
locale: "en-us",
textFormat: "plain",
from: { id: "server", name: "server", role: "user" },
name: "TriggerScenario",
value: {
trigger: "MyScenario",
args: {
myVar1: "{custom_arg_1}",
myVar2: "{custom_arg_2}"
}
}
}).subscribe(console.log,console.error);
It's not mentioned anywhere in the documentation of DirectLineJS that it can be used like that, however it is triggering correct scenario and passing the arguments to the bot correctly.
The issue I'm having seems to be more related to the HealthBot itself, as it is not recognising any user input and returns generic message defined in Default reply for utterances that are not understood
.
Has anyone got any experience with that level of customization and could advise how to trigger scenarios on demand via DirectLineJS using postActivity
.
Is there anything wrong in the way I am triggering the scenario?
Upvotes: 1
Views: 605
Reputation: 31
I seems that I have resolved the mystery. The scenarios are triggered correctly with my code. The issue was down to the Health Bot not recognizing user input properly. I have resolved it with adding some guards in the scenario itself.
Upvotes: 2
Reputation: 1
The sample code https://github.com/microsoft/HealthBotContainerSample/blob/master/public/index.js, has the correct example, if you are using WebChat V4. Just uncomment the triggeredScenario object and replace the trigger property with your scenario id.
store.dispatch({
type: 'DIRECT_LINE/POST_ACTIVITY',
meta: {method: 'keyboard'},
payload: {
activity: {
type: "invoke",
name: "InitConversation",
locale: user.locale,
value: {
// must use for authenticated conversation.
jsonWebToken: jsonWebToken,
// Use the following activity to proactively invoke a bot scenario
/*
triggeredScenario: {
trigger: "{scenario_id}",
args: {
myVar1: "{custom_arg_1}",
myVar2: "{custom_arg_2}"
}
}
*/
}
}
}
});
Upvotes: 0