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
239 lines (228 loc) • 10.4 kB
HTML
<script type="text/javascript">
$.RedBot.registerType('chatbot-viber-node', {
category: 'config',
defaults: {
botname: {
value: '',
required: true
},
usernames: {
value: '',
required: false
},
webHook: {
value: '',
validate: function(value) {
return $.RedBot.validate.url(value);
}
},
store: {
value: '',
type: 'chatbot-context-store',
required: false
},
log: {
value: null
},
debug: {
value: false
}
},
oneditprepare: function() {
$("#node-config-input-polling").spinner({min: 0, step: 100});
var node = this;
var nodeRedUrl = $.RedBot.getNodeRedUrl();
// fetch available context providers
$.get(nodeRedUrl + 'redbot/globals')
.done(function(response) {
if (response != null && response.viber != null && response.viber[node.botname] != null) {
$('#node-config-input-botname').prop('readonly', true);
$('.form-editable').hide();
$('.form-warning').show();
$('.form-warning .bot-name').html('"' + node.botname + '"');
}
});
},
paletteName: 'Viber Bot',
credentials: {
token: {
type: 'text'
}
},
label: function () {
return this.botname;
}
});
</script>
<script type="text/x-red" data-template-name="chatbot-viber-node">
<div class="form-row">
<label for="node-config-input-botname"><i class="icon-bookmark"></i> Bot Name</label>
<input type="text" id="node-config-input-botname">
</div>
<div class="form-editable">
<div class="form-row">
<label for="node-config-input-token">Token</label>
<input type="text" id="node-config-input-token">
</div>
<div class="form-row">
<label for="node-config-input-providerToken">Web Hook</label>
<input type="text" id="node-config-input-webHook">
<div class="form-warning">
Needs to be a public internet address, accessible outside the local network.
Use <b>ngrok</b> to create a bridge to your local environment while in development mode
</div> </div>
<div class="form-row">
<label for="node-config-input-usernames">Users</label>
<input type="text" id="node-config-input-usernames">
<div style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;margin-top:5px;">
Comma separated list of userId authorized to use the chatBot
</div>
</div>
<div class="form-row">
<label for="node-config-input-log">Log file</label>
<input type="text" id="node-config-input-log">
<div style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;margin-top:5px;">
Store inbound and outbound messages to file
</div>
</div>
<div class="form-row">
<label for="node-input-bot">Context</label>
<input type="text" id="node-config-input-store" placeholder="Select storage for chat context">
<div style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;margin-top:5px;">
Select the chat context provider to use with this bot, if none is selected then non-persistent "memory" will be used.<br>
To extend <strong>RedBot</strong> with a new chat context provider see <a href="https://github.com/guidone/node-red-contrib-chatbot/wiki/Creating-a-Chat-Context-Provider" target="_blank">this tutorial</a>.
</div>
</div>
<div class="form-row">
<label for="node-config-input-debug">Debug</label>
<input type="checkbox" value="true" id="node-config-input-debug">
<span class="redbot-form-hint">
Show debug information on send/receive
</span>
</div>
</div>
<div class="form-warning" style="display:none;">
This bot configuration is stored in <b>Node-RED</b> <em>settings.js</em> and cannot be modified from the UI, check
the section <code>functionGlobalContext</code> near the key <em class="bot-name">""</em>
</div>
</script>
<script type="text/x-red" data-help-name="chatbot-viber-node"><p>In order to create a chatbot in <strong>Viber</strong>, you have to register at the partners site <a href="http://partners.viber.com/">here</a>, then click on <em>“Create Bot account”</em>. Fill in the form then grab the <strong>access token</strong>.</p>
<p>Like other platforms, <strong>Viber</strong> requires a callback URL (web hook) to send messages to and must be accessible from internet (not just your local network), in order to test in your local environment, you can use ngrok to create a bridge between a public address and your local instance of <strong>RedBot</strong>:</p>
<pre><code class="language-bash">ngrok http localhost:1880
</code></pre>
<p>You should get something like</p>
<p><img src="https://s3.us-west-2.amazonaws.com/secure.notion-static.com/7d009da9-4b7e-412b-81e4-1e3bc3caa564/facebook-1.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20230218%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20230218T124917Z&X-Amz-Expires=3600&X-Amz-Signature=3e0c1e97b1fb777041134333ddab26fc64688bc2ac6b070460c329dc68d1982c&X-Amz-SignedHeaders=host&x-id=GetObject" alt="Ngrok"></p>
<p>Grab the https address you, something like <a href="https://123123.ngrok.io">https://123123.ngrok.io</a>, this is the base url that points back to your <strong>Node-RED</strong> instance.</p>
<p>The callback is</p>
<pre><code class="language-bash">https://youraddress.ngrok.io/redbot/viber
</code></pre>
<p>A <strong>Viber</strong> bot needs at least the access token and a working web hook in order to work. Note that unless other platforms that requires a callback (like <strong>Slack</strong> or <strong>Facebook Messenger</strong>), the web hook is required in the <strong>RedBot</strong> configuration (in <strong>Node-RED</strong>) and not in the <strong>Viber</strong> backend. P.S. After a chatbot is created in the <strong>Viber</strong> platform, it will not be possible to send a message in any client until a valid web-hook is set in the configuration.</p>
</script>
<script type="text/javascript">
$.RedBot.registerType('chatbot-viber-receive', {
category: $.RedBot.config.name + ' Platforms',
color: '#FFCC66',
defaults: {
bot: {
value: '',
type: 'chatbot-viber-node',
required: true
},
botProduction: {
value: '',
type: 'chatbot-viber-node',
required: false
}
},
inputs: 0,
outputs: 1,
icon: 'viber.svg',
paletteLabel: 'Viber Receiver',
label: function () {
return 'Viber Receiver';
}
});
</script>
<script type="text/x-red" data-template-name="chatbot-viber-receive">
<div class="form-row">
<label for="node-input-bot" style="display:block;width:100%;">Bot configuration <span class="redbot-environment">(development)</span></label>
<input type="text" id="node-input-bot" placeholder="Bot">
</div>
<div class="form-row" style="margin-top:25px;">
<label for="node-input-botProduction" style="display:block;width:100%;">Bot configuration <span class="redbot-environment">(production)</span></label>
<input type="text" id="node-input-botProduction" placeholder="Bot">
</div>
<div class="redbot-form-hint">
Bot for <strong>production</strong> will be launched only if the global variable <em>"environment"</em> in <em>settings.js</em> is set to <em>"production"</em>, otherwise will be used the configuration for <strong>development</strong>.
</div>
</script>
<script type="text/x-red" data-help-name="chatbot-viber-receive">
<p>Input node for Viber.</p>
</script>
<script type="text/javascript">
$.RedBot.registerType('chatbot-viber-send', {
category: $.RedBot.config.name + ' Platforms',
color: '#FFCC66',
defaults: {
bot: {
value: '',
type: 'chatbot-viber-node',
required: true
},
botProduction: {
value: '',
type: 'chatbot-viber-node',
required: false
},
track: {
value: false
},
passThrough: {
value: false
},
outputs: {
value: 0
}
},
inputs: 1,
outputs: 1,
icon: 'viber.svg',
paletteLabel: 'Viber Sender',
label: function () {
return 'Viber Sender';
},
oneditsave: function() {
var track = $('#node-input-track').is(':checked');
var passThrough = $('#node-input-passThrough').is(':checked');
this.outputs = track || passThrough ? 1 : 0;
}
});
</script>
<script type="text/x-red" data-template-name="chatbot-viber-send">
<div class="form-row">
<label for="node-input-bot" style="display:block;width:100%;">Bot configuration <span class="redbot-environment">(development)</span></label>
<input type="text" id="node-input-bot" placeholder="Bot">
</div>
<div class="form-row" style="margin-top:25px;">
<label for="node-input-botProduction" style="display:block;width:100%;">Bot configuration <span class="redbot-environment">(production)</span></label>
<input type="text" id="node-input-botProduction" placeholder="Bot">
</div>
<div class="redbot-form-hint">
Bot for <strong>production</strong> will be launched only if the global variable <em>"environment"</em> in <em>settings.js</em> is set to <em>"production"</em>, otherwise will be used the configuration for <strong>development</strong>.
</div>
<div class="form-row" style="margin-top:25px;">
<label for="node-input-track" style="margin-bottom:0px;">Track</label>
<input type="checkbox" value="true" id="node-input-track" style="margin-top:0px;">
<div class="redbot-form-hint">
Track response of the user for this message: any further answer will be redirect to the output pin.
</div>
<label for="node-input-track" style="margin-bottom:0px;margin-top:15px;">Pass Through</label>
<input type="checkbox" value="true" id="node-input-passThrough" style="margin-top:0px;">
<div class="redbot-form-hint">
Forward the message to the output pin after sending (useful to chain messages and keep the right order)
</div>
</div>
</script>
<script type="text/x-red" data-help-name="chatbot-viber-send">
<p>Output node for Viber.</p>
</script>