UNPKG

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

87 lines (82 loc) 2.98 kB
<script type="text/javascript"> $.RedBot.registerType('chatbot-document', { category: $.RedBot.config.name, color: '#FFCC66', defaults: { name: { value: '' }, filename: { value: '' }, document: { value: '' }, caption: { value: '', required: false } }, inputs: 1, outputs: 1, icon: 'chatbot-document.png', paletteLabel: 'Document', label: function() { return this.name || 'Document'; }, oneditprepare: function() { $.RedBot.fetchPlatforms() .done(function(platforms) { $('#dialog-form').RB_Platforms(); }); } }); </script> <script type="text/x-red" data-template-name="chatbot-document"> <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-document">Document</label> <input type="text" id="node-input-document" placeholder="Document filename or URL"> </div> <div class="form-row"> <label for="node-input-caption">Caption</label> <input type="text" id="node-input-caption" class="platform-telegram-slack" placeholder="Caption"> <div class="redbot-platforms telegram slack"/> </div> </script> <script type="text/x-red" data-help-name="chatbot-document"><p>The <code>Document node</code> sends a document to the chatbot from a local file or from a URL or from a Buffer passed by an upstream node (the simplest way to use it to chain with to <code>File node</code> or a <code>Http node</code>).</p> <p>Some file types are not supported by a specific platform, for example <em>Telegram</em> only supports <em>.zip</em>, <em>.pdf</em>, <em>.gif</em>. If a file not supported is automatically compressed and converted in a ZIP file.</p> <p>To programmatically send a document, in the upstream <code>Function node</code></p> <pre><code class="language-javascript">msg.payload.document = &#39;/my-file.pdf&#39;; return msg; </code></pre> <p>Or using a <code>Buffer</code>:</p> <pre><code class="language-javascript">msg.payload.document = new Buffer(&lt;my-buffer&gt;); msg.payload.filename = &#39;my-file-name.pdf&#39;; return msg; </code></pre> <p>In case the upstream node pass through a <code>Buffer</code>, the node tries to extract a proper file name (visible to user in the chat client) using the payload of the upstream <code>File node</code> or the name of the node itself.</p> <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>document</td> <td>string or buffer</td> <td>The document string could be a path for a local file or a URL (context variables can be used)</td> </tr> <tr> <td>caption</td> <td>string</td> <td>Caption of the document. Only for Telegram, Slack and Viber</td> </tr> </tbody></table> </script>