How to use HTML Directive
In this document, you will learn to use an HTML directive and get user input.
If you call a 3rd party site for javascript or CSS, you will need to white list their domain.
For illustration, we will use a simple HTML form in the HTML directive to get the data from the user and post it to an intent.
Â
Template node
<html>
<head>
<style>
</style>
<script type="text/javascript">
</script>
</head>
<body>
<form>
<p><label for="fname">First name:</label> <input type="text" id="fname" name="fname"></p>
<p><label for="lname">Last name:</label> <input type="text" id="lname" name="lname"></p>
<p style="text-align: center;"><button onclick="window.parent.htmlFormSendData(event)">Submit</button></p>
</form>
</body>
</html>
HTML DirectiveÂ
Use the HTML form (above) in the HTML Directive (below).
msg.payload.orbita = msg.payload.orbita || {};
msg.payload.orbita.directive = msg.payload.orbita.directive || [];
//node.warn(msg.payload.multiagent.chat.chatText );
msg.payload.orbita.directive.push({
type: "html5",
options: {
template: "400x150",
url: `/oeapi/userdata`
}
});
return msg;
Property | Description |
---|---|
| The type should be set to html5 to invoke the HTML Directive. |
| The options object contains the following properties.
|
| (OPTIONAL) The template property defines the size of HTML content. |
| HTML if url is empty |
url: | URL to the HTML page |
| (OPTIONAL) This property helps to set the id value of the iframe. |
| (OPTIONAL) This property defines how to render the html5 directive in the chatbot. If it is true, it will render inside the chat bubble and if it is false it will render outside of the chat bubble. |
Â
renderBubble: true
renderBubble: false
Bot View Template
To handle the Submit button from the HTML form, you have to create a function in the Custom JS tab of the Bot View Template node and use the self.submitQuery property.
If using an intent utterance to trigger an intent:
self.submitQuery('intent utterance','display text', 'Event', Custom Object}
if using an event to trigger the intent,
self.submitQuery('FlowMessageFreeTextEvent','display text', 'FlowMessageFreeTextEvent', Custom Object}
For event:
Â
For utterance:
Â
var htmlFormSendData = function(e) {
var fname = $('#'+$('iframe').attr('id')).contents().find('#fname').val();
var lname = $('#'+$('iframe').attr('id')).contents().find('#lname').val();
// self.submitQuery('FlowMessageFreeTextEvent', 'Thanks','FlowMessageFreeTextEvent', { "fname": fname, "lname": lname });
self.submitQuery('utterance intent formResult', 'Thanks','', { "fname": fname, "lname": lname });
e.preventDefault();
};
When the user fills the form and clicks the submit button, the intent utterance mentioned in the Bot view template code will be sent to cause the formResult intent to fire.
Your details Say node:
The example flow, everything except the javascript for the Bot View Template.
Â
The First name and the Last name will be available in this object:
msg.payload.originalDetectIntentRequest.payload.extPayload
Â
Example 2: Calling an HTML5 Control from Flow Studio
Â
Â
Experience manager flow:
Directive
Template Node code:
Â
Note in this example 2, we don’t need any javascript code in the bot view template
window.parent.orbitaChatBot.sendQuickReply(......);
This has to be a number or text, not an object. If your HTML card results are an object using the method shown in the first HTML 5 example.
Passes the value as an utterance. In the Flow manager, the Single Input Control is set to hide inputs from the keyboard. Textbox - Hidden, it waiting for an input, which sendQuickReply sends.
Â
Â
Â