{
    "componentChunkName": "component---src-templates-doc-page-js",
    "path": "/docs/en/telephony/script_voice_bot/",
    "result": {"data":{"site":{"siteMetadata":{"title":"Gatsby-doc-engine"}},"markdownRemark":{"id":"a1e22fbc-0239-555f-8439-2c2193204872","excerpt":"Bot script for a voice broadcast Text-to-speech and speech-to-text functions are used in voice broadcasts.?> Text-to-speech — the text is converted to voice…","html":"<h1>Bot script for a voice broadcast</h1>\n<hr>\n<p>Text-to-speech and speech-to-text functions are used in voice broadcasts.</p>\n<p class='warn'>Text-to-speech — the text is converted to voice.</p>\n<p class='warn'>Speech-to-text — the sound stream is converted into text.</p>\n<p>That aspect of bot script development has certain peculiarities. This article considers the following aspects:</p>\n<ul>\n<li><a href=\"#adapting-the-script-for-a-telephone-channel\">Adapting the script for a telephone channel</a></li>\n<li><a href=\"#using-audio-files\">Using audio files</a></li>\n<li><a href=\"#working-with-a-phone-number-list\">Working with a phone number list</a></li>\n<li><a href=\"#scheduling-a-call-from-a-script\">Scheduling a call from a script</a></li>\n<li><a href=\"#tagging-the-broadcast-outcomes\">Tagging the broadcast outcomes</a></li>\n<li><a href=\"#extending-the-broadcast-report\">Extending the broadcast report</a></li>\n<li><a href=\"#retrieving-call-recordings\">Retrieving call recordings</a></li>\n</ul>\n</br>\n<h3>Adapting the script for a telephone channel</h3>\n<h5>Recognition</h5>\n<p>When adapting the bot script for a phone channel, you need to catch and handle the event <code class=\"language-text\">speechNotRecognized</code>. The event is triggered if a client request could not be recognized within 5 seconds, or if the recognition returned nothing.</p>\n<p>For example:</p>\n<ul>\n<li>The bot catches the event and requests the client to repeat the phrase once more:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span> speechNotRecognized || noContext = true\n        <span class=\"token storageType\">event:</span> speechNotRecognized\n        <span class=\"token variableParameter\">a:</span> Please repeat, I can’t hear you.\n        <span class=\"token variableParameter\">go!:</span> <span class=\"token constantCharacter\">{{$session.lastState}}</span></code></pre></div>\n<ul>\n<li>One of the following phrases is selected:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span> CatchAll\n        <span class=\"token storageType\">event!:</span> speechNotRecognized\n        <span class=\"token storageType\">q!:</span> *\n        <span class=\"token variableParameter\">random:</span>\n            <span class=\"token variableParameter\">a:</span> Could you repeat please?\n            <span class=\"token variableParameter\">a:</span> I didn’t catch that.\n            <span class=\"token variableParameter\">a:</span> Please repeat.\n            <span class=\"token variableParameter\">a:</span> I’m sorry, I couldn’t hear what you said.</code></pre></div>\n<ul>\n<li>Let us consider an example when the bot encounters a voice message system.</li>\n</ul>\n<p class='tip'>Please note that pre-paid minutes in your subscriber plan will be spent while the bot is talking to an automated voice message system.</p>\n<p>The bot asks the client to repeat the reply or hangs up if it could not recognize the phrase:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span> NoInput || noContext=true\n        <span class=\"token storageType\">event:</span> speechNotRecognized\n        <span class=\"token variableParameter\">script:</span>\n            $session.noInputCounter = $session.noInputCounter || 0;\n            $session.noInputCounter++;\n        \n        <span class=\"token variableParameter\">if:</span> $session.noInputCounter >= 5\n            <span class=\"token variableParameter\">a:</span> It seems that the line is bad. I will call back later.\n            <span class=\"token variableParameter\">script:</span>\n                $dialer.hangUp('(The bot has hung up)');\n        <span class=\"token variableParameter\">else:</span>\n            <span class=\"token variableParameter\">a:</span> I cannot hear you, please repeat!</code></pre></div>\n<p class='warn'><a href=/1.10.3/docs/en/JAICP_DSL/tags/declarative_tags/event  >Other <code class=\"language-text\">event</code> for the telephone channel</a></p>\n</br>\n<h5>Call termination by the bot</h5>\n<p class='warn'>The bot cannot use the method <code class=\"language-text\">$dialer.hangUp('(Bot has hung up)')</code> to terminate a call by itself.</p>\n<p>The phrase <code class=\"language-text\">Bot has hung up</code> will be displayed in the non-voice channel that you are using for bot debugging.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span> HangUp\n        <span class=\"token variableParameter\">a:</span> Have a good day. Goodbye.\n        <span class=\"token variableParameter\">script:</span>\n            $dialer.hangUp('(The bot has hung up)');</code></pre></div>\n<p>The argument for <code class=\"language-text\">$dialer.hangUp()</code> is optional.</p>\n<p class='warn'>Use <code class=\"language-text\">event: botHangup</code> to track an event when the conversation has been terminated at the request of the bot.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">  <span class=\"token keyword\">state:</span> BotHangUp\n    <span class=\"token storageType\">event:</span> botHangup\n    <span class=\"token variableParameter\">script:</span>\n        log(\"Got event botHangup\");</code></pre></div>\n</br>\n<h5>Call termination by the client</h5>\n<p class='warn'>Use <code class=\"language-text\">event: hangup</code> to track the event of call termination by the client.</p>\n<p>For example, to determine what state the client was in before the call was terminated:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span> ClientHungUp\n        <span class=\"token storageType\">event!:</span> hangup\n        <span class=\"token variableParameter\">script:</span>\n            getClientHangUpReaction($session.lastState);</code></pre></div>\n<p>Here, if the bot terminates the call by itself, the <code class=\"language-text\">hangup</code> event is not triggered.</p>\n</br>\n<h5>Transfer to the operator</h5>\n<p>You can also transfer the call to an operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token literal-property property\">script</span><span class=\"token operator\">:</span>\n    $response<span class=\"token punctuation\">.</span>replies <span class=\"token operator\">=</span> $response<span class=\"token punctuation\">.</span>replies <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    $response<span class=\"token punctuation\">.</span>replies\n     <span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span><span class=\"token string\">\"switch\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">phoneNumber</span><span class=\"token operator\">:</span><span class=\"token number\">88008000000</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p class='warn'><a href=/1.10.3/docs/en/bot_answers/message_types#switch  >More about call transfers to operators</a></p>\n</br>\n<h5>Tone dialing</h5>\n<p>The bot may request and process the sending of dtmf messages (numbers/characters coded as tones).</p>\n<p>A dtmf message request:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token literal-property property\">script</span><span class=\"token operator\">:</span>\n    $response<span class=\"token punctuation\">.</span>replies <span class=\"token operator\">=</span> $response<span class=\"token punctuation\">.</span>replies <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    $response<span class=\"token punctuation\">.</span>replies<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'dtmf'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">max</span><span class=\"token operator\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span>            <span class=\"token comment\">//the maximum number of digits expected from the subscriber.</span>\n        <span class=\"token literal-property property\">timeout</span><span class=\"token operator\">:</span> <span class=\"token number\">15000</span>     <span class=\"token comment\">//the subscriber input timeout, in milliseconds (a number).</span>\n     <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Then a request is caught, for example, with the digits:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">state:</span> Digits\n    <span class=\"token storageType\">q:</span> $regexp&lt;\\d+>\n    <span class=\"token variableParameter\">a:</span> you have dialed <span class=\"token constantCharacter\">{{$parseTree.text}}</span>!</code></pre></div>\n<p>The event <code class=\"language-text\">noDtmfAnswerEvent</code> is triggered if the subscriber has not input a dtmf message:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span> noDTMF || noContext = true\n        <span class=\"token storageType\">event:</span> noDtmfAnswerEvent\n        <span class=\"token variableParameter\">a:</span> You have not selected anything.\n        <span class=\"token variableParameter\">go!:</span> <span class=\"token constantCharacter\">{{$session.lastState}}</span></code></pre></div>\n<p class='warn'><a href=/1.10.3/docs/en/bot_answers/message_types#dtmf  >More details about tone dialing</a></p>\n</br>\n<h5>Sessions</h5>\n<p class='warn'><a href=/1.10.3/docs/en/JS_API/session_lifetime_control  >More about sessions in the JAICP platform</a></p>\n<p>In voice broadcasts a session starts when the subscriber picks up the receiver or makes a call themselves. Call termination is treated as the session termination.</p>\n<p>Here, if you use the same script for other channels, then the session for them will start at the time of the first call by the client when there is no other active session for this client.</p>\n<p class='tip'>We do not recommend artificial session splitting for voice broadcasts using the <a href=/1.10.3/docs/en/JS_API/built_in_services/reactions/newSession  ><code class=\"language-text\">newSession</code></a> response.</p>\n</br>\n<h3>Using audio files</h3>\n<p>You can use a pre-recorded file for a reply from a bot. The platform allows you to use audio files in the <a href=\"https://en.wikipedia.org/wiki/Pulse-code_modulation\" target=\"_blank\" rel=\"noopener noreferrer\">PCM</a> format with the file extension <code class=\"language-text\">.wav</code>. PCM settings:</p>\n<ul>\n<li>constant bit rate <code class=\"language-text\">128 kb/s</code>;</li>\n<li>1 channel (mono);</li>\n<li>sampling rate <code class=\"language-text\">8000Hz</code>;</li>\n<li>codec <code class=\"language-text\">16-bit(PCM) little endian</code>.</li>\n</ul>\n<p>Add the <a href=\"/1.10.3/docs/en/JAICP_DSL/tags/reaction_tags/audio\">tag <code class=\"language-text\">audio</code></a> to the bot’s reply and include an audio file with the extension <code class=\"language-text\">.wav</code> in the link.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span> audio\n        <span class=\"token variableParameter\">audio:</span> https://example.wav   <span class=\"token comment\">// audio file link (any repository)</span></code></pre></div>\n</br>\n<h3>Working with a phone number list</h3>\n<p class='warn'><a href=/1.10.3/docs/en/telephony/lists_of_numbers  >Managing telephone number lists</a></p>\n<p>When creating a phone number list for a voice broadcast, you can add additional fields to the list. For example, <em>First name</em>, <em>Last name</em>, <em>City</em>. The table will only be validated by the first column that contains the phone numbers and the remaining fields will be loaded as text.</p>\n<p>You can use the data from the additional fields in a broadcast script.</p>\n<p class='warn'>The method <code class=\"language-text\">$dialer.getPayload()</code> returns a <code class=\"language-text\">json</code> object with populated phone number list fields.</p>\n<p>For example, we are uploading a phone number list:</p>\n</br>\n<table>\n<thead>\n<tr>\n<th align=\"center\">phone</th>\n<th align=\"center\">name</th>\n<th align=\"center\">address</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"center\">79990000000ᅠᅠ</td>\n<td align=\"center\">John ᅠᅠ  ᅠᅠ</td>\n<td align=\"center\">New York</td>\n</tr>\n</tbody>\n</table>\n</br>\n<p>Calling the method <code class=\"language-text\">$dialer.getPayload()</code> will return a <code class=\"language-text\">json</code> object:</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"phone\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"79990000000\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"name\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"John\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"address\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"New York\"</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Script use:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span> Hello\n        <span class=\"token variableParameter\">a:</span> Hello!\n        <span class=\"token variableParameter\">if:</span> $dialer.getPayload().name\n            <span class=\"token variableParameter\">a:</span> Your name is <span class=\"token constantCharacter\">{{$dialer.getPayload().name}}</span>\n        <span class=\"token variableParameter\">else:</span>\n            <span class=\"token variableParameter\">a:</span> I don’t know your name.</code></pre></div>\n<p>If the list has been uploaded with headers, then calling the method <code class=\"language-text\">$dialer.getPayload()</code> will return a <code class=\"language-text\">json</code> object:</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token punctuation\">{</span><span class=\"token number\">0</span><span class=\"token operator\">:</span> <span class=\"token string\">\"79990000000\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token operator\">:</span> <span class=\"token string\">\"John\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token operator\">:</span> <span class=\"token string\">\"New York\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>In this case <code class=\"language-text\">var name = $dialer.getPayload()[1]</code>.</p>\n<p>If the column is empty, then calling the <code class=\"language-text\">$dialer.getPayload().address</code> function will return an empty value.</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"phone\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"79990000000\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"name\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"John\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"address\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</br>\n<p class='warn'>The method <code class=\"language-text\">$dialer.getCaller()</code> returns a string with the user’s phone number in the format in which the telephone switchboard sends it.</p>\n<p>Script use:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span> Hello\n        <span class=\"token variableParameter\">a:</span> Hello!\n        <span class=\"token variableParameter\">a:</span> Your number is <span class=\"token constantCharacter\">{{getCaller()}}</span>.\n        <span class=\"token variableParameter\">if:</span> $dialer.getPayload().name\n            <span class=\"token variableParameter\">a:</span> Your name is <span class=\"token constantCharacter\">{{$dialer.getPayload().name}}</span>\n        <span class=\"token variableParameter\">else:</span>\n            <span class=\"token variableParameter\">a:</span> I don’t know your name.</code></pre></div>\n</br>\n<h3>Scheduling a call from a script</h3>\n<p>You may need to schedule a new call during a conversation between a bot and a client. For example, a client may ask you to call later.</p>\n<p class='warn'>Use the <code class=\"language-text\">$dialer.redial()</code> method to schedule a new call and override the calling policy for this number from your script.</p>\n<p><a href=\"https://help.just-ai.com/docs/api/calls_api/\" target=\"_blank\" rel=\"noopener noreferrer\">Parameters of this method match those of the <code class=\"language-text\">CallJobParametersList</code> method in Calls API</a>.</p>\n</br>\n<table>\n<thead>\n<tr>\n<th align=\"left\">Parameter</th>\n<th align=\"left\">Example</th>\n<th align=\"left\">Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\"><code class=\"language-text\">startDateTime</code></td>\n<td align=\"left\"><code class=\"language-text\">2020-03-23T00:00:00Z</code></td>\n<td align=\"left\">Call start date. Takes the <a href=\"https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Date\" target=\"_blank\" rel=\"noopener noreferrer\"><code class=\"language-text\">Date</code></a> object. </br> </br> The call will be made </br> within the <code class=\"language-text\">[startDateTime, finishDateTime]</code> interval.</td>\n</tr>\n<tr>\n<td align=\"left\"><code class=\"language-text\">finishDateTime</code></td>\n<td align=\"left\"><code class=\"language-text\">2020-03-23T00:00:00Z</code></td>\n<td align=\"left\">Call end date. Takes the <a href=\"https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Date\" target=\"_blank\" rel=\"noopener noreferrer\"><code class=\"language-text\">Date</code></a> object. </br> </br> Calls will not be made after <code class=\"language-text\">finishDateTime</code>.</td>\n</tr>\n<tr>\n<td align=\"left\"><code class=\"language-text\">allowedTime</code></td>\n<td align=\"left\"><code class=\"language-text\">\"mon\": [{\"localTimeFrom\": \"10:00\", \"localTimeTo\": \"11:30\"}]</code></td>\n<td align=\"left\">For each day of the week, one or several recommended calling intervals can be specified. </br> </br> <code class=\"language-text\">localTimeFrom</code> is the earliest time for a call. The time value is not absolute: customer’s local time will be used for calling. </br> </br> <code class=\"language-text\">localTimeTo</code> is the latest time for a call.  The time value is not absolute: customer’s local time will be used for calling.</td>\n</tr>\n<tr>\n<td align=\"left\"><code class=\"language-text\">allowedDays</code></td>\n<td align=\"left\"><code class=\"language-text\">[\"sun\"]</code></td>\n<td align=\"left\">Weekdays when calling is allowed.</td>\n</tr>\n<tr>\n<td align=\"left\"><code class=\"language-text\">maxAttempts</code></td>\n<td align=\"left\"><code class=\"language-text\">1</code></td>\n<td align=\"left\">Callback attempts.</td>\n</tr>\n<tr>\n<td align=\"left\"><code class=\"language-text\">retryIntervalInMinutes</code></td>\n<td align=\"left\"><code class=\"language-text\">120</code></td>\n<td align=\"left\">The pause (in minutes) between callback attempts.</td>\n</tr>\n<tr>\n<td align=\"left\"><code class=\"language-text\">gmtZone</code></td>\n<td align=\"left\"><code class=\"language-text\">\"+03:00\"</code></td>\n<td align=\"left\">Timezone ID. Should be specified from <code class=\"language-text\">\"-18:00\"</code> to <code class=\"language-text\">\"+18:00\"</code> or as the name of zone according to <a href=\"https://docs.oracle.com/middleware/12212/wcs/tag-ref/MISC/TimeZones.html\" target=\"_blank\" rel=\"noopener noreferrer\">IANA TZBD</a>.</td>\n</tr>\n</tbody>\n</table>\n</br>\n<p class='tip'>Please note that <code class=\"language-text\">$dialer.redial()</code> method is not used without specified parameters. To ensure the correct work of the method, it is necessary to set the parameter <code class=\"language-text\">startDateTime</code> or <code class=\"language-text\">allowedTime</code>. If the rest of the parameters are not specified, their values will be taken from the voice calling campaign settings.</p>\n<p>For example, you configure the following callback parameters:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">state:</span>\n    <span class=\"token storageType\">q!:</span> Сall back\n    <span class=\"token variableParameter\">script:</span>\n        $dialer.redial({\n            allowedTime: {\n                \"mon\": [{\"localTimeFrom\": \"10:00\", \"localTimeTo\": \"11:30\"},\n                        {\"localTimeFrom\": \"13:00\", \"localTimeTo\": \"14:30\"}],\n                \"fri\": [{\"localTimeFrom\": \"12:30\", \"localTimeTo\": \"15:00\"}],\n                \"default\": [{\"localTimeFrom\": \"10:00\", \"localTimeTo\": \"18:00\"}]\n            },\n            retryIntervalInMinutes: 120,\n            maxAttempts: 3\n         })\n    <span class=\"token variableParameter\">a:</span> ok</code></pre></div>\n<p class='tip'>For the recommended interval, both the <code class=\"language-text\">localTimeFrom</code> and <code class=\"language-text\">localTimeTo</code> bounds must be specified. If one of the boundaries is not specified, then an error is returned.</p>\n<p>In this example, the callback will be made on Monday from 10:00 to 11:30 and from 13:00 to 14:30, and on Friday from 12:30 to 15:00. Recommendations for others not explicitly specified days are specified in the <code class=\"language-text\">allowedTime</code> parameter with the <code class=\"language-text\">default</code> key.</p>\n</br>\n<p>If the <code class=\"language-text\">allowedDays</code> parameter is specified, the call can be made only on the day that is explicitly specified.</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">state:</span>\n    <span class=\"token storageType\">q!:</span> Сall back\n    <span class=\"token variableParameter\">script:</span>\n        $dialer.redial({\n            allowedDays: [\"sat\", \"sun\"],\n            allowedTime: {\n                \"fri\": [{\"localTimeFrom\": \"12:30\", \"localTimeTo\": \"15:00\"}],\n                \"default\": [{\"localTimeFrom\": \"10:00\", \"localTimeTo\": \"18:00\"}]\n            },\n             retryIntervalInMinutes: 120,\n            maxAttempts: 3\n         })\n    <span class=\"token variableParameter\">a:</span> ok</code></pre></div>\n<p>In this example, although the interval is explicitly specified for Friday in the <code class=\"language-text\">allowedTime</code> parameter, the call can only be made on Saturday or Sunday.</p>\n<p class='tip'>Please note that the recommended intervals within one day must be specified without intersections.</p>\n<p>Examples of intersections:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">\"mon\": [{\"localTimeFrom\": \"10:00\", \"localTimeTo\": \"13:30\"}, \n        {\"localTimeFrom\": \"13:00\", \"localTimeTo\": \"14:30\"}],\n\"tue\": [{\"localTimeFrom\": \"10:00\", \"localTimeTo\": \"18:30\"}, \n         {\"localTimeFrom\": \"13:00\", \"localTimeTo\": \"14:30\"}],</code></pre></div>\n</br>\n<p>If the <code class=\"language-text\">localTimeFrom</code> parameter is greater than <code class=\"language-text\">localTimeTo</code> in the specified interval, then the interval is considered to be correct. It starts on the specified day and ends the next day. The calls in the following example will be made from 8 p.m. Monday to 3 a.m. Tuesday:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">\"mon\": [{\"localTimeFrom\": \"20:00\", \"localTimeTo\": \"03:00\"}],</code></pre></div>\n</br>\n<p>Configure callback parameters based on the client’s reply. Use the <a href=\"/1.10.3/docs/en/NLU_core/slot_filling\"><code class=\"language-text\">$parseTree._Date.timestamp</code> filled slot</a> to define the call start date:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">state:</span> Call me back\n        <span class=\"token storageType\">intent!:</span> /Call me back\n        <span class=\"token variableParameter\">a:</span> Ok, I will call you back!\n        <span class=\"token variableParameter\">script:</span>\n            $dialer.redial({startDateTime: new Date($parseTree._Date.timestamp)})\n            $dialer.hangUp();</code></pre></div>\n</br>\n<p>Configure callback settings at the client’s request with additional parameters:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">state:</span> \n    <span class=\"token storageType\">q!:</span> call me back in a hour\n\t<span class=\"token variableParameter\">script:</span>\n\t   var redialTimeFrom = moment().add(60, \"m\").toDate();\n       var redialTimeTo = moment().add(75, \"m\").toDate();\n\t   $dialer.redial({\n          startDateTime: redialTimeFrom, finishDateTime: redialTimeTo,   <span class=\"token comment\">// call back in the interval of [now + 1h, now + 1h 15m]</span>\n          localTimeFrom: \"12:00 AM\", localTimeTo: \"12:00 AM\",                  <span class=\"token comment\">// ignore call time limits based on the customer’s time</span>\n          maxAttempts: 2,                                                <span class=\"token comment\">// make 2 calling attempts</span>\n          retryIntervalInMinutes: 5                                      <span class=\"token comment\">// with a 5 minute pause between them</span>\n       })\n\t<span class=\"token variableParameter\">a:</span> Ok, I will call you back in an hour</code></pre></div>\n</br>\n<p>You can only schedule one call in a conversation. For example, a client may ask the bot to call later. Calls to <code class=\"language-text\">$dialer.redial()</code> are ignored for subsequent client replies as callback parameters have already been set.</p>\n<p>Please note that <code class=\"language-text\">$dialer.redial()</code> parameters can be overridden if the bot did not reply. It can be done in <code class=\"language-text\">postProcess</code> or another state if a <code class=\"language-text\">go!</code> transition was made without a bot reply.</p>\n<p>You can schedule up to 5 callbacks per number for a single voice calling campaign from your script.</p>\n<p class='warn'><a href=/1.10.3/docs/en/telephony/call_policy  >Learn more about call priority and calling policy</a></p>\n<p>&#x3C;/br</p>\n<h3>Tagging the broadcast outcomes</h3>\n<p>By tagging broadcast outcomes in a script you can add user-defined metrics into the statistics.</p>\n<p class='warn'><a href=/1.10.3/docs/en/telephony/statistics  >More about statistics</a></p>\n<p class='warn'>The method <code class=\"language-text\">$dialer.setCallResult</code> allows tagging of the broadcasting outcomes for keeping extended statistics.</p>\n<p>For example, let us consider the following script:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">        <span class=\"token keyword\">state:</span> Yes\n            <span class=\"token storageType\">q:</span> Yes\n            <span class=\"token variableParameter\">a:</span> Thank you for your cooperation! Goodbye!\n            <span class=\"token variableParameter\">script:</span>\n                $dialer.setCallResult(\"YES\");\n                $dialer.hangUp();\n            \n        <span class=\"token keyword\">state:</span> No\n            <span class=\"token storageType\">q:</span> No\n            <span class=\"token variableParameter\">a:</span> I’m sorry to hear that you’re not interested. Goodbye!\n            <span class=\"token variableParameter\">script:</span>\n               $dialer.setCallResult(\"NO\");\n               $dialer.hangUp();\n            \n        <span class=\"token keyword\">state:</span> Maybe\n            <span class=\"token storageType\">q:</span> Maybe\n            <span class=\"token variableParameter\">a:</span> We will call you back later. Talk to you soon!\n            <span class=\"token variableParameter\">script:</span>\n                $dialer.setCallResult(\"MAYBE\");\n                $dialer.hangUp();</code></pre></div>\n<p>Now the broadcast outcome will be displayed in the table with the metrics when the script reaches the specific state: <code class=\"language-text\">YES</code>, <code class=\"language-text\">NO</code>, <code class=\"language-text\">MAYBE</code>.</p>\n<p>If extended metrics are not needed for the script, use methods that tag the outcomes about accepting or declining a proposal while not requiring the name to be filled in.</p>\n<p class='warn'>The methods <code class=\"language-text\">$dialer.setCallResultAccepted</code> and <code class=\"language-text\">$dialer.setCallResultRejected</code> make it possible to tag the outcome as <code class=\"language-text\">ACCEPTED</code> or <code class=\"language-text\">REJECTED</code>, respectively.</p>\n<p>Script:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">        <span class=\"token keyword\">state:</span> Yes\n            <span class=\"token storageType\">q:</span> Yes\n            <span class=\"token variableParameter\">a:</span> Thank you for your cooperation! Goodbye!\n            <span class=\"token variableParameter\">script:</span>\n                $dialer.setCallResultAccepted();\n                $dialer.hangUp();\n            \n        <span class=\"token keyword\">state:</span> No\n            <span class=\"token storageType\">q:</span> No\n            <span class=\"token variableParameter\">a:</span> I’m sorry to hear that you’re not interested. Goodbye!\n            <span class=\"token variableParameter\">script:</span>\n               $dialer.setCallResultRejected();\n               $dialer.hangUp();</code></pre></div>\n<p>In the table with the metrics the outcomes of the broadcast will be displayed as <code class=\"language-text\">ACCEPTED</code> and <code class=\"language-text\">REJECTED</code> when specific states are reached.</p>\n</br>\n<h3>Extending the broadcast report</h3>\n<p class='warn'>The method <code class=\"language-text\">$dialer.reportData($header, $value, $order)</code> makes it possible to add columns with arbitrary data to a <a href=/1.10.3/docs/en/telephony/statistics  >broadcast <code class=\"language-text\">.xls</code> report</a>.</p>\n<p>Method parameters:</p>\n<ul>\n<li><code class=\"language-text\">$header</code> (string) — the column name in the report;</li>\n<li><code class=\"language-text\">$value</code> (string) — the value;</li>\n<li><code class=\"language-text\">$order</code> (number) — the sorting order of the columns in the exported <code class=\"language-text\">.xls</code> report.</li>\n</ul>\n<p>The script developer may add columns into the report that are needed for a specific broadcast, for example:</p>\n<ol>\n<li>Retrieving data during a call:\n<ul>\n<li><code class=\"language-text\">$dialer.reportData(\"Full Name\", \"John Doe\")</code> — a <code class=\"language-text\">Full Name</code> column will be added to the broadcast outcome report, and the value <code class=\"language-text\">John Doe</code> will be inserted.</li>\n</ul>\n</li>\n<li>To log the phrase and the completion of a step:\n<ul>\n<li><code class=\"language-text\">$dialer.reportData(\"Step_Refused\", \"I don’t need it\")</code> — a <code class=\"language-text\">Step_Refused</code> column will be added to the broadcast outcome report and it will contain the phrase <code class=\"language-text\">I don’t need it</code>.</li>\n</ul>\n</li>\n</ol>\n<p>The <code class=\"language-text\">$order</code> parameter is optional and takes the default value of <code class=\"language-text\">0</code> if omitted. The columns in the report are arranged in descending order depending on the corresponding <code class=\"language-text\">$order</code> values, and if it is the same for multiple columns, these will be sorted alphabetically.</p>\n<p>Consider the following script:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">theme:</span> /\n\n    <span class=\"token keyword\">state:</span>\n        <span class=\"token storageType\">q!:</span> *start\n        <span class=\"token variableParameter\">a:</span> Hello! What is your name?\n\n        <span class=\"token keyword\">state:</span> Name\n            <span class=\"token storageType\">q:</span> *\n            <span class=\"token variableParameter\">a:</span> Hello, <span class=\"token constantCharacter\">{{$parseTree.text}}</span>!\n            <span class=\"token variableParameter\">script:</span>\n                $dialer.reportData(\"Name\", $parseTree.text);\n            <span class=\"token variableParameter\">a:</span> What do you think about smoking?\n\n            <span class=\"token keyword\">state:</span> Smoking\n                <span class=\"token storageType\">q:</span> *\n                <span class=\"token variableParameter\">a:</span> Okay, we’ll put it down as: \"<span class=\"token constantCharacter\">{{$parseTree.text}}</span>\".\n                <span class=\"token variableParameter\">script:</span>\n                    $dialer.reportData(\"Attitude to smoking\", $parseTree.text, 1);</code></pre></div>\n</br>\n<p>Here the <code class=\"language-text\">Attitude to smoking</code> column will be the first of the user-defined columns as its <code class=\"language-text\">$order</code> is <code class=\"language-text\">1</code>. The <code class=\"language-text\">Name</code> column will be placed second, because its <code class=\"language-text\">$order</code> is omitted and therefore equals <code class=\"language-text\">0</code>.</p>\n<p>In a more complex case, the columns will be sorted this way in accordance with their <code class=\"language-text\">$order</code> values:</p>\n<table>\n<thead>\n<tr>\n<th>Sex</th>\n<th>First Name</th>\n<th>Last Name</th>\n<th>Patronymic</th>\n<th>Attitude to smoking</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>-1</td>\n</tr>\n</tbody>\n</table>\n<p class='tip'>Please note that the number of columns in the broadcast report is limited. Ask your account administrator for details.</p>\n<h3>Retrieving call recordings</h3>\n<p>If the <a href=\"/1.10.3/docs/en/telephony/telephone_channel\">phone channel</a> has its <em>Record calls</em> parameter set to active, you can retrieve links to ongoing calls directly from the script using the <code class=\"language-text\">$dialer.getCallRecordingPath()</code> method.</p>\n<p>The method returns the relative path to the current call recording, such as the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">242829491/2019-06-18/79313365671/16:56:31.55-1P</code></pre></div>\n<p>The full path conforms to this template:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://{{host}}/restapi/download/{{projectId}}/recordings/call/{{callRecordingPath}}</code></pre></div>\n<p>Here,</p>\n<ul>\n<li><code class=\"language-text\">host</code> is the domain where the project is hosted, e.g. <code class=\"language-text\">app.jaicp.com</code>.</li>\n<li><code class=\"language-text\">projectId</code> is an integer project identifier, e.g. <code class=\"language-text\">242829491</code>.</li>\n<li><code class=\"language-text\">callRecordingPath</code> is the value returned by <code class=\"language-text\">$dialer.getCallRecordingPath</code>.</li>\n</ul>","frontmatter":{"title":"","description":null},"headings":[{"value":"Bot script for a voice broadcast"}]}},"pageContext":{"slug":"/docs/en/telephony/script_voice_bot/","previous":{"fields":{"slug":"/docs/en/telephony/sip_providers/"},"frontmatter":{"title":"","description":null}},"next":{"fields":{"slug":"/docs/en/telephony/recognition_synthesis_settings/"},"frontmatter":{"title":"","description":null}}}},
    "staticQueryHashes": ["1209419333"]}