UNPKG

botnaut

Version:

Facebook Messenger Chatbot Framework

1,470 lines (895 loc) 48.1 kB
<!DOCTYPE HTML> <html lang="" > <head> <meta charset="UTF-8"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>Responder · 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="Router.html" /> <link rel="prev" href="Request.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 active" 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 " 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=".." >Responder</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"> <div id="Responder">&#xA0;</div> <h2 id="responder"><a name="responder" class="plugin-anchor" href="#responder"><i class="fa fa-link" aria-hidden="true"></i></a>Responder</h2> <p><strong>Kind</strong>: global class </p> <ul> <li><a href="#Responder">Responder</a><ul> <li><a href="#new_Responder_new">new Responder()</a></li> <li><a href="#Responder_data">.data</a> : <code>object</code></li> <li><a href="#Responder_setMessgingType">.setMessgingType(messagingType, [tag])</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_isResponseType">.isResponseType()</a> &#x21D2; <code>boolean</code></li> <li><a href="#Responder_setData">.setData(data)</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_text">.text(text, [quickReplies])</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_setState">.setState(object)</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_addQuickReply">.addQuickReply(action, title, [data], [prepend])</a></li> <li><a href="#Responder_expected">.expected(action)</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_toAbsoluteAction">.toAbsoluteAction(action)</a> &#x21D2; <code>string</code></li> <li><a href="#Responder_image">.image(imageUrl, [reusable])</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_video">.video(videoUrl, [reusable])</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_file">.file(fileUrl, [reusable])</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_wait">.wait([ms])</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_typingOn">.typingOn()</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_typingOff">.typingOff()</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_seen">.seen()</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_passThread">.passThread(targetAppId, [data])</a> &#x21D2; <code>this</code></li> <li><a href="#Responder_receipt">.receipt(recipientName, [paymentMethod], [currency], [uniqueCode])</a> &#x21D2; <code>ReceiptTemplate</code></li> <li><a href="#Responder_button">.button(text)</a> &#x21D2; <code>ButtonTemplate</code></li> <li><a href="#Responder_genericTemplate">.genericTemplate([shareable], [isSquare])</a> &#x21D2; <code>GenericTemplate</code></li> <li><a href="#Responder_list">.list([topElementStyle])</a> &#x21D2; <code>ListTemplate</code></li> </ul> </li> </ul> <div id="new_Responder_new">&#xA0;</div> <h3 id="new-responder"><a name="new-responder" class="plugin-anchor" href="#new-responder"><i class="fa fa-link" aria-hidden="true"></i></a>new Responder()</h3> <p>Instance of responder is passed as second parameter of handler (res)</p> <div id="Responder_data">&#xA0;</div> <h3 id="responderdata--object"><a name="responderdata--object" class="plugin-anchor" href="#responderdata--object"><i class="fa fa-link" aria-hidden="true"></i></a>responder.data : <code>object</code></h3> <p><strong>Kind</strong>: instance property of <a href="#Responder"><code>Responder</code></a> </p> <div id="Responder_setMessgingType">&#xA0;</div> <h3 id="respondersetmessgingtypemessagingtype-tag-&#x21D2;-this"><a name="respondersetmessgingtypemessagingtype-tag-&#x21D2;-this" class="plugin-anchor" href="#respondersetmessgingtypemessagingtype-tag-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.setMessgingType(messagingType, [tag]) &#x21D2; <code>this</code></h3> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> </tr> </thead> <tbody> <tr> <td>messagingType</td> <td><code>string</code></td> <td></td> </tr> <tr> <td>[tag]</td> <td><code>string</code></td> <td><code>null</code></td> </tr> </tbody> </table> <div id="Responder_isResponseType">&#xA0;</div> <h3 id="responderisresponsetype-&#x21D2;-boolean"><a name="responderisresponsetype-&#x21D2;-boolean" class="plugin-anchor" href="#responderisresponsetype-&#x21D2;-boolean"><i class="fa fa-link" aria-hidden="true"></i></a>responder.isResponseType() &#x21D2; <code>boolean</code></h3> <p>Returns true, when responder is not sending an update (notification) message</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <div id="Responder_setData">&#xA0;</div> <h3 id="respondersetdatadata-&#x21D2;-this"><a name="respondersetdatadata-&#x21D2;-this" class="plugin-anchor" href="#respondersetdatadata-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.setData(data) &#x21D2; <code>this</code></h3> <p>Set temporary data to responder, which are persisted through single event</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> </tr> </thead> <tbody> <tr> <td>data</td> <td><code>object</code></td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript">bot.use(<span class="hljs-string">&apos;foo&apos;</span>, (req, res, postBack) =&gt; { res.setData({ a: <span class="hljs-number">1</span> }); postBack(<span class="hljs-string">&apos;bar&apos;</span>); }); bot.use(<span class="hljs-string">&apos;bar&apos;</span>, (req, res) =&gt; { res.data.a; <span class="hljs-comment">// === 1 from postback</span> }); </code></pre> <div id="Responder_text">&#xA0;</div> <h3 id="respondertexttext-quickreplies-&#x21D2;-this"><a name="respondertexttext-quickreplies-&#x21D2;-this" class="plugin-anchor" href="#respondertexttext-quickreplies-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.text(text, [quickReplies]) &#x21D2; <code>this</code></h3> <p>Send text as a response</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>text</td> <td><code>string</code></td> <td>text to send to user, can contain placeholders (%s)</td> </tr> <tr> <td>[quickReplies]</td> <td><code>Object.&lt;string, string&gt;</code> \</td> <td><code>Array.&lt;Object&gt;</code></td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript"><span class="hljs-comment">// simply</span> res.text(<span class="hljs-string">&apos;Hello %s&apos;</span>, name, { action: <span class="hljs-string">&apos;Quick reply&apos;</span>, another: <span class="hljs-string">&apos;Another quick reply&apos;</span> }); <span class="hljs-comment">// complex</span> res.text(<span class="hljs-string">&apos;Hello %s&apos;</span>, name, [ { action: <span class="hljs-string">&apos;action&apos;</span>, title: <span class="hljs-string">&apos;Quick reply&apos;</span> }, { action: <span class="hljs-string">&apos;complexAction&apos;</span>, <span class="hljs-comment">// required</span> title: <span class="hljs-string">&apos;Another quick reply&apos;</span>, <span class="hljs-comment">// required</span> match: <span class="hljs-string">&apos;string&apos;</span> || <span class="hljs-regexp">/regexp/</span>, <span class="hljs-comment">// optional</span> someData: <span class="hljs-string">&apos;Will be included in payload data&apos;</span> <span class="hljs-comment">// optional</span> } ]); </code></pre> <div id="Responder_setState">&#xA0;</div> <h3 id="respondersetstateobject-&#x21D2;-this"><a name="respondersetstateobject-&#x21D2;-this" class="plugin-anchor" href="#respondersetstateobject-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.setState(object) &#x21D2; <code>this</code></h3> <p>Sets new attributes to state (with Object.assign())</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> </tr> </thead> <tbody> <tr> <td>object</td> <td><code>object</code></td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript">res.setState({ visited: <span class="hljs-literal">true</span> }); </code></pre> <div id="Responder_addQuickReply">&#xA0;</div> <h3 id="responderaddquickreplyaction-title-data-prepend"><a name="responderaddquickreplyaction-title-data-prepend" class="plugin-anchor" href="#responderaddquickreplyaction-title-data-prepend"><i class="fa fa-link" aria-hidden="true"></i></a>responder.addQuickReply(action, title, [data], [prepend])</h3> <p>Appends quick reply, to be sent with following text method</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>action</td> <td><code>string</code></td> <td></td> <td>relative or absolute action</td> </tr> <tr> <td>title</td> <td><code>string</code></td> <td></td> <td>quick reply title</td> </tr> <tr> <td>[data]</td> <td><code>Object</code></td> <td></td> <td>additional data</td> </tr> <tr> <td>[prepend]</td> <td><code>boolean</code></td> <td><code>false</code></td> <td>set true to add reply at the beginning</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript">bot.use((req, res) =&gt; { res.addQuickReply(<span class="hljs-string">&apos;barAction&apos;</span>, <span class="hljs-string">&apos;last action&apos;</span>); res.addQuickReply(<span class="hljs-string">&apos;theAction&apos;</span>, <span class="hljs-string">&apos;first action&apos;</span>, {}, <span class="hljs-literal">true</span>); res.text(<span class="hljs-string">&apos;Text&apos;</span>, { fooAction: <span class="hljs-string">&apos;goto foo&apos;</span> }); <span class="hljs-comment">// will be merged and sent with previously added quick replies</span> }); </code></pre> <div id="Responder_expected">&#xA0;</div> <h3 id="responderexpectedaction-&#x21D2;-this"><a name="responderexpectedaction-&#x21D2;-this" class="plugin-anchor" href="#responderexpectedaction-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.expected(action) &#x21D2; <code>this</code></h3> <p>When user writes some text as reply, it will be processed as action</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>action</td> <td><code>string</code></td> <td>desired action</td> </tr> </tbody> </table> <div id="Responder_toAbsoluteAction">&#xA0;</div> <h3 id="respondertoabsoluteactionaction-&#x21D2;-string"><a name="respondertoabsoluteactionaction-&#x21D2;-string" class="plugin-anchor" href="#respondertoabsoluteactionaction-&#x21D2;-string"><i class="fa fa-link" aria-hidden="true"></i></a>responder.toAbsoluteAction(action) &#x21D2; <code>string</code></h3> <p>Converts relative action to absolute action path</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a><br><strong>Returns</strong>: <code>string</code> - absolute action path </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>action</td> <td><code>string</code></td> <td>relative action to covert to absolute</td> </tr> </tbody> </table> <div id="Responder_image">&#xA0;</div> <h3 id="responderimageimageurl-reusable-&#x21D2;-this"><a name="responderimageimageurl-reusable-&#x21D2;-this" class="plugin-anchor" href="#responderimageimageurl-reusable-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.image(imageUrl, [reusable]) &#x21D2; <code>this</code></h3> <p>Sends image as response. Requires appUrl option to send images from server</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>imageUrl</td> <td><code>string</code></td> <td></td> <td>relative or absolute url</td> </tr> <tr> <td>[reusable]</td> <td><code>boolean</code></td> <td><code>false</code></td> <td>force facebook to cache image</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript"><span class="hljs-comment">// image on same server (appUrl option)</span> res.image(<span class="hljs-string">&apos;/img/foo.png&apos;</span>); <span class="hljs-comment">// image at url</span> res.image(<span class="hljs-string">&apos;https://google.com/img/foo.png&apos;</span>); </code></pre> <div id="Responder_video">&#xA0;</div> <h3 id="respondervideovideourl-reusable-&#x21D2;-this"><a name="respondervideovideourl-reusable-&#x21D2;-this" class="plugin-anchor" href="#respondervideovideourl-reusable-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.video(videoUrl, [reusable]) &#x21D2; <code>this</code></h3> <p>Sends video as response. Requires appUrl option to send videos from server</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>videoUrl</td> <td><code>string</code></td> <td></td> <td>relative or absolute url</td> </tr> <tr> <td>[reusable]</td> <td><code>boolean</code></td> <td><code>false</code></td> <td>force facebook to cache asset</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript"><span class="hljs-comment">// file on same server (appUrl option)</span> res.video(<span class="hljs-string">&apos;/img/foo.mp4&apos;</span>); <span class="hljs-comment">// file at url</span> res.video(<span class="hljs-string">&apos;https://google.com/img/foo.mp4&apos;</span>); </code></pre> <div id="Responder_file">&#xA0;</div> <h3 id="responderfilefileurl-reusable-&#x21D2;-this"><a name="responderfilefileurl-reusable-&#x21D2;-this" class="plugin-anchor" href="#responderfilefileurl-reusable-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.file(fileUrl, [reusable]) &#x21D2; <code>this</code></h3> <p>Sends file as response. Requires appUrl option to send files from server</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>fileUrl</td> <td><code>string</code></td> <td></td> <td>relative or absolute url</td> </tr> <tr> <td>[reusable]</td> <td><code>boolean</code></td> <td><code>false</code></td> <td>force facebook to cache asset</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript"><span class="hljs-comment">// file on same server (appUrl option)</span> res.file(<span class="hljs-string">&apos;/img/foo.pdf&apos;</span>); <span class="hljs-comment">// file at url</span> res.file(<span class="hljs-string">&apos;https://google.com/img/foo.pdf&apos;</span>); </code></pre> <div id="Responder_wait">&#xA0;</div> <h3 id="responderwaitms-&#x21D2;-this"><a name="responderwaitms-&#x21D2;-this" class="plugin-anchor" href="#responderwaitms-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.wait([ms]) &#x21D2; <code>this</code></h3> <p>Sets delay between two responses</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> </tr> </thead> <tbody> <tr> <td>[ms]</td> <td><code>number</code></td> <td><code>600</code></td> </tr> </tbody> </table> <div id="Responder_typingOn">&#xA0;</div> <h3 id="respondertypingon-&#x21D2;-this"><a name="respondertypingon-&#x21D2;-this" class="plugin-anchor" href="#respondertypingon-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.typingOn() &#x21D2; <code>this</code></h3> <p>Sends &quot;typing...&quot; information</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <div id="Responder_typingOff">&#xA0;</div> <h3 id="respondertypingoff-&#x21D2;-this"><a name="respondertypingoff-&#x21D2;-this" class="plugin-anchor" href="#respondertypingoff-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.typingOff() &#x21D2; <code>this</code></h3> <p>Stops &quot;typing...&quot; information</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <div id="Responder_seen">&#xA0;</div> <h3 id="responderseen-&#x21D2;-this"><a name="responderseen-&#x21D2;-this" class="plugin-anchor" href="#responderseen-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.seen() &#x21D2; <code>this</code></h3> <p>Reports last message from user as seen</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <div id="Responder_passThread">&#xA0;</div> <h3 id="responderpassthreadtargetappid-data-&#x21D2;-this"><a name="responderpassthreadtargetappid-data-&#x21D2;-this" class="plugin-anchor" href="#responderpassthreadtargetappid-data-&#x21D2;-this"><i class="fa fa-link" aria-hidden="true"></i></a>responder.passThread(targetAppId, [data]) &#x21D2; <code>this</code></h3> <p>Pass thread to another app</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> </tr> </thead> <tbody> <tr> <td>targetAppId</td> <td><code>string</code></td> <td></td> </tr> <tr> <td>[data]</td> <td><code>string</code> \</td> <td><code>object</code></td> <td><code>null</code></td> </tr> </tbody> </table> <div id="Responder_receipt">&#xA0;</div> <h3 id="responderreceiptrecipientname-paymentmethod-currency-uniquecode-&#x21D2;-receipttemplate"><a name="responderreceiptrecipientname-paymentmethod-currency-uniquecode-&#x21D2;-receipttemplate" class="plugin-anchor" href="#responderreceiptrecipientname-paymentmethod-currency-uniquecode-&#x21D2;-receipttemplate"><i class="fa fa-link" aria-hidden="true"></i></a>responder.receipt(recipientName, [paymentMethod], [currency], [uniqueCode]) &#x21D2; <code>ReceiptTemplate</code></h3> <p>Sends Receipt template</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>recipientName</td> <td><code>string</code></td> <td></td> <td></td> </tr> <tr> <td>[paymentMethod]</td> <td><code>string</code></td> <td><code>&quot;&apos;Cash&apos;&quot;</code></td> <td>should not contain more then 4 numbers</td> </tr> <tr> <td>[currency]</td> <td><code>string</code></td> <td><code>&quot;&apos;USD&apos;&quot;</code></td> <td>sets right currency</td> </tr> <tr> <td>[uniqueCode]</td> <td><code>string</code></td> <td><code>null</code></td> <td>when omitted, will be generated randomly</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript">res.receipt(<span class="hljs-string">&apos;Name&apos;</span>, <span class="hljs-string">&apos;Cash&apos;</span>, <span class="hljs-string">&apos;CZK&apos;</span>, <span class="hljs-string">&apos;1&apos;</span>) .addElement(<span class="hljs-string">&apos;Element name&apos;</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-string">&apos;/inside.png&apos;</span>, <span class="hljs-string">&apos;text&apos;</span>) .send(); </code></pre> <div id="Responder_button">&#xA0;</div> <h3 id="responderbuttontext-&#x21D2;-buttontemplate"><a name="responderbuttontext-&#x21D2;-buttontemplate" class="plugin-anchor" href="#responderbuttontext-&#x21D2;-buttontemplate"><i class="fa fa-link" aria-hidden="true"></i></a>responder.button(text) &#x21D2; <code>ButtonTemplate</code></h3> <p>Sends nice button template. It can redirect user to server with token in url</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> </tr> </thead> <tbody> <tr> <td>text</td> <td><code>string</code></td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript">res.button(<span class="hljs-string">&apos;Hello&apos;</span>) .postBackButton(<span class="hljs-string">&apos;Text&apos;</span>, <span class="hljs-string">&apos;action&apos;</span>) .urlButton(<span class="hljs-string">&apos;Url button&apos;</span>, <span class="hljs-string">&apos;/internal&apos;</span>, <span class="hljs-literal">true</span>) <span class="hljs-comment">// opens webview with token</span> .urlButton(<span class="hljs-string">&apos;Other button&apos;</span>, <span class="hljs-string">&apos;https://goo.gl&apos;</span>) <span class="hljs-comment">// opens in internal browser</span> .send(); </code></pre> <div id="Responder_genericTemplate">&#xA0;</div> <h3 id="respondergenerictemplateshareable-issquare-&#x21D2;-generictemplate"><a name="respondergenerictemplateshareable-issquare-&#x21D2;-generictemplate" class="plugin-anchor" href="#respondergenerictemplateshareable-issquare-&#x21D2;-generictemplate"><i class="fa fa-link" aria-hidden="true"></i></a>responder.genericTemplate([shareable], [isSquare]) &#x21D2; <code>GenericTemplate</code></h3> <p>Creates a generic template</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>[shareable]</td> <td><code>boolean</code></td> <td><code>false</code></td> <td>ability to share template</td> </tr> <tr> <td>[isSquare]</td> <td><code>boolean</code></td> <td><code>false</code></td> <td>use square aspect ratio for images</td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript">res.genericTemplate() .addElement(<span class="hljs-string">&apos;title&apos;</span>, <span class="hljs-string">&apos;subtitle&apos;</span>) .setElementImage(<span class="hljs-string">&apos;/local.png&apos;</span>) .setElementUrl(<span class="hljs-string">&apos;https://www.seznam.cz&apos;</span>) .postBackButton(<span class="hljs-string">&apos;Button title&apos;</span>, <span class="hljs-string">&apos;action&apos;</span>, { actionData: <span class="hljs-number">1</span> }) .addElement(<span class="hljs-string">&apos;another&apos;</span>, <span class="hljs-string">&apos;subtitle&apos;</span>) .setElementImage(<span class="hljs-string">&apos;https://goo.gl/image.png&apos;</span>) .setElementAction(<span class="hljs-string">&apos;action&apos;</span>, { actionData: <span class="hljs-number">1</span> }) .urlButton(<span class="hljs-string">&apos;Local link with extension&apos;</span>, <span class="hljs-string">&apos;/local/path&apos;</span>, <span class="hljs-literal">true</span>, <span class="hljs-string">&apos;compact&apos;</span>) .send(); </code></pre> <div id="Responder_list">&#xA0;</div> <h3 id="responderlisttopelementstyle-&#x21D2;-listtemplate"><a name="responderlisttopelementstyle-&#x21D2;-listtemplate" class="plugin-anchor" href="#responderlisttopelementstyle-&#x21D2;-listtemplate"><i class="fa fa-link" aria-hidden="true"></i></a>responder.list([topElementStyle]) &#x21D2; <code>ListTemplate</code></h3> <p>Creates a generic template</p> <p><strong>Kind</strong>: instance method of <a href="#Responder"><code>Responder</code></a> </p> <table> <thead> <tr> <th>Param</th> <th>Type</th> <th>Default</th> </tr> </thead> <tbody> <tr> <td>[topElementStyle]</td> <td><code>&apos;large&apos;</code> \</td> <td><code>&apos;compact&apos;</code></td> <td><code>&apos;large&apos;</code></td> </tr> </tbody> </table> <p><strong>Example</strong> </p> <pre><code class="lang-javascript">res.list(<span class="hljs-string">&apos;compact&apos;</span>) .postBackButton(<span class="hljs-string">&apos;Main button&apos;</span>, <span class="hljs-string">&apos;action&apos;</span>, { actionData: <span class="hljs-number">1</span> }) .addElement(<span class="hljs-string">&apos;title&apos;</span>, <span class="hljs-string">&apos;subtitle&apos;</span>) .setElementImage(<span class="hljs-string">&apos;/local.png&apos;</span>) .setElementUrl(<span class="hljs-string">&apos;https://www.seznam.cz&apos;</span>) .postBackButton(<span class="hljs-string">&apos;Button title&apos;</span>, <span class="hljs-string">&apos;action&apos;</span>, { actionData: <span class="hljs-number">1</span> }) .addElement(<span class="hljs-string">&apos;another&apos;</span>, <span class="hljs-string">&apos;subtitle&apos;</span>) .setElementImage(<span class="hljs-string">&apos;https://goo.gl/image.png&apos;</span>) .setElementAction(<span class="hljs-string">&apos;action&apos;</span>, { actionData: <span class="hljs-number">1</span> }) .urlButton(<span class="hljs-string">&apos;Local link with extension&apos;</span>, <span class="hljs-string">&apos;/local/path&apos;</span>, <span class="hljs-literal">true</span>, <span class="hljs-string">&apos;compact&apos;</span>) .send(); </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="Request.html" class="navigation navigation-prev " aria-label="Previous page: Request"> <i class="fa fa-angle-left"></i> </a> <a href="Router.html" class="navigation navigation-next " aria-label="Next page: Router"> <i class="fa fa-angle-right"></i> </a> </div> <script> var gitbook = gitbook || []; gitbook.push(function() { gitbook.page.hasChanged({"page":{"title":"Responder","level":"2.2","depth":1,"next":{"title":"Router","level":"2.3","depth":1,"path":"api/Router.md","ref":"api/Router.md","articles":[]},"previous":{"title":"Request","level":"2.1","depth":1,"path":"api/Request.md","ref":"api/Request.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/Responder.md","mtime":"2018-05-23T15:31:55.027Z","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>