Skip to main content

$textCampaign.postponeClient

This method allows postponing a message sent to a client during a text campaign depending on some condition set in the script.

Syntax

$textCampaign.postponeClient(5400);
$textCampaign.postponeClient("1h 30m");

The method accepts one argument, interval — the time interval for which the message should be postponed.

Interval format

The value of interval can be either a number or a string.

  • As a number, it means the timeout duration in seconds.
  • As a string, it signifies the timeout duration in human-readable format.

An interval cannot exceed 99 hours.

String values of interval must be matched by the following regular expression:

(\s*(?<h>\d{0,2})\s*(hours|hour|h))?(\s*(?<m>\d{0,2})\s*(minutes|minute|min|m))?(\s*(?<s>\d{0,2})\s*(seconds|second|sec|s))?\s*
Examples of interval string values
  • 5 seconds
  • 1 sec
  • 3s
  • 1 min
  • 1 minute
  • 10 minutes
  • 1 hour
  • 10 hours
  • 3 min 1 sec
  • 1h5m3s

How to use

Let’s assume you want to send a text campaign in a way that it reaches your clients during working hours. You cannot achieve this using the JAICP interface alone, because clients may be located in different time zones.

You can develop the script in a way to include the necessary business logic:

  1. As part of your script, make the bot always ask and remember the client’s country or city of residence.
  2. Add a current time check to the text campaign event handler.
  3. If the time is outside working hours, call $textCampaign.postponeClient to schedule resending the message.

A message can be postponed up to 10 times for one client. After this point, JAICP will no longer send messages to this client and record an error in the campaign report.

How postponed messages are displayed in the interface
Campaign card. The campaign progress bar is along the bottom-hand border and is divided into two segments, green and blue, corresponding to messages that have been sent to clients and postponed respectively.
# Here, we import the cities dictionary from the zb-common system project.
require: city/cityEn.sc
module = sys.zb-common

# Here we import the Moment.js library.
require: dateTime/moment.min.js
module = sys.zb-common

theme: /

# The script branch where the bot learns the client’s city.
state: Start || modal = true
q!: $regex</start>
a: Hi! Could you please tell me which city you live in?

state: GetCity
q: * $City *
script: $client.city = $parseTree._City;
a: Thank you! Now I’m at your service.
go: /

state: CatchAll || noContext = true
event: noMatch
a: Sorry, but I won’t be able to function properly without knowing where you live.

# The state for handling the event triggered by the campaign launch.
state: Promo
event!: promoEvent
script:
var currentTime = $jsapi.timeForZone($client.city.timezone);
$temp.currentHour = moment(currentTime).hours();
if: $temp.currentHour >= 21 || $temp.currentHour <= 9
script: $textCampaign.postponeClient("1 hour");
go: /
else:
a: A 10% discount on all items if you register a bonus card! Are you interested?

# States for continuing the conversation…