node-red-contrib-chatbot
Version:
REDBot a Chat bot for a full featured chat bot for Telegram, Facebook Messenger and Slack. Almost no coding skills required
132 lines (127 loc) • 4.48 kB
HTML
<script type="text/javascript">
$.RedBot.registerType('chatbot-alexa-directive', {
category: $.RedBot.config.name,
color: '#FFCC66',
defaults: {
directiveType: {
value: ''
},
slot: {
value: '',
validate: function(value) {
if ((this.directiveType === 'Dialog.ElicitSlot' || this.directiveType === 'Dialog.ConfirmSlot')
&& $.RedBot.validate.isEmpty(value)) {
return false;
}
return true;
}
}
},
inputs: 1,
outputs: 1,
paletteLabel: 'Alexa Directive',
icon: 'chatbot-directive.png',
label: function() {
return 'Alexa Directive';
},
oneditprepare: function() {
$('#node-input-directiveType')
.change(function() {
var type = $(this).val();
$('.form-row.only-for').hide();
if (type != null) {
$('.form-row.only-for-' + type.replace('.', '-')).show();
}
});
$('.form-row.only-for').hide();
if (this.directiveType != null) {
$('.form-row.only-for-' + this.directiveType.replace('.', '-')).show();
}
},
outputLabels: function() {
return this.directiveType != null ? this.directiveType : '';
}
});
</script>
<script type="text/x-red" data-template-name="chatbot-alexa-directive">
<div class="form-row">
<label for="node-input-directiveType">Type</label>
<select id="node-input-directiveType" placeholder="Select directive type">
<option value="">Select directive</option>
<option value="EndSession">End session</option>
<option value="Dialog.Delegate">Dialog.Delegate</option>
<option value="Dialog.ElicitSlot">Dialog.ElicitSlot</option>
<option value="Dialog.ConfirmSlot">Dialog.ConfirmSlot</option>
<option value="Dialog.ConfirmIntent">Dialog.ConfirmIntent</option>
</select>
</div>
<div class="form-row only-for only-for-Dialog-ElicitSlot only-for-Dialog-ConfirmSlot">
<label for="node-input-slot" style="width:auto;">Slot Name</label>
<input type="text" id="node-input-slot" placeholder="Enter slot name">
</div>
</script>
<script type="text/x-red" data-help-name="chatbot-alexa-directive"><p><em>Directives</em> are the way to instruct the <strong>Alexa</strong> devices how to behave in some situation, for example in a <a href="https://developer.amazon.com/docs/custom-skills/dialog-interface-reference.html">multi-turn dialog</a>.</p>
<p>The most used directives are:</p>
<ul>
<li><p><em>EndSession</em> to terminate a session (for example to complete a dialog without giving any response to the user except a confirmation sound) or</p>
</li>
<li><p><em>Dialog.Delegate</em> to delegate to <strong>Alexa</strong> how to handle a multi-turn dialog with the user</p>
</li>
</ul>
<p>Types of directive</p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>endSession</td>
<td>Terminate the dialog with just a simple confirmation sound</td>
</tr>
<tr>
<td>Dialog.Delegate</td>
<td>Let <strong>Alexa</strong> decide the next step in a multi-turn dialog (depends on the bot Model)</td>
</tr>
<tr>
<td>Dialog.ElicitSlot</td>
<td>Instruct <strong>Alexa</strong> to ask the user for a required slot of the intent, need to be chained with a <code>Alexa Speech node</code></td>
</tr>
<tr>
<td>Dialog.ConfirmSlot</td>
<td>Instruct <strong>Alexa</strong> to ask the user to confirm a previuosly selected slot of the intent, need to be chained with a <code>Alexa Speech node</code></td>
</tr>
<tr>
<td>Dialog.ConfirmIntent</td>
<td>Instruct <strong>Alexa</strong> to ask the user to confirm a intent, need to be chained with a <code>Alexa Speech node</code></td>
</tr>
</tbody></table>
<p>In order to create a directive programmatically in a upstream Function node:</p>
<pre><code class="language-javascript">msg.payload = {
directiveType: 'Dialog.ConfirmSlot',
slot: 'my-slot'
};
return msg;
</code></pre>
<p>Available parameters for the <code>msg.payload</code></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>directiveType</td>
<td>string</td>
<td>Type of directive. One of <em>endSession</em>, <em>Dialog.Delegate</em>, <em>Dialog.ElicitSlot</em>, <em>Dialog.ConfirmSlot</em>, <em>Dialog.ConfirmIntent</em></td>
</tr>
<tr>
<td>slot</td>
<td>string</td>
<td>The slot to confirm or elicit</td>
</tr>
</tbody></table>
</script>