Sometimes it is desired to steer the conversation in a different direction based the current date and/or time.
In below example we look at the current day as well as hour to determine whether the message came in during working hours. An example where this can be used is when wanting to handover to an agent. If the message came in outside of working hours you can let them know when contact ís possible, otherwise do the handover.
config:
conversationOwner: null
conversationOwners:
- identifier: conversationOwner
channel: WhatsApp
scriptLanguageVersion: 1
scriptVersion: 1
defaultDelay: 200
lists:
positive-answers:
items:
- Ja
negative-answers:
source: negative-answers.yml
flows:
- id: main
description: Entry flow for the bot
steps:
- !entry
id: Entry-1
actions: []
clientActions: []
matches:
- opening
allowRestart: true
isCaseSensitive: true
doCatchAll: true
- !var
id: Save current time and day
actions: []
clientActions: []
set:
hour: $GetNow("Europe/Amsterdam", "HH")
dayOfWeek: $GetNow("Europe/Amsterdam", "dddd")
- !logic
id: 'Business hours: yes or no'
actions: []
clientActions: []
entries:
- condition: !and
conditions:
- !regex
var: hour
tests:
- ^(0[8-9]|1[0-6])$
isCaseSensitive: false
- !regex
var: dayOfWeek
tests:
- (Monday|Tuesday|Wednesday|Thursday|Friday)
isCaseSensitive: false
position:
cursor: inside business hours.Text-1
- condition: !default {}
position:
cursor: outside business hours.Text-1
- id: inside business hours
description: ''
steps:
- !text
id: Text-1
actions: []
clientActions: []
message: You have messaged us within our business hours.
- id: outside business hours
description: ''
steps:
- !text
id: Text-1
actions: []
clientActions: []
message: You have messaged us outside of our business hours.
In here we use the $GetNow
system functions as described in Variables.
Previous: examples Intro