Oracle Digital Assistant – Add a delay between messages with a Custom Component

ODA

From a chatbot design point of view, best practices say that the response messages should not all go at the same time like a machine-gun.

Lets look to an example. The below example could be a welcoming dialog (or monolog) as the bot introduces himself. What would be better, the 4 lines all displayed at the same time, or having a small half-second delay between each line?

  • Hello, I am Asimov, your SiFi bot
  • You can ask me about SiFi books and movies
  • I have a big source of data at my hand
  • What do you want to know?

Now the main question is: How to implement this?

The answer, is by using the Bot Node SDK to create a custom component.

'use strict';
module.exports = {
metadata: () => ({
name: 'delay_dt',
properties: {
milliseconds: { required: true, type: 'number' },
},
supportedActions: ['sucess', 'failure']
}),
invoke: (conversation, done) => {
var millis = conversation.properties().milliseconds;
setTimeout (() => {
conversation.logger().info("Starting Delay of "+millis+" miliseconds");
conversation.transition('sucess');
conversation.keepTurn(true);
done();
}, millis);
}
};
view raw delay.js hosted with ❤ by GitHub

I am not a Nodejs expert, so probably there are better ways of doing this. I did however stayed with the basics and used a SetTimeout function that executes once the timeout finalizes.

Then we can invoke this component from the dialog flow with the below code. I am not making use of the available transitions defined in the custom component, so you can ignore that part!

delay1: 
    component: "delay_dt" 
    properties: 
      milliseconds: 5000      
    transitions:
      next: message2

Quite simple and very handy – it gives a completely different feel to the chatbot!

0