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

22 lines (20 loc) 2.25 kB
<script type="text/javascript"> $.RedBot.registerType('chatbot-pop-message', { category: $.RedBot.config.name + ' Flow', color: '#FFCC66', defaults: {}, inputs: 1, outputs: 1, paletteLabel: 'Pop Message', icon: 'link-call.svg', label: 'Pop Message' }); </script> <script type="text/x-red" data-help-name="chatbot-pop-message"><p>The <code>Pop Message node</code> is useful with all the nodes (like <a href="https://www.notion.so/bbc3deb2d39a4b338fc6515eee337cd4">NLPjs Process</a> , <a href="https://www.notion.so/0dc75116dee9458486e1a4f09fc3f44b">MC GraphQL node</a> ) that overwrites the <code>msg.payload</code> of the <strong>Node-RED</strong> message, losing any reference with the original message from the chatbot user.</p> <p>The <code>Pop Message node</code> restores the previous value of <code>msg.payload</code> overwritten by these nodes.</p> <p>For example consider this flow when we want to query a database to check is the user is allowed to use the chatbot:</p> <p><img src="https://raw.githubusercontent.com/guidone/node-red-contrib-chatbot/master/docs/images/example-pop-node.png" alt="Check user credentials"></p> <p>The node <a href="https://www.notion.so/0dc75116dee9458486e1a4f09fc3f44b">MC GraphQL node</a> is querying the database presenting the result in <code>msg.payload</code> overwriting the user’s message which is required in the rest of the flow. The <code>Function node</code> checks the result of the query and controls the flow: if the user is not allowed to use the chatbot the flow is redirected to the second pin and a <em>“Not allowed”</em> message is answered. If the user has the right permission the flow is redirected to the first pin and the user’s message (the previous value of <code>msg.payload</code>) is restored to be used in the rest of the flow (for example a parse node).</p> <p>It’s possible to store the current message (<code>msg.payload</code>) with the <code>Push message node</code>, this is useful in all situations where the downstream node is overwriting the <code>payload</code> of the <strong>Node-RED</strong> message.</p> <p><strong>Warning:</strong> it doesn’t work across <strong>RedBot</strong>’s senders and receivers</p> </script>