UNPKG

botnaut

Version:

Facebook Messenger Chatbot Framework

1,183 lines (633 loc) 30.5 kB
<!DOCTYPE HTML> <html lang="" > <head> <meta charset="UTF-8"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>Serverless · Botnaut</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="description" content=""> <meta name="generator" content="GitBook 3.2.3"> <meta name="author" content="David Menger"> <link rel="stylesheet" href="../gitbook/style.css"> <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css"> <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css"> <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css"> <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css"> <meta name="HandheldFriendly" content="true"/> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png"> <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon"> <link rel="next" href="BuildRouter.html" /> <link rel="prev" href="Ai.html" /> </head> <body> <div class="book"> <div class="book-summary"> <div id="book-search-input" role="search"> <input type="text" placeholder="Type to search" /> </div> <nav role="navigation"> <ul class="summary"> <li class="header">Building a chat bot</li> <li class="chapter " data-level="1.1" data-path="../"> <a href="../"> Getting Started </a> </li> <li class="chapter " data-level="1.2" data-path="../tutorial/buildingConversation.html"> <a href="../tutorial/buildingConversation.html"> Building a Conversation </a> <ul class="articles"> <li class="chapter " data-level="1.2.1" data-path="../tutorial/buildingConversation.html"> <a href="../tutorial/buildingConversation.html#asking-a-question"> Asking a question </a> </li> <li class="chapter " data-level="1.2.2" data-path="../tutorial/buildingConversation.html"> <a href="../tutorial/buildingConversation.html#using-quick-replies-for-controlling-conversation"> Using quick replies </a> </li> <li class="chapter " data-level="1.2.3" data-path="../tutorial/buildingConversation.html"> <a href="../tutorial/buildingConversation.html#post-back-is-also-an-action"> Postbacks </a> </li> </ul> </li> <li class="chapter " data-level="1.3" data-path="../tutorial/conversationState.html"> <a href="../tutorial/conversationState.html"> Conversation State </a> <ul class="articles"> <li class="chapter " data-level="1.3.1" data-path="../tutorial/conversationState.html"> <a href="../tutorial/conversationState.html#accessing-user-profile"> User profile </a> </li> <li class="chapter " data-level="1.3.2" data-path="../tutorial/conversationState.html"> <a href="../tutorial/conversationState.html#using-the-state-in-navigation"> Using state in navigation </a> </li> <li class="chapter " data-level="1.3.3" data-path="../tutorial/conversationState.html"> <a href="../tutorial/conversationState.html#reading-and-modifiing-user-state"> Reading and writing state </a> </li> </ul> </li> <li class="chapter " data-level="1.4" data-path="../tutorial/asyncActions.html"> <a href="../tutorial/asyncActions.html"> Asynchronous Actions </a> <ul class="articles"> <li class="chapter " data-level="1.4.1" data-path="../tutorial/asyncActions.html"> <a href="../tutorial/asyncActions.html#blocking-asynchronous-actions"> Blocking Actions </a> </li> <li class="chapter " data-level="1.4.2" data-path="../tutorial/asyncActions.html"> <a href="../tutorial/asyncActions.html#non-blocking-asynchronous-actions"> Non Blocking Actions </a> </li> <li class="chapter " data-level="1.4.3" data-path="../tutorial/asyncActions.html"> <a href="../tutorial/asyncActions.html#loading-attachments-to-buffer"> Loading Attachments </a> </li> </ul> </li> <li class="chapter " data-level="1.5" data-path="../tutorial/advancedRouting.html"> <a href="../tutorial/advancedRouting.html"> Advanced Routing </a> <ul class="articles"> <li class="chapter " data-level="1.5.1" data-path="../tutorial/advancedRouting.html"> <a href="../tutorial/advancedRouting.html#resolving-actions"> Resolving Actions </a> </li> <li class="chapter " data-level="1.5.2" data-path="../tutorial/advancedRouting.html"> <a href="../tutorial/advancedRouting.html#simple-text-actions"> Text Actions </a> </li> <li class="chapter " data-level="1.5.3" data-path="../tutorial/advancedRouting.html"> <a href="../tutorial/advancedRouting.html#integrating-with-ai-prediction"> Integrating AI </a> </li> <li class="chapter " data-level="1.5.4" data-path="../tutorial/advancedRouting.html"> <a href="../tutorial/advancedRouting.html#redirecting-flow-with-post-back"> Redirecting with Postback </a> </li> </ul> </li> <li class="chapter " data-level="1.6" data-path="../tutorial/nestingRouters.html"> <a href="../tutorial/nestingRouters.html"> Nesting - Reusable Blocks </a> <ul class="articles"> <li class="chapter " data-level="1.6.1" data-path="../tutorial/nestingRouters.html"> <a href="../tutorial/nestingRouters.html#basic-concept"> Concept </a> </li> <li class="chapter " data-level="1.6.2" data-path="../tutorial/nestingRouters.html"> <a href="../tutorial/nestingRouters.html#example"> Example </a> </li> </ul> </li> <li class="chapter " data-level="1.7" data-path="../tutorial/templates.html"> <a href="../tutorial/templates.html"> Sending Templates </a> <ul class="articles"> <li class="chapter " data-level="1.7.1" data-path="../tutorial/templates.html"> <a href="../tutorial/templates.html#button-template"> Button Template </a> </li> <li class="chapter " data-level="1.7.2" data-path="../tutorial/templates.html"> <a href="../tutorial/templates.html#generic-template"> Generic Template </a> </li> <li class="chapter " data-level="1.7.3" data-path="../tutorial/templates.html"> <a href="../tutorial/templates.html#receipt-template"> Receipt Template </a> </li> <li class="chapter " data-level="1.7.4" data-path="../tutorial/templates.html"> <a href="../tutorial/templates.html#working-with-webviews"> Webviews </a> </li> </ul> </li> <li class="chapter " data-level="1.8" data-path="../tutorial/testing.html"> <a href="../tutorial/testing.html"> Testing </a> </li> <li class="chapter " data-level="1.9" data-path="../tutorial/analytics.html"> <a href="../tutorial/analytics.html"> Analytics </a> </li> <li class="chapter " data-level="1.10" data-path="../tutorial/usingWithWingbot.html"> <a href="../tutorial/usingWithWingbot.html"> Using with Wingbot.ai </a> <ul class="articles"> <li class="chapter " data-level="1.10.1" data-path="../tutorial/usingWithWingbot.html"> <a href="../tutorial/usingWithWingbot.html#bot-configuration"> Bot configuration </a> </li> <li class="chapter " data-level="1.10.2" data-path="../tutorial/usingWithWingbot.html"> <a href="../tutorial/usingWithWingbot.html#express-mongodb"> Express Mongodb </a> </li> <li class="chapter " data-level="1.10.3" data-path="../tutorial/usingWithWingbot.html"> <a href="../tutorial/usingWithWingbot.html#serverless-aws-lambda"> Serverless AWS Lambda </a> </li> </ul> </li> <li class="header">API</li> <li class="chapter " data-level="2.1" data-path="Request.html"> <a href="Request.html"> Request </a> </li> <li class="chapter " data-level="2.2" data-path="Responder.html"> <a href="Responder.html"> Responder </a> </li> <li class="chapter " data-level="2.3" data-path="Router.html"> <a href="Router.html"> Router </a> </li> <li class="chapter " data-level="2.4" data-path="Tester.html"> <a href="Tester.html"> Tester </a> </li> <li class="chapter " data-level="2.5" data-path="ButtonTemplate.html"> <a href="ButtonTemplate.html"> Template Builders </a> <ul class="articles"> <li class="chapter " data-level="2.5.1" data-path="ButtonTemplate.html"> <a href="ButtonTemplate.html#ButtonTemplate"> ButtonTemplate </a> </li> <li class="chapter " data-level="2.5.2" data-path="ButtonTemplate.html"> <a href="ButtonTemplate.html#GenericTemplate"> GenericTemplate </a> </li> <li class="chapter " data-level="2.5.3" data-path="ButtonTemplate.html"> <a href="ButtonTemplate.html#ReceiptTemplate"> ReceiptTemplate </a> </li> </ul> </li> <li class="chapter " data-level="2.6" data-path="Settings.html"> <a href="Settings.html"> Bot Settings </a> </li> <li class="chapter " data-level="2.7" data-path="express.html"> <a href="express.html"> Express/MongoDb tools </a> </li> <li class="chapter " data-level="2.8" data-path="bufferloader.html"> <a href="bufferloader.html"> Utils </a> </li> <li class="chapter " data-level="2.9" data-path="Ai.html"> <a href="Ai.html"> Ai </a> </li> <li class="chapter active" data-level="2.10" data-path="serverlessAWS.html"> <a href="serverlessAWS.html"> Serverless </a> </li> <li class="chapter " data-level="2.11" data-path="BuildRouter.html"> <a href="BuildRouter.html"> Wingbot.ai </a> </li> <li class="chapter " data-level="2.12" data-path="callback.html"> <a href="callback.html"> Middlewares </a> </li> <li class="divider"></li> <li> <a href="https://www.gitbook.com" target="blank" class="gitbook-link"> Published with GitBook </a> </li> </ul> </nav> </div> <div class="book-body"> <div class="body-inner"> <div class="book-header" role="navigation"> <!-- Title --> <h1> <i class="fa fa-circle-o-notch fa-spin"></i> <a href=".." >Serverless</a> </h1> </div> <div class="page-wrapper" tabindex="-1" role="main"> <div class="page-inner"> <div id="book-search-results"> <div class="search-noresults"> <section class="normal markdown-section"> <h2 id="functions"><a name="functions" class="plugin-anchor" href="#functions"><i class="fa fa-link" aria-hidden="true"></i></a>Functions</h2> <dl> <dt><a href="#createProcessor">createProcessor(reducer, processorOptions, [stateStorage])</a></dt> <dd><p>Create a chat event processor</p> </dd> <dt><a href="#createUpdater">createUpdater(lambdaName, [token], [log])</a></dt> <dd><p>Create updater handler for wingbot which deploys new lambda version</p> <p>listens for POST on <code>/update</code></p> </dd> <dt><a href="#createHandler">createHandler(processor, verifyToken, [log], [onDispatch])</a></dt> <dd><p>Create an serverless handler for accepting messenger events</p> </dd> <dt><a href="#createValidator">createValidator(config, [log], [onDispatch])</a></dt> <dd><p>Create validator handler for wingbot configurations</p> <p>listens for POST on <code>/validate</code></p> </dd> </dl> <div id="createProcessor">&#xA0;</div> <h2 id="createprocessorreducer-processoroptions-statestorage"><a name="createprocessorreducer-processoroptions-statestorage" class="plugin-anchor" href="#createprocessorreducer-processoroptions-statestorage"><i class="fa fa-link" aria-hidden="true"></i></a>createProcessor(reducer, processorOptions, [stateStorage])</h2> <p>Create a chat event processor</p> <p><strong>Kind</strong>: global function </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>reducer</td> <td><code>function</code> \</td> <td><code>Router</code></td> <td>Root router object or processor function</td> </tr> <tr> <td>processorOptions</td> <td><code>Object</code></td> <td>settings for message processing</td> </tr> <tr> <td>[processorOptions.pageToken]</td> <td><code>string</code></td> <td>page token</td> </tr> <tr> <td>[processorOptions.appSecret]</td> <td><code>string</code></td> <td>bot application secret</td> </tr> <tr> <td>[processorOptions.appUrl]</td> <td><code>string</code></td> <td>where the bot application is deployed</td> </tr> <tr> <td>[processorOptions.timeout]</td> <td><code>number</code></td> <td>how long the state will be locked for single event</td> </tr> <tr> <td>[processorOptions.log]</td> <td><code>Object</code></td> <td>console.log/error/warn like object</td> </tr> <tr> <td>[processorOptions.defaultState]</td> <td><code>Object</code></td> <td>default conversation state</td> </tr> <tr> <td>[processorOptions.chatLog]</td> <td><code>DynamoChatLog</code></td> <td>discussion logger</td> </tr> <tr> <td>[processorOptions.tokenStorage]</td> <td><code>DynamoBotToken</code></td> <td>storage for chabot tokens</td> </tr> <tr> <td>[processorOptions.senderFnFactory]</td> <td><code>function</code></td> <td>override default sender function</td> </tr> <tr> <td>[processorOptions.securityMiddleware]</td> <td><code>function</code></td> <td>override webview calls authorizer</td> </tr> <tr> <td>[processorOptions.cookieName]</td> <td><code>string</code></td> <td>webview cookie (for default securityMiddleware)</td> </tr> <tr> <td>[processorOptions.loadUsers]</td> <td><code>boolean</code></td> <td>set false to not load user profiles</td> </tr> <tr> <td>[processorOptions.userLoader]</td> <td><code>Object</code></td> <td>override default user loader</td> </tr> <tr> <td>[processorOptions.onSenderError]</td> <td><code>function</code></td> <td>override default sender error reporter</td> </tr> <tr> <td>[processorOptions.autoTyping]</td> <td><code>Object</code> \</td> <td><code>boolean</code></td> <td>enable auto typing</td> </tr> <tr> <td>[processorOptions.autoTyping.time]</td> <td><code>number</code></td> <td>default typing time</td> </tr> <tr> <td>[processorOptions.autoTyping.perCharacters]</td> <td><code>number</code></td> <td>typing time per character</td> </tr> <tr> <td>[processorOptions.autoTyping.minTime]</td> <td><code>number</code></td> <td>auto typing lower threshold</td> </tr> <tr> <td>[processorOptions.autoTyping.maxTime]</td> <td><code>number</code></td> <td>auto typing upper threshold</td> </tr> <tr> <td>[processorOptions.dynamo]</td> <td><code>Object</code></td> <td>dynamodb configuration</td> </tr> <tr> <td>[processorOptions.dynamo.db]</td> <td><code>AWS.DynamoDB</code></td> <td>dynamodb db object</td> </tr> <tr> <td>[processorOptions.dynamo.tablePrefix]</td> <td><code>string</code></td> <td>dynamodb table prefix</td> </tr> <tr> <td>[stateStorage]</td> <td><code>DynamoState</code></td> <td>storage for states</td> </tr> </tbody> </table> <div id="createUpdater">&#xA0;</div> <h2 id="createupdaterlambdaname-token-log"><a name="createupdaterlambdaname-token-log" class="plugin-anchor" href="#createupdaterlambdaname-token-log"><i class="fa fa-link" aria-hidden="true"></i></a>createUpdater(lambdaName, [token], [log])</h2> <p>Create updater handler for wingbot which deploys new lambda version</p> <p>listens for POST on <code>/update</code></p> <p><strong>Kind</strong>: global function </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>lambdaName</td> <td><code>string</code></td> <td></td> <td>bot handler name</td> </tr> <tr> <td>[token]</td> <td><code>string</code></td> <td><code>null</code></td> <td>bot authorization token</td> </tr> <tr> <td>[log]</td> <td><code>object</code></td> <td></td> <td>console.* like logger object</td> </tr> </tbody> </table> <div id="createHandler">&#xA0;</div> <h2 id="createhandlerprocessor-verifytoken-log-ondispatch"><a name="createhandlerprocessor-verifytoken-log-ondispatch" class="plugin-anchor" href="#createhandlerprocessor-verifytoken-log-ondispatch"><i class="fa fa-link" aria-hidden="true"></i></a>createHandler(processor, verifyToken, [log], [onDispatch])</h2> <p>Create an serverless handler for accepting messenger events</p> <p><strong>Kind</strong>: global function </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>processor</td> <td><code>Processor</code> \</td> <td><code>Hook</code></td> <td>Root router object or processor function</td> </tr> <tr> <td>verifyToken</td> <td><code>string</code></td> <td>chatbot application token</td> </tr> <tr> <td>[log]</td> <td><code>object</code></td> <td>console.* like logger object</td> </tr> <tr> <td>[onDispatch]</td> <td><code>function</code></td> <td>will be called after dispatch of all events</td> </tr> </tbody> </table> <div id="createValidator">&#xA0;</div> <h2 id="createvalidatorconfig-log-ondispatch"><a name="createvalidatorconfig-log-ondispatch" class="plugin-anchor" href="#createvalidatorconfig-log-ondispatch"><i class="fa fa-link" aria-hidden="true"></i></a>createValidator(config, [log], [onDispatch])</h2> <p>Create validator handler for wingbot configurations</p> <p>listens for POST on <code>/validate</code></p> <p><strong>Kind</strong>: global function </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>config</td> <td><code>object</code></td> <td></td> </tr> <tr> <td>[config.token]</td> <td><code>string</code></td> <td>authorization token</td> </tr> <tr> <td>[config.blocksResource]</td> <td><code>Blocks</code></td> <td>authorization token</td> </tr> <tr> <td>[config.routerFactory]</td> <td><code>function</code></td> <td>creates blank router for testing purposes</td> </tr> <tr> <td>[config.testText]</td> <td><code>string</code></td> <td>text for router testing (null to disable)</td> </tr> <tr> <td>[config.testPostBack]</td> <td><code>string</code></td> <td>postback to test the bot (null to disable)</td> </tr> <tr> <td>[log]</td> <td><code>object</code></td> <td>console.* like logger object</td> </tr> <tr> <td>[onDispatch]</td> <td><code>function</code></td> </tr> </tbody> </table> </section> </div> <div class="search-results"> <div class="has-results"> <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1> <ul class="search-results-list"></ul> </div> <div class="no-results"> <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1> </div> </div> </div> </div> </div> </div> <a href="Ai.html" class="navigation navigation-prev " aria-label="Previous page: Ai"> <i class="fa fa-angle-left"></i> </a> <a href="BuildRouter.html" class="navigation navigation-next " aria-label="Next page: Wingbot.ai"> <i class="fa fa-angle-right"></i> </a> </div> <script> var gitbook = gitbook || []; gitbook.push(function() { gitbook.page.hasChanged({"page":{"title":"Serverless","level":"2.10","depth":1,"next":{"title":"Wingbot.ai","level":"2.11","depth":1,"path":"api/BuildRouter.md","ref":"api/BuildRouter.md","articles":[]},"previous":{"title":"Ai","level":"2.9","depth":1,"path":"api/Ai.md","ref":"api/Ai.md","articles":[]},"dir":"ltr"},"config":{"plugins":["theme-default","collapsible-menu","anchors"],"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"},"pluginsConfig":{"collapsible-menu":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-api":{"theme":"dark","languages":[{"lang":"js","name":"JavaScript","default":true}]},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"showLevel":false,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}},"anchors":{}},"theme":"default","author":"David Menger","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"twitter":"https://twitter.com/davidmenger"},"title":"Botnaut","gitbook":"*","description":"Facebook Messenger framework for Node.js"},"file":{"path":"api/serverlessAWS.md","mtime":"2018-05-23T15:31:55.136Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-05-23T15:31:59.833Z"},"basePath":"..","book":{"language":""}}); }); </script> </div> <script src="../gitbook/gitbook.js"></script> <script src="../gitbook/theme.js"></script> <script src="../gitbook/gitbook-plugin-collapsible-menu/plugin.js"></script> <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script> <script src="../gitbook/gitbook-plugin-search/search.js"></script> <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script> <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script> <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script> <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script> </body> </html>