Skip to main content

Script setup

This article is part of a tutorial about creating an outbound call campaign using NLU.

  1. Telephony setup
  2. Script setup (you are here)
  3. Campaign launch
  4. Analytics
  5. Additional features
  6. Testing

During this stage we will set up the bot script. We will utilize various $dialer methods in the bot script extensions for telephony management, and we will be using the NLU core for natural language understanding.

Configuration file

Go to the Editor and create a standard chatbot.yaml configuration file for NLU projects:

name: call-campaign
entryPoint: main.sc

botEngine: v2
language: en

nlp:
intentNoMatchThresholds:
phrases: 0.2
patterns: 0.2

The main script

Create the src/main.sc file and put the main script mechanics into the theme tag:

theme: /

state: Start
q!: $regex</start>
script:
$jsapi.startSession();
$session.userName = $dialer.getPayload().name || "stranger";
$dialer.setCallResult("Greeting");

a: Hello, {{$session.userName}}!
a: Due to the COVID-19 pandemic, the world government is concerned for your safety.
go!: /Symptoms

state: Symptoms
a: Have you recently found yourself with a fever, a dry cough, or a rapid tiredness?

state: Positive
intent: /Agree
intent: /Sick
a: Then do not put yourself in danger! Seek medical attention immediately!
script:
$dialer.reportData("Case", "Positive");
$dialer.setCallResult("Known case");
go!: /Goodbye

state: Negative
intent: /Disagree
intent: /Healthy
a: Good to hear everything is fine! Still, do not forget to wash your hands and wear face masks.
script:
$dialer.reportData("Case", "Negative");
$dialer.setCallResult("Known case");
go!: /Goodbye

state: Unrecognized
event!: noMatch
a: So you say: {{$parseTree.text}}. Remember about proper hygiene and wearing face masks.
script:
$dialer.reportData("Case", $parseTree.text);
$dialer.setCallResult("Known case");
go!: /Goodbye

state: Goodbye
event!: hangup
a: Goodbye and stay safe!
script:
$dialer.hangUp();

state: NoInput || noContext = true
event!: speechNotRecognized
script:
$session.noInputCounter = $session.noInputCounter || 0;
$session.noInputCounter++;
if: $session.noInputCounter >= 3
a: I’m sorry, there’s something wrong with the connection.
script:
$dialer.setCallResult("Bad connection");
go!: /Goodbye
else:
a: I didn’t catch that. Could you repeat, please?

Also create the test/test.xml file, but leave it empty for now:

<test>
<test-case/>
</test>

Dialog start

When the bot reaches out to the client, it receives a /start command, which can be processed with a pattern for regular expressions. The handler for this activator does the following:

  1. Marks the session as new and cleans previously stored session data.
  2. Extracts the client name from the phone number list and stores it in the session data.
  3. Sets the appropriate call result.

If no client name is provided, a neutral form of address is used instead.

state: Start
q!: $regex</start>
script:
$jsapi.startSession();
$session.userName = $dialer.getPayload().name || "stranger";
$dialer.setCallResult("Greeting");

a: Hello, {{$session.userName}}!
a: Due to the COVID-19 pandemic, the world government is concerned for your safety.
go!: /Symptoms

Reporting the client response

The states nested into the Symptoms parent state handle different replies to the question about the client’s well-being, whether it be positive, negative, or unrecognized. In each case, the bot records the reply to the campaign report under the Case column. Unrecognized responses are recorded as is.

state: Symptoms
a: Have you recently found yourself with a fever, a dry cough, or a rapid tiredness?

state: Positive
intent: /Agree
intent: /Sick
a: Then do not put yourself in danger! Seek medical attention immediately!
script:
$dialer.reportData("Case", "Positive");
$dialer.setCallResult("Known case");
go!: /Goodbye

state: Negative
intent: /Disagree
intent: /Healthy
a: Good to hear everything is fine! Still, do not forget to wash your hands and wear face masks.
script:
$dialer.reportData("Case", "Negative");
$dialer.setCallResult("Known case");
go!: /Goodbye

state: Unrecognized
event!: noMatch
a: So you say: {{$parseTree.text}}. Remember about proper hygiene and wearing face masks.
script:
$dialer.reportData("Case", $parseTree.text);
$dialer.setCallResult("Known case");
go!: /Goodbye
tip
Learn more about $dialer.reportData

Dialog end

During the last step, the bot says goodbye and ends the call.

state: Goodbye
event!: hangup
a: Goodbye and stay safe!
script:
$dialer.hangUp();
caution
The bot will also transition to this state if the client hangs up without replying to the question. In this case, the call result and the information on their health will not be updated.

Unrecognized speech handling

The NoInput technical state handles situations when no response from the client can be recognized. If the number of transitions to this state becomes greater than the threshold, the bot ends the call.

state: NoInput || noContext = true
event!: speechNotRecognized
script:
$session.noInputCounter = $session.noInputCounter || 0;
$session.noInputCounter++;
if: $session.noInputCounter >= 3
a: I’m sorry, there’s something wrong with the connection.
script:
$dialer.setCallResult("Bad connection");
go!: /Goodbye
else:
a: I didn’t catch that. Could you repeat, please?
caution
All telephony bots should contain some speechNotRecognized event handler and impose a limit on unrecognized requests per session, so that ineffective calls finish quickly without spending excessive call minutes.
tip
hangup and speechNotRecognized are examples of telephony system events.

Intent setup

Go to NLU > Intents and create the intents used in the script: /Agree, /Disagree, /Healthy, and /Sick. Fill them with training phrases conveying the appropriate meanings:

AgreeyesyeahI haveyep
DisagreenoI don’tno needI don’t have anything
Healthyeverything is finewe are all okayI’m fit as a fiddlethere is no problem
SickI’m sickquite feverish, yesI have COVIDI really am tired

Training phrases for the /Healthy intent

After filling up the intents, press the Test button in order to train the classifier.

Now everything is ready for you to create and launch your first campaign.