Built-in scripting functions
Review
Functions are used as arguments by script components. They allow you to calculate specific values and even perform operations on the system.
Functions are divided into:
-
pure – the return value depends only on the parameters.
-
with site effects - the return value may vary depending on the state of the system.
-
modifiers – makes changes to the system.
Components constantly use arguments,
arguments can be represented as expressions, expressions can use functions.
Function Categories
| Category | Description |
|---|---|
Pure mathematical functions. |
|
Pure functions for working with strings. |
|
Pure functions for working with dates and times and side-effect functions for accessing the current time. |
|
Pure functions for value conversion, encoding, packaging, presentation. |
|
Pure hash functions. |
|
Pure functions for working with file paths and directory categories. |
|
Various functions for bidirectional access to context and state. |
|
Side-effect functions for special access to variables. |
|
Side-effect functions for obtaining data from the system configuration. |
|
Pure constant substitution functions. |
|
Pure character substitution functions. |
|
Side-effect functions for accessing call data and queue state modifiers. |
Function directory
| Function | Options | Description |
|---|---|---|
|
|
Sine of a number |
|
|
Cosine of a number |
|
|
Tangent of a number |
|
|
Arcsine of numbers |
|
|
Arc cosine of a number |
|
|
Arctangent of a number |
|
|
Arctangent of the quotient of two numbers |
|
|
Hyperbolic sine of a number |
|
|
Hyperbolic cosine of a number |
|
|
Hyperbolic tangent of a number |
|
|
Exponent of a number |
|
|
Natural logarithm of a number |
|
|
Binary logarithm of a number |
|
|
Decimal logarithm of a number |
|
|
The result of raising one number to the power of another |
|
|
Square root of a number |
|
|
Error function: Not available on Windows |
|
|
Not available on Windows |
|
|
The maximum of two numbers |
|
|
Minimum of two numbers |
|
|
The result of discarding the fractional part of a number |
|
|
The result of rounding a number to an integer |
|
|
Absolute value of a number |
|
|
Closest integer from below |
|
|
Closest integer from above |
|
|
Decimal logarithm of a number |
|
|
Natural logarithm of a number |
|
|
Logarithm of one number to the base of another |
|
|
Number square |
|
Random decimal number from |
|
|
|
Random integer from 0 to a specified integer |
|
|
Random integer in the range between two integers |
| Function | Options | Description |
|---|---|---|
|
Returns the generated UUID. |
|
|
|
Returns the length of a string in characters. |
|
|
Returns the result of concatenating two strings. |
|
|
Result of comparing two strings: |
|
|
Returns the index of the position of the first occurrence of the substring (n2) in the string (n1). Returns |
|
|
Returns the position index of the last occurrence of the substring (n2) in the string (n1). Returns |
|
|
Returns a substring from the specified position (n2) to the end. |
|
|
Returns a substring from the specified position (n2) of no more than the specified length (n3). |
|
|
Returns the result of replacing the occurrence of (n2) in the string (n1) with the value (n3). |
|
|
Returns a lowercase string. |
|
|
Returns an uppercase string. |
|
|
Returns a string after removing a substring from the specified position (n2) to the end. |
|
|
Returns a string after removing a substring from the specified position (n2) of the specified length (n3). |
|
|
Returns the index of the position of the first occurrence of the substring (n2) in the string (n1). Returns |
|
|
Returns the index of the position of the first occurrence of the substring (n2) in the string (n1), starting at the specified position (n3). Returns |
|
|
Returns a string stripped of leading and trailing empty characters (space, tab, etc.). |
|
|
Returns a string stripped of leading blank characters (space, tab, etc.). |
|
|
Returns a string stripped of trailing empty characters (space, tab, etc.). |
|
|
Returns a string stripped of leading blank characters (space, tab, etc.). |
|
|
Returns a string stripped of trailing empty characters (space, tab, etc.). |
|
|
Returns the left side of a string no greater than the specified length. |
|
|
Returns the right side of a string no greater than the specified length. |
|
|
Returns the reversed string. |
|
|
Returns the result of a replacement using a regular expression. p1 - value, p2 - pattern, p3 - replacement. |
|
|
Returns the result of a replacement using a regular expression with the |
|
|
Returns the modified json structure. Applies the search query (p1) to the value (p2), modifies the detected element according to the options (p3) and returns the overall result. Example:
modify_json(
"chat/0/msgs",
'{"chat":[{"msgs":[{"txt":"abc"}]}]}',
'{"action":"append","value":{"txt":"zcv"}}'
)
Options are presented as a json object with a required key
|
| Function | Options | Description |
|---|---|---|
|
Returns a number representing the absolute value in milliseconds since 1970. |
|
|
Returns the current date and time in the server’s local time zone in RFC3339 format. For example, |
|
|
Returns the current date and time in UTC in RFC3339 format. |
|
|
Returns the number of seconds according to the Gregorian calendar, since 0 AD. |
|
|
|
Returns the date in the server’s local time zone based on the absolute value of tick. |
|
|
Returns the date in UTC based on the absolute value of tick. |
|
|
Converts date to unix timestamp |
|
|
Returns a string representing the date (n2) in the specified format (n1). For example: Possible format string placeholders: |
|
Returns the current date in the server’s local time zone, without specifying the time zone. Format |
|
|
|
Returns a date from a specified date/time. |
|
Returns the current time in the server’s local time zone, without specifying a time zone. Format |
|
|
|
Returns the time from the specified date/time. |
|
|
Returns a date/time generated from a string. The string can contain various date/time representations, including RFC3339. |
|
|
Returns date/time based on the passed p1 - year, p2 - month, p3 - day. |
|
|
Returns date/time based on the passed p1 - year, p2 - month, p3 - day, p4 - hour, p5 - minute. |
|
|
Returns date/time based on the passed n1 - year, n2 - month, n3 - day, n4 - hour, n5 - minutes, n6 - seconds. |
|
|
Returns date/time based on the passed n1 - year, n2 - month, n3 - day, n4 - hour, n5 - minutes, n6 - seconds, n7 - milliseconds. |
|
|
Returns the number of specified time units between two dates. The parameter is specified as an atom (not a string), for example Possible types of units in descending order: |
|
|
Returns the date after adding the specified number (n2) of the specified time units (n1) to the specified date/time (n3). The parameter is specified as an atom (not a string), for example Possible types of units in descending order: |
|
|
Returns the current year of the specified date/time. |
|
|
Returns the current month ( |
|
|
Returns the current day ( |
|
|
Returns the current hour ( |
|
|
Returns the current minute ( |
|
|
Returns the current second ( |
|
|
Returns the current millisecond ( |
|
|
Returns the number of the day in the year for the specified date/time. |
|
|
Returns the day of the week number ( |
|
|
Returns the week number in the year for the specified date/time. |
|
|
Returns |
|
|
Returns the date/time adjusted to the server’s local time zone. Numerical date/time values do not change, but the absolute time point can be shifted after changing the time zone to local. |
|
|
Returns the date/time normalized to UTC. Numerical date/time values do not change, but the absolute time point can be shifted after changing the time zone to zero. |
|
|
Returns the UTC date/time for the specified date/time, considered in the server’s local time zone. |
|
|
Returns the local date/time for the specified date/time, treated as UTC. |
|
|
Returns |
| Function | Options | Description |
|---|---|---|
|
|
Returns a string with a single character based on its Unicode code. |
|
|
Converts a numeric value to a string. |
|
|
Converts a string to a number. If it fails, it exits with an error. |
|
|
Converts a string to a number, cutting off inappropriate characters from the end. In the limit it returns |
|
|
Returns a string with the HEX representation of a number. |
|
|
Returns a number based on its HEX representation. |
|
|
Returns the string resulting from packing into Base64 representation. |
|
|
Returns the string resulting from decompression from a Base-64 representation. |
|
|
Returns a string encoded with UrlEncode. |
|
|
Returns a string encoded using UrlEncode. |
|
|
Returns a string encoded using Unicode Hex Character Code. |
|
|
Returns a string decoded using Unicode Hex Character Code |
|
|
Returns the string resulting from the escape sequence conversion. Used for inserting into JSON. |
|
|
Returns the string resulting from unpacking from the escape sequence. Used to clean up after JSON. |
|
|
Returns the result of the string transliteration. |
|
|
If the value of the first parameter is |
| Function | Options | Description |
|---|---|---|
|
|
Returns a hash of a string encoded in UTF-8 using the MD5 algorithm. |
|
|
Returns a hash of any value using the CRC32 algorithm (IEEE 802.3). |
|
|
Returns a new hash value from the previous value combined with a new chunk. n1 is the previous hash value, n2 is a new piece of data. According to the CRC32 algorithm (IEEE 802.3). |
|
|
Returns a hash of any value using the Adler-32 algorithm. |
|
|
Returns a new hash value from the previous value combined with a new chunk. n1 is the previous hash value, n2 is a new piece of data. According to the Adler-32 algorithm. |
|
|
Returns the hash sum of any value using an internal algorithm. |
| Function | Options | Description |
|---|---|---|
|
|
Returns the path type (the category prefix from the specified path). |
|
|
Returns the relative path (the specified path without the category prefix). |
|
|
Returns the filename extracted from the specified path. |
|
|
Returns the file extension extracted from the specified path. |
|
|
Returns the name of the directory. For a file path, this is the name of the directory; for a directory path, this is the name of the parent directory. |
|
|
Returns the path formed by concatenating two parts. |
|
|
Returns a path formed by concatenating three parts: path, filename, and file extension. |
|
Returns |
|
|
Returns |
|
|
||
|
Returns |
|
|
Returns |
|
|
Returns |
|
|
Returns |
|
|
Returns |
|
|
Returns |
|
|
Returns |
|
|
Returns |
|
|
Returns |
| Function | Options | Description |
|---|---|---|
|
|
Returns the value of the input parameter at the specified index. Scripts can accept up to 20 input parameters. |
|
Returns a string containing the ID of the current scripting engine. Other script handlers can send messages to the handler using this identifier, for example using the Script Interaction component. |
|
|
Returns a string containing the project ID of the currently running script. |
|
|
|
|
|
|
|
|
|
Executes a component of the specified type from a group of service script components. The first parameter is the component type (numeric number or key from the module name, for example 103 or pause), the second parameter is the component properties from the documentation, with the exception of transition branches and variables for output values (can be erlang:map() or erlang:proplist() or binary() with JSON). Returns an object with the keys of the fields of the output variables and additionally "transferKey", the format of the return value matches the format of the second parameter. |
|
|
Executes a component of the specified type from a group of service script components. The first parameter is the component type (a numeric number or a key from the module name, for example 103 or pause). The second parameter is the component properties from the documentation, excluding transition branches and variables for output values (can be erlang:map() or erlang:proplist() or binary() with JSON). The third parameter sets the format of the return value (map, proplist, json). Another third parameter can order a value for a specific key to be returned from the result (for example, to return a value typically stored in a component’s output variable). Also, the third parameter can set the mode of returning a string concatenated from the transferKey and varValue values (format "TransferKeyValue;OtherKeyValue"), for this you need to set the third parameter without quotes: "{transfer,Key}". Returns an object with the keys of the output variable fields and additionally "transferKey", or the value for a specific key from this object. Examples: ---- component(notify, #{mode ⇒ 0, text ⇒ [a1], user ⇒ <<"admin">>}, map) component(111, #{<<"mode">> ⇒ 0, <<"text">> ⇒ <<"Something">>, <<"user">> ⇒ <<"admin">>}, json) component(111, <<"\"mode\": 0, \"text\": \"Something\", \"user\": \"admin\"">>, <<"transferKey">>) component(parser, #{algoritm ⇒ 0, functionJSON ⇒ 0, data ⇒ <<"{\\\"a\\\":\\\"value\\\"}">>, query ⇒ <<"a">>}, {transfer,<<"resultVariable">>}) ---- Component codes and fields are available in the documentation on the corresponding component pages. One possible way is to set up a new script with a component that has the settings of interest, and copy its contents from the JSON script. |
|
|
Waits for and blocks the critical section (analogous to the Mutex component). The first parameter is the unique name of the critical section. The second parameter is the waiting time in milliseconds before the timeout. Returns "ok", "timeout", "error". |
|
|
Waits for and blocks the critical section (analogous to the Mutex component). The first parameter is the unique name of the critical section. The second parameter is the waiting time in milliseconds before the timeout. The third parameter is the type of operation under lock (1 or read - reading, 2 or write - writing). The fourth parameter is the time in milliseconds after which the critical section will be automatically released. Returns "ok", "timeout", "error". |
|
|
Releases the critical section (analogous to the Mutex component). Returns "ok" or "error". |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Function | Options | Description |
|---|---|---|
|
|
Returns |
|
|
Returns the value of a variable by its name. |
|
|
Returns the value of a variable by its name, and if the value is not set, then the default value from the second parameter. |
|
|
Returns a string with a variable identifier by its name. |
|
|
Returns the value of a variable by its name, and if the value is a string, then it is returned in the original encoding without conversion. |
|
|
Sets the value of a variable by its name if its value is not specified. Returns the value of a variable as a result of an operation. |
|
|
Returns the value of a variable by its name. |
|
|
Extends or places in the data storage on the site the value (2nd parameter) by key (1st parameter) for 2 days. Returns "ok". If the storage is unavailable, returns "error". |
|
|
Extends or places in the data storage on the site the value (2nd parameter) by key (1st parameter) for the specified number of seconds (3rd parameter). Returns "ok". If the storage is unavailable, returns "error". |
|
|
Returns the value by key from the data store on the site, or the default value if there is none. If the storage is unavailable, returns "error". |
|
|
Removes the value for the specified key from the data store on the site. If the storage is unavailable, returns "error". |
| Reading and modifying an existing value in the store when working in parallel mode should be done in a critical section, for example, built by the "Mutex" component or the lock/unlock expression functions. |
| Function | Options | Description |
|---|---|---|
|
Returns the URL of the closest available server with the logical role ws. |
|
|
Returns the site on which the script is executed. |
|
|
Returns the domain in which the script is running. |
|
|
Returns the parent domain of the one in which the script is running. |
|
|
Returns |
|
|
|
Returns In |
| Function | Options | Description |
|---|---|---|
|
Returns the number |
|
|
Returns the number |
|
|
Returns the number |
| Function | Options | Description |
|---|---|---|
|
Returns a string with a tab character. |
|
|
Returns a string with a line terminator. |
|
|
Returns a string with a quote character. |
|
|
Returns a string with a double quote character. |
| Function | Options | Description |
|---|---|---|
|
|
Returns the value of the specified parameter from the For example, Available only for calls received in IVR. |
|
Returns a string with the number dialed by the subscriber from the INVITE that is included in the routing. ATTENTION! For incoming calls from outside (from connections to providers), this number generally does not coincide with the one to which the external call was received. For the latter, use the calledid() function. Available only for calls received in IVR. To obtain a subscriber number when making outgoing calls using ivr (component 'Outgoing call', API 'invite_byivr'), you must use the IVR script parameters (startparam(N)) and pass the necessary information through them. |
|
|
Returns a string with the extension KAF through which the call was received in the IVR. Contains the entire postfix after removing the feature code number. Available only for calls received in IVR. To obtain a subscriber number when making outgoing calls using ivr (component 'Outgoing call', API 'invite_byivr'), you must use the IVR script parameters (startparam(N)) and pass the necessary information through them. |
|
|
Returns a string with the subscriber number generated as a result of applying representation rules, or the internal number of the subscriber of the current domain, or username from the From header of an INVITE request received for routing. ATTENTION! For incoming calls from outside (from connections to providers), this number generally does not coincide with the one from which the external call came, since it can be converted by normalization rules. For the latter, use the callerid() function. Available only for calls received in IVR. To obtain a subscriber number when making outgoing calls using ivr (component 'Outgoing call', API 'invite_byivr'), you must use the IVR script parameters (startparam(N)) and pass the necessary information through them. |
|
|
Returns a string with the number dialed by the subscriber. For calls originating externally from the provider, contains the username of the To header of the original received INVITE request before normalization and routing rules are applied. Available only for calls received in IVR. |
|
|
Returns a string with the number dialed by the subscriber. For calls originating externally from the provider, contains the username of the From header of the original received INVITE request before normalization, routing, and presentation rules are applied. Available only for calls received in IVR. |
|
|
Returns a string with the value of the header |
|
|
Returns a string with the native identifier of the current session (SC), extracting it from the labels of the current call. If you execute the function at the very beginning of the first call, it may delay execution by up to 500 ms while waiting for the session to be assigned. |
|
|
Returns a string with the current session identifier (SC), identifying it in the session store by the label’s native session. If you execute the function at the very beginning of the first call, it may delay execution by up to 500 ms while waiting for the session to be assigned. |
|
|
Returns a string with the value of the In order for an arbitrary header from the initial request from the subscriber to be forwarded to the IVR shoulder, you need to configure the list of headers forwarded through (the 'fwd_headers' parameter) in the configuration parameters of the 'esg' and 'b2b' roles. If there are several specified headers, their values will be separated by a line break ('\r\n' or 0x0D,0x0A). Available only for calls received in IVR. |
|
|
Returns a string with the entity identifier hunt-group to which the call is directed. Available only for calls received in IVR via featurecode with type |
|
|
Returns a string with the identifier of the runtime object of the hunt group queue. Available only for calls received in IVR via featurecode with type |
|
|
Returns the current numeric value of the priority in the queue. Available only for calls received in IVR via featurecode with type |
|
|
|
Sets a new numeric priority value in the queue, automatically moving. Available only for calls received in IVR via featurecode with type |
|
Returns the current position in the queue. Available only for calls received in IVR via featurecode with type |
|
|
Available only for calls received in IVR via featurecode with type |
|
|
Returns the number of operators in the hunt group. Available only for calls received in IVR via featurecode with type |
|
|
|
Returns the number of operators in the hunt group that are in state ( Available only for calls received in IVR via featurecode with type |
|
Returns a string with the name of the queued state. Available only for calls received in IVR via featurecode with type |
|
|
Returns the displayname from the Only available for |
|
|
Returns the username from the Only available for |
|
|
Returns domain from the Only available for |
|
|
Returns a string with the operator call number (username from the URI header Only available for |