prisme-flow
Version:
prisme platform flow engine
123 lines (112 loc) • 4.47 kB
HTML
<!--
Created by prisme.io on 09/06/2017.
@author <a href="mailto:hello@prisme.io">savane vamara</a> (prisme.io)
-->
<script type="text/javascript">
RED.nodes.registerType('bot-conversation', {
category: 'bot',
color: '#FFCC66',
defaults: {
name: {
value: ''
},
chatId: {
value: ''
},
transport: {
value: ''
},
messageId: {
value: ''
},
contextMessageId: {
value: false
}
},
inputs: 1,
outputs: 1,
oneditprepare: function() {
var _this = this;
$('#node-input-contextMessageId').on('change', function() {
var checked = $(this).is(':checked');
if (checked) {
$('#node-input-messageId').val('{messageId}').attr('disabled', true);
} else {
$('#node-input-messageId').val(_this.messageId).attr('disabled', false);
}
});
},
paletteLabel: 'conversation',
icon: 'conversation.png',
label: function() {
return this.name || 'Conversation';
}
});
</script>
<script type="text/x-red" data-template-name="bot-conversation">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-transport"><i class="icon-plane"></i> Transport</label>
<select id="node-input-transport">
<option value="">Select transport</option>
<option value="facebook">Facebook Messenger</option>
<option value="slack">Slack</option>
<option value="smooch">Smooch</option>
<option value="telegram">Telegram</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-user"></i> ChatId</label>
<input type="text" id="node-input-chatId" placeholder="Chat id" style="width:150px;">
<div style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;clear:both;">
The <code>chatId</code> is needed to initiate the conversation (you can grab the chatId from the logs or a debug node),
the <code>chatId</code> is unique per user across the different platforms (Telegram, Facebook, Slack).
</div>
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-user"></i> MessageId</label>
<input type="text" id="node-input-messageId" class="platform-telegram" placeholder="Message Id" style="width:150px;">
<input type="checkbox" value="true" id="node-input-contextMessageId" style="width:20px;"> Use context <em>{messageId}</em>
<div style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;clear:both;">
Specify a <code>messageId</code> to edit a message already sent to the user. Use context <code>messageId</code> to
edit the last sent message.
</div>
</div>
<div style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;clear:both;margin-top:30px;margin-bottom:10px;">
Some attributes apply for specific platform:<br>
<span class="icon-platform-facebook"></span> = <span style="font-size:10px">Facebook</span>
<span class="icon-platform-telegram"></span> = <span style="font-size:10px">Telegram</span>
<span class="icon-platform-smooch"></span> = <span style="font-size:10px">Smooch</span>
<span class="icon-platform-slack"></span> = <span style="font-size:10px">Slack</span>
</div>
</script>
<script type="text/x-red" data-help-name="bot-conversation">
<p>
Start a chat bot conversation, for example to initiate a conversation (sending a message) to a user in response of a event, chain this node to a Message node (or Image, Location, etc) <em>[Telegram, Facebook, Smooch, Slack]</em>
</p>
<p>
The <code>chatId</code> is needed to initiate the conversation (you can grab the chatId from the logs or a debug node),
the <code>chatId</code> is unique per user across the different platforms (Telegram, Facebook, Slack).
</p>
<p>The parameters <code>chatId</code> and <code>transport</code> can be passed through the payload by the upstream node:</p>
<pre>
msg.payload = {
chatId: '42',
transport: 'telegram'
};
return msg;
</pre>
<p>
In order to edit an already sent message (only <em>Telegram</em>), specify the <code>messageId</code> or use the context
<code>messageId</code> which is the id of the last sent message. To set the <code>messageId</code> programmatically in the upstream node
<pre>
msg.payload = {
messageId: 123456
};
return msg;
</pre>
</p>
</script>