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. You can add comments to your conditions by using the # character.

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 #Sends the request when a pseudo-random integer from range 1..10000 is an even number"
       }
    }
    Note: This includes a comment after the # character.
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)
json module JSON encoder and decoder See Python's json 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
Supported for email only
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
Supported only for campaign calls
Outbound campaign ID str | None contact.get_campaign_id() If the campaign call is related to campaign with ID A2497527E637480F8F698CCAC40EFD4C:
contact.get_campaign_id() == 'A2497527E637480F8F698CCAC40EFD4C'
Outbound campaign customer ID str | None contact.get_campaign_customer_id() If the campaign call is related to customer with ID FD39EABEC7804148AB80CC5BE3028E26:
contact.get_campaign_customer_id() == 'FD39EABEC7804148AB80CC5BE3028E26'
Outbound campaign classifier ID str | None

(can be None only when classification is not done by an agent from a call result list)

contact.get_campaign_classifier_id() If the campaign call has been classified using classifier with ID A5EB6A0B8B38EB11AA47027E1B397C3D:
contact.get_campaign_classifier_id() ==
            'A5EB6A0B8B38EB11AA47027E1B397C3D'
Outbound campaign classifier str | None

(can be None only when classification is not done by an agent from a call result list or not defined in IVR configuration)

contact.get_campaign_classifier() If the campaign call has been classified using a classifier whose text value is not Busy or No Answer:
contact.get_campaign_classifier() not in ('Busy', 'No Answer')
Outbound campaign call result str | None contact.get_campaign_call_result() If the campaign call has been classified using a classifier whose technical call result value is WRONG_PERSON or WRONG_NUMBER:
contact.get_campaign_call_result() in ('WRONG_PERSON', 'WRONG_NUMBER')
Outbound campaign customer result str | None contact.get_campaign_result() If the campaign call's technical customer result value is CALL or REDIAL:
contact.get_campaign_result() in ('CALL', 'REDIAL')
Outbound campaign dialer type str | None contact.get_campaign_dialer_type() If the campaign call's campaign uses dialer type QueueDialer:
contact.get_campaign_dialer_type() == 'QueueDialer'
Outbound campaign dialing mode str | None contact.get_campaign_dialing_mode() If the campaign call's campaign uses dialing mode Preview or Predictive:
contact.get_campaign_dialing_mode() in ('Preview', 'Predictive')
Event data
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
Table 3. Queue status data
Note: The value can only be None if the contact object is not related to an inbound queue.
Description Python data type Syntax

Returns True if the queue is available, False otherwise

An available queue:
  • is open according to its service times
  • is not full
  • has serving agents
  • does not use instant forwarding if it's a phone queue
bool | None

queue.is_available()

For example, to check if the queue is available:

queue.is_available() is True

Returns True if the queue is open according to its service times, False otherwise

bool | None

queue.is_open()

For example, to check if the queue is closed:

queue.is_open() is False
Returns the number of contacts in the queue, including contacts accepted by agents int | None

queue.get_num_contacts_all()

For example, to check if the number is greater than 50:

queue.get_num_contacts_all() > 50
Returns the number of contacts per agent in the queue, including contacts accepted by agents float | None

queue.get_num_contacts_all_per_agent()

For example, to check if the number is greater than 1:

queue.get_num_contacts_all_per_agent() > 1
Returns the number of contacts in the queue, excluding contacts accepted by agents int | None

queue.get_num_contacts_waiting()

For example, to check if the number is greater than or equal to 10:

queue.get_num_contacts_waiting() >= 10
Returns the number of contacts per agent in the queue, excluding contacts accepted by agents float | None

queue.get_num_contacts_waiting_per_agent()

For example, to check if the number is greater than or equal to 5:

queue.get_num_contacts_waiting_per_agent() >= 5
Returns the total number of agents serving in the queue, regardless of status int | None

queue.get_num_agents_all()

For example, to check if the number is equal to 0:

queue.get_num_agents_all() == 0
Returns the number of agents serving in the queue with Waiting status int | None

queue.get_num_agents_waiting()

For example, to check if the number is less than 5:

queue.get_num_agents_waiting() < 5

Returns the number of agents serving in the queue with Talking status

For phone queues only. For other queue types, this is expected to always return 0.

int | None

queue.get_num_agents_talking()

For example, to check if the number is equal to 0:

queue.get_num_agents_talking() == 0
Returns the number of agents serving in the queue with Not ready status int | None

queue.get_num_agents_not_ready()

For example, to check if the number is not equal to 0:

queue.get_num_agents_not_ready() != 0

Returns the number of agents serving in the queue with Paused status

An agent is Paused when their profile is of type Absence.

int | None

queue.get_num_agents_paused()

For example, to check if the number is greater than 5:

queue.get_num_agents_paused() > 5
Returns the maximum current contact waiting time (in seconds) for the queue int | None

queue.get_contact_wait_time_max()

For example, to check if the number is greater than 600:

queue.get_contact_wait_time_max() > 600
Returns the average current contact waiting time (in seconds) for the queue int | None

queue.get_contact_wait_time_avg()

For example, to check if the number is greater than 300:

queue.get_contact_wait_time_avg() > 300
Returns the estimated current contact waiting time (in seconds) for the queue int | None

queue.get_contact_wait_time_est()

For example, to check if the number is greater than 200:

queue.get_contact_wait_time_est() > 200