UNPKG

botnaut

Version:

Facebook Messenger Chatbot Framework

1,293 lines (718 loc) 38.6 kB
<!DOCTYPE HTML> <html lang="" > <head> <meta charset="UTF-8"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>Ai · 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="serverlessAWS.html" /> <link rel="prev" href="bufferloader.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 active" data-level="2.9" data-path="Ai.html"> <a href="Ai.html"> Ai </a> </li> <li class="chapter " 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=".." >Ai</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="classes"><a name="classes" class="plugin-anchor" href="#classes"><i class="fa fa-link" aria-hidden="true"></i></a>Classes</h2> <dl> <dt><a href="#Ai">Ai</a></dt> <dd></dd> </dl> <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="#markAsHandled">markAsHandled([aiHandled])</a> &#x21D2; <code>Request</code></dt> <dd><p>Mark request as handled - usefull for AI analytics</p> </dd> </dl> <div id="Ai">&#xA0;</div> <h2 id="ai"><a name="ai" class="plugin-anchor" href="#ai"><i class="fa fa-link" aria-hidden="true"></i></a>Ai</h2> <p><strong>Kind</strong>: global class </p> <ul> <li><a href="#Ai">Ai</a><ul> <li><a href="#Ai_confidence">.confidence</a> : <code>number</code></li> <li><a href="#Ai_threshold">.threshold</a> : <code>number</code></li> <li><a href="#Ai_logger">.logger</a> : <code>Object</code></li> <li><a href="#Ai_prefixTranslator">.prefixTranslator(prefix, req)</a></li> <li><a href="#Ai_mockIntent">.mockIntent([intent], [confidence])</a> &#x21D2; <code>this</code></li> <li><a href="#Ai_onConfirmMiddleware">.onConfirmMiddleware(onIntentConfirmed, getMeta)</a> &#x21D2; <code>function</code></li> <li><a href="#Ai_register">.register(model, options, prefix)</a> &#x21D2; <code>WingbotModel</code></li> <li><a href="#Ai_match">.match(intent, [confidence], [prefix])</a> &#x21D2; <code>function</code></li> <li><a href="#Ai_navigate">.navigate(knownIntents, [threshold], [confidence], [prefix])</a> &#x21D2; <code>function</code></li> <li><a href="#Ai_makeSure">.makeSure(knownIntents, [threshold], [confidence], prefix)</a> &#x21D2; <code>function</code></li> </ul> </li> </ul> <div id="Ai_confidence">&#xA0;</div> <h3 id="aiconfidence--number"><a name="aiconfidence--number" class="plugin-anchor" href="#aiconfidence--number"><i class="fa fa-link" aria-hidden="true"></i></a>ai.confidence : <code>number</code></h3> <p>Upper threshold - for match method and for navigate method</p> <p><strong>Kind</strong>: instance property of <a href="#Ai"><code>Ai</code></a> </p> <div id="Ai_threshold">&#xA0;</div> <h3 id="aithreshold--number"><a name="aithreshold--number" class="plugin-anchor" href="#aithreshold--number"><i class="fa fa-link" aria-hidden="true"></i></a>ai.threshold : <code>number</code></h3> <p>Lower threshold - for navigate and makeSure methods</p> <p><strong>Kind</strong>: instance property of <a href="#Ai"><code>Ai</code></a> </p> <div id="Ai_logger">&#xA0;</div> <h3 id="ailogger--object"><a name="ailogger--object" class="plugin-anchor" href="#ailogger--object"><i class="fa fa-link" aria-hidden="true"></i></a>ai.logger : <code>Object</code></h3> <p>The logger (console by default)</p> <p><strong>Kind</strong>: instance property of <a href="#Ai"><code>Ai</code></a> </p> <div id="Ai_prefixTranslator">&#xA0;</div> <h3 id="aiprefixtranslatorprefix-req"><a name="aiprefixtranslatorprefix-req" class="plugin-anchor" href="#aiprefixtranslatorprefix-req"><i class="fa fa-link" aria-hidden="true"></i></a>ai.prefixTranslator(prefix, req)</h3> <p>The prefix translator - for request-specific prefixes</p> <p><strong>Kind</strong>: instance method of <a href="#Ai"><code>Ai</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> </tr> </thead> <tbody> <tr> <td>prefix</td> <td><code>string</code></td> </tr> <tr> <td>req</td> <td><code>Request</code></td> </tr> </tbody> </table> <div id="Ai_mockIntent">&#xA0;</div> <h3 id="aimockintentintent-confidence-&#x21D2;-this"><a name="aimockintentintent-confidence-&#x21D2;-this" class="plugin-anchor" href="#aimockintentintent-confidence-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>ai.mockIntent([intent], [confidence]) &#x21D2; <code>this</code></h3> <p>Usefull method for testing AI routes</p> <p><strong>Kind</strong>: instance method of <a href="#Ai"><code>Ai</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>[intent]</td> <td><code>string</code></td> <td><code>null</code></td> <td>intent name</td> </tr> <tr> <td>[confidence]</td> <td><code>number</code></td> <td><code></code></td> <td>the confidence of the top intent</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript"><span class="hljs-keyword">const</span> { Tester, ai, Route } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;bontaut&apos;</span>); <span class="hljs-keyword">const</span> bot = <span class="hljs-keyword">new</span> Route(); bot.use([<span class="hljs-string">&apos;intentAction&apos;</span>, ai.match(<span class="hljs-string">&apos;intentName&apos;</span>)], (req, res) =&gt; { res.text(<span class="hljs-string">&apos;PASSED&apos;</span>); }); describe(<span class="hljs-string">&apos;bot&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ it(<span class="hljs-string">&apos;should work&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ ai.mockIntent(<span class="hljs-string">&apos;intentName&apos;</span>); <span class="hljs-keyword">const</span> t = <span class="hljs-keyword">new</span> Tester(bot); <span class="hljs-keyword">return</span> t.text(<span class="hljs-string">&apos;Any text&apos;</span>) .then(() =&gt; { t.actionPassed(<span class="hljs-string">&apos;intentAction&apos;</span>); t.any() .contains(<span class="hljs-string">&apos;PASSED&apos;</span>); }) }); }); </code></pre> <div id="Ai_onConfirmMiddleware">&#xA0;</div> <h3 id="aionconfirmmiddlewareonintentconfirmed-getmeta-&#x21D2;-function"><a name="aionconfirmmiddlewareonintentconfirmed-getmeta-&#x21D2;-function" class="plugin-anchor" href="#aionconfirmmiddlewareonintentconfirmed-getmeta-&#x21D2;-function"><i class="fa fa-link" aria-hidden="true"></i></a>ai.onConfirmMiddleware(onIntentConfirmed, getMeta) &#x21D2; <code>function</code></h3> <p>When user confirms their intent, onIntentConfirmed handler will be called. To create meta data from recognized request use getMeta handler. Its useful for updating training data for AI</p> <p><strong>Kind</strong>: instance method of <a href="#Ai"><code>Ai</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>onIntentConfirmed</td> <td><code>function</code></td> <td></td> <td>handler, which will be called when intent is confirmed</td> </tr> <tr> <td>getMeta</td> <td><code>function</code></td> <td><code></code></td> <td>handler, which will be called when intent is confirmed</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript"><span class="hljs-keyword">const</span> { Router, ai } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;botnaut&apos;</span>); bot.use(ai.onConfirmMiddleware((senderId, intent, text, timestamp, meta) =&gt; { <span class="hljs-comment">// log this information</span> }, (req) =&gt; { <span class="hljs-comment">// create and return meta data object</span> })); bot.use(ai.makeSure([<span class="hljs-string">&apos;intent1&apos;</span>, <span class="hljs-string">&apos;intent2&apos;</span>]), (req, res) =&gt; { <span class="hljs-built_in">console</span>.log(req.confidences); <span class="hljs-comment">// { intent1: 0.8604, intent2: undefined }</span> res.text(<span class="hljs-string">&apos;What you mean?&apos;</span>, res.ensures({ intent1: <span class="hljs-string">&apos;Intent one?&apos;</span>, intent2: <span class="hljs-string">&apos;Intent two?&apos;</span>, anyOther: <span class="hljs-string">&apos;Niether&apos;</span> })); }); </code></pre> <div id="Ai_register">&#xA0;</div> <h3 id="airegistermodel-options-prefix-&#x21D2;-wingbotmodel"><a name="airegistermodel-options-prefix-&#x21D2;-wingbotmodel" class="plugin-anchor" href="#airegistermodel-options-prefix-&#x21D2;-wingbotmodel"><i class="fa fa-link" aria-hidden="true"></i></a>ai.register(model, options, prefix) &#x21D2; <code>WingbotModel</code></h3> <p>Registers Wingbot AI model</p> <p><strong>Kind</strong>: instance method of <a href="#Ai"><code>Ai</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>model</td> <td><code>string</code></td> <td>model name</td> </tr> <tr> <td>options</td> <td><code>Object</code></td> <td>the configuration</td> </tr> <tr> <td>[options.cacheSize]</td> <td><code>number</code></td> <td>remember number of caches</td> </tr> <tr> <td>[options.matches]</td> <td><code>number</code></td> <td>ask AI for number of matches</td> </tr> <tr> <td>prefix</td> <td><code>string</code></td> <td>model prefix</td> </tr> </tbody> </table> <div id="Ai_match">&#xA0;</div> <h3 id="aimatchintent-confidence-prefix-&#x21D2;-function"><a name="aimatchintent-confidence-prefix-&#x21D2;-function" class="plugin-anchor" href="#aimatchintent-confidence-prefix-&#x21D2;-function"><i class="fa fa-link" aria-hidden="true"></i></a>ai.match(intent, [confidence], [prefix]) &#x21D2; <code>function</code></h3> <p>Returns matching middleware</p> <p><strong>Kind</strong>: instance method of <a href="#Ai"><code>Ai</code></a><br><strong>Returns</strong>: <code>function</code> - - the middleware </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> </tr> </thead> <tbody> <tr> <td>intent</td> <td><code>string</code> \</td> <td><code>Array</code></td> <td></td> </tr> <tr> <td>[confidence]</td> <td><code>number</code></td> <td><code></code></td> </tr> <tr> <td>[prefix]</td> <td><code>string</code></td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript"><span class="hljs-keyword">const</span> { Router, ai } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;botnaut&apos;</span>); ai.register(<span class="hljs-string">&apos;app-model&apos;</span>); bot.use(ai.match(<span class="hljs-string">&apos;intent1&apos;</span>), (req, res) =&gt; { <span class="hljs-built_in">console</span>.log(req.confidences); <span class="hljs-comment">// { intent1: 0.9604 }</span> res.text(<span class="hljs-string">&apos;Oh, intent 1 :)&apos;</span>); }); </code></pre> <div id="Ai_navigate">&#xA0;</div> <h3 id="ainavigateknownintents-threshold-confidence-prefix-&#x21D2;-function"><a name="ainavigateknownintents-threshold-confidence-prefix-&#x21D2;-function" class="plugin-anchor" href="#ainavigateknownintents-threshold-confidence-prefix-&#x21D2;-function"><i class="fa fa-link" aria-hidden="true"></i></a>ai.navigate(knownIntents, [threshold], [confidence], [prefix]) &#x21D2; <code>function</code></h3> <p>Create AI middleware, which resolves multiple replies and <strong>makes postback, when it&apos;s confident</strong> Confidence should be between <code>threshold</code> and <code>confidence</code> to proceed to next resolver</p> <p><strong>Kind</strong>: instance method of <a href="#Ai"><code>Ai</code></a><br><strong>Returns</strong>: <code>function</code> - - the middleware </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>knownIntents</td> <td><code>Array</code> \</td> <td><code>Object</code></td> <td></td> <td>list or map of accepted intents</td> </tr> <tr> <td>[threshold]</td> <td><code>number</code></td> <td><code></code></td> <td>lower threshold</td> </tr> <tr> <td>[confidence]</td> <td><code>number</code></td> <td><code></code></td> <td>upper threshold for confidence</td> </tr> <tr> <td>[prefix]</td> <td><code>string</code></td> <td></td> <td>model name</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript"><span class="hljs-keyword">const</span> { Router, ai } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;botnaut&apos;</span>); bot.use(ai.navigate([<span class="hljs-string">&apos;intent1&apos;</span>, <span class="hljs-string">&apos;intent2&apos;</span>]), (req, res) =&gt; { <span class="hljs-built_in">console</span>.log(req.confidences); <span class="hljs-comment">// { intent1: 0.8604, intent2: undefined }</span> res.text(<span class="hljs-string">&apos;What you mean?&apos;</span>, res.ensures({ intent1: <span class="hljs-string">&apos;Intent one?&apos;</span>, intent2: <span class="hljs-string">&apos;Intent two?&apos;</span>, anyOther: <span class="hljs-string">&apos;Niether&apos;</span> })); }); </code></pre> <div id="Ai_makeSure">&#xA0;</div> <h3 id="aimakesureknownintents-threshold-confidence-prefix-&#x21D2;-function"><a name="aimakesureknownintents-threshold-confidence-prefix-&#x21D2;-function" class="plugin-anchor" href="#aimakesureknownintents-threshold-confidence-prefix-&#x21D2;-function"><i class="fa fa-link" aria-hidden="true"></i></a>ai.makeSure(knownIntents, [threshold], [confidence], prefix) &#x21D2; <code>function</code></h3> <p>Create AI middleware, which resolves multiple replies. Confidence should be between <code>threshold</code> and <code>confidence</code> to proceed to next resolver</p> <p><strong>Kind</strong>: instance method of <a href="#Ai"><code>Ai</code></a><br><strong>Returns</strong>: <code>function</code> - - the middleware </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>knownIntents</td> <td><code>Array</code> \</td> <td><code>Object</code></td> <td></td> <td>list or map of accepted intents</td> </tr> <tr> <td>[threshold]</td> <td><code>number</code></td> <td><code></code></td> <td>lower threshold</td> </tr> <tr> <td>[confidence]</td> <td><code>number</code></td> <td><code></code></td> <td>upper threshold for confidence</td> </tr> <tr> <td>prefix</td> <td><code>string</code></td> <td></td> <td>model name</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript"><span class="hljs-keyword">const</span> { Router, ai } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;botnaut&apos;</span>); bot.use(ai.makeSure([<span class="hljs-string">&apos;intent1&apos;</span>, <span class="hljs-string">&apos;intent2&apos;</span>]), (req, res) =&gt; { <span class="hljs-built_in">console</span>.log(req.confidences); <span class="hljs-comment">// { intent1: 0.8604, intent2: undefined }</span> res.text(<span class="hljs-string">&apos;What you mean?&apos;</span>, res.ensures({ intent1: <span class="hljs-string">&apos;Intent one?&apos;</span>, intent2: <span class="hljs-string">&apos;Intent two?&apos;</span>, anyOther: <span class="hljs-string">&apos;Niether&apos;</span> })); }); </code></pre> <div id="markAsHandled">&#xA0;</div> <h2 id="markashandledaihandled-&#x21D2;-request"><a name="markashandledaihandled-&#x21D2;-request" class="plugin-anchor" href="#markashandledaihandled-&#x21D2;-request"><i class="fa fa-link" aria-hidden="true"></i></a>markAsHandled([aiHandled]) &#x21D2; <code>Request</code></h2> <p>Mark request as handled - usefull for AI analytics</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>[aiHandled]</td> <td><code>boolean</code></td> <td><code>true</code></td> <td>true by default</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript">bot.use(<span class="hljs-string">&apos;some other query&apos;</span>, (req, res) =&gt; { req.markAsHandled(); }); </code></pre> </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="bufferloader.html" class="navigation navigation-prev " aria-label="Previous page: Utils"> <i class="fa fa-angle-left"></i> </a> <a href="serverlessAWS.html" class="navigation navigation-next " aria-label="Next page: Serverless"> <i class="fa fa-angle-right"></i> </a> </div> <script> var gitbook = gitbook || []; gitbook.push(function() { gitbook.page.hasChanged({"page":{"title":"Ai","level":"2.9","depth":1,"next":{"title":"Serverless","level":"2.10","depth":1,"path":"api/serverlessAWS.md","ref":"api/serverlessAWS.md","articles":[]},"previous":{"title":"Utils","level":"2.8","depth":1,"path":"api/bufferloader.md","ref":"api/bufferloader.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/Ai.md","mtime":"2018-05-23T15:31:55.124Z","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>