Using conditions

You can define a condition in your request handling by using Python. The request will only be sent out if the condition is met.

The condition can be, for example:

  • language restriction: POST request will only be sent if the conversation's language is either Finnish or English

    
    {
       "request": {
          "method": "POST",
          "condition": "contact.get_language().lower() in ('en', 'fi')"
       }
    }
  • prevent PUT request from being sent if the conversation has been created less than ten minutes ago

    
    {
       "request": {
          "method": "PUT",
          "condition": "contact.get_seconds_since_created() >= 600"
       }
    }
  • send a GET request randomly

    
    {
       "request": {
          "method": "GET",
          "condition": "random.randrange(1, 10000) % 2 == 0"
       }
    }
Table 1. Functions, modules, and objects available for use in conditions
Item Type Description Examples
contact object Real-time contact data See table Referring to contact and event data in conditional request configuration below.
event object Real-time event data See table Referring to contact and event data in conditional request configuration below.
builtins various Set of basic functions and types See Python's built-in functions (3.12)
datetime module Basic date and time types See Python's datetime module (3.12)
random module Generate pseudo-random numbers See Python's random module (3.12)
re module Regular expression operations See Python's re module (3.12)
time module Time access and conversions See Python's time module (3.12)
Table 2. Referring to contact and event data in conditional request configuration
Property Python data type Syntax Examples
Channel type str contact.get_channel_type()
If the conversation uses the chat channel:
contact.get_channel_type() == 'chat'
Channel subtype str | None contact.get_channel_sub_type()
If the conversation's channel subtype is other than SMS:
contact.get_channel_sub_type() != 'sms'
Direction str contact.get_direction()
If the conversation is inbound:
contact.get_direction() == 'inbound'
Note: It's recommended to select the direction in the configuration rather than define it in a condition.
ID str contact.get_id() -
Monitoring / reporting ID str contact.get_guid() -
Creation timestamp str contact.get_created()
If the conversation was created during certain UTC hours:
contact.get_created()[11:13] in ('09', '12', '15')
Seconds elapsed since the contact was created float contact.get_seconds_since_created()
If the conversation's lifetime (at the time of the triggering event) is longer or equal to one minute:
contact.get_seconds_since_created() >= 60
Language str contact.get_language()
If the conversation's language is either English or Finnish:
contact.get_language().lower() in ('en', 'fi')
Priority int contact.get_priority()
If the conversation's priority value is less than or equal to 100:
contact.get_priority() <= 100
Skills list | None contact.get_skills()
If the conversation has no skill requirements:
contact.get_skills() is None
If the conversation has at least one skill requirement:
contact.get_skills() is not None
If the conversation has two or more skill requirements, taking into account that the conversation's skills may be None:
len(contact.get_skills or []) >= 2

If the conversation has one or more skill requirements of level 4 or higher:

(cs := contact.get_skills()) is not None and max([s['value'] for s in cs]) >= 4
If the conversation has a skill requirement named English:
'English' in (s.get('name') for s in (contact.get_skills() or []))
Current queue dict | None contact.get_queue()
If the conversation has no current queue set:
contact.get_queue() is None
If the conversation has a current queue set:
contact.get_queue() is not None
If the conversation's current queue extension address equals chat.queue.fi@acme.com, taking into account that the conversation's current queue may be None:
(contact.get_queue() or {}).get('address') == 'chat.queue.fi@acme.com'
Forwarding queue dict | None contact.get_forwarding_queue()
If the conversation has no forwarding queue set:
contact.get_forwarding_queue() is None
If the conversation has a forwarding queue set:
contact.get_forwarding_queue() is not None

If the conversation has been forwarded from queue address chat.queue.fi@acme.com, taking into account that the conversation's forwarding queue may be None:

(contact.get_forwarding_queue() or {}).get('address') == 'chat.queue.fi@acme.com'
Current agent dict | None contact.get_agent()
If the conversation has no current agent set:
contact.get_agent() is None
If the conversation has current agent set:
contact.get_agent() is not None
If the conversation has a current agent with chat address agent@acme.com:
(contact.get_agent() or {}).get('chat_address') == 'agent@acme.com'
Preferred agent dict | None contact.get_preferred_agent() See Current agent above.
Required agents list | None contact.get_required_agents()
If the conversation has no required agents set:
contact.get_required_agents() is None
If the conversation has at least one required agent set:
contact.get_required_agents() is not None
If the conversation has two or more required agents set, taking into account that the conversation's required agents may be None:
len(contact.get_required_agents() or []) >= 2

If the conversation has an agent with chat address agent@acme.com set as one of the required agents, taking into account that the conversation's required agent may be None:

'agent@acme.com' in (a.get('chat_address') for a in (contact.get_required_agents() or []))
Transferring agent dict | None contact.get_transferring_agent() See Current agent above.
Source str contact.get_source_address()
If the conversation has originated from a Finnish phone number:
contact.get_source_address().startswith('+358')
Destination str contact.get_destination_address()

If the conversation is arriving to queue address chat.queue.en@acme.com or chat.queue.fi@acme.com:

contact.get_destination_address() in ('chat.queue.en@acme.com', 'chat.queue.fi@acme.com')
External destination str contact.get_external_destination_address()

If the call has been forwarded or transferred to a PSTN number registered to the Uusimaa region in Finland, taking into account that the conversation's external destination address may be None:

(contact.get_external_destination_address() or '').startswith('+3589', '09')
CAD dict | None contact.get_attached_data()

If the conversation has the same value in key my-string-key as in string my-string-value on root level of CAD, taking into account that CAD could be None:

(contact.get_attached_data() or {}).get('my-string-key') == 'my-string-value'

If the conversation has the value of key my-numeric-value greater than 100, taking into account that the value is expected to be stored in CAD under path record/fields and that either the whole CAD or one/all of the sub-levels of the CAD could be None:

(contact.get_attached_data() or {}).get('record', {}).get('fields', {}).get('my-numeric-value', 0) > 100
Note: For emails, the system converts the saved CAD values to string. This means you cannot later refer to the values inside a JSON object or an array. To use an individual CAD value either in a further condition or as a data placeholder in another event-driven JSON configuration, place it directly under the save configuration.
Case ID

str | None

(can be None only for conversations from other channels than email)

contact.get_case_id()

If the email conversation has a case ID that is an even number:

int(contact.get_case_id() or '1') % 2 == 0
To addresses list | None contact.get_to_addresses()

If the email conversation has multiple To addresses:

len(contact.get_to_addresses() or []) > 1

If the email conversation has address email.queue@acme.com in its list of To addresses:

'email.queue@acme.com' in (contact.get_to_addresses() or [])
Cc addresses list | None contact.get_cc_addresses()

See To addresses.

Subject str | None contact.get_subject()

If the email conversation has a subject indicating that it is a reply message (in English or Finnish):

(contact.get_subject() or '').lower()[:3] in ('re:', 'vs:')
Body str | None contact.get_body()

If the email conversation either has no body text or body text that is a maximum of 500 characters:

(body := contact.get_body()) is None or len(body) <= 500
Event type name str event.type If the conversation uses the chat channel and has event allocated or rejected:
event.type not in ('allocated', 'rejected') or contact.get_channel_type() == 'chat'
Note: It's recommended to select the event(s) in the configuration rather than define them in a condition.
Event timestamp float event.timestamp
If the event occurs within the specified UTC hour range (08-16):
8 <= datetime.datetime.fromtimestamp(event.timestamp).hour <= 16
If the event occurs on even minutes:
datetime.datetime.fromtimestamp(event.timestamp).minute % 2 == 0