Saltar al contendio prinicipal

COTLang Guide

Advertencia

Esta página aún no se encuentra traducida al español.

Cotalker Scripting Language


design

Overview

COTLang is a scripting language created by Cotalker, primarily used in its routines. It is used to extract data from different contexts in Cotalker.


COTLang Commands

When setting up routine stages, COTLang can be used for getting information from Cotalker databases.

Below is a table with COTLang commands, their descriptions, and format:

VALUE:
Extracts data from stages data of a routine.

$VALUE#[EXTRACTOR]

OUTPUT:
Used to obtain the previous stage's data

$OUTPUT#[stage-name]#[EXTRACTOR]

ENV:
Access the environment variable.

$ENV# environment-var

CODE:
Transform the code into an object.

$CODE#[model]#[EXTRACTOR]#[INPUT]

JOIN:
Concatenate values.

$JOIN#[Some char to join]#[ARG A]#[ARG B]#...#[ARG N]

TIME:
Generates date, relative to the current date.

$$TIME#[PARAM1]#[PARAM2]

META:
Extracts data from message.meta (Questions).

$META#[EXTRACTOR]

EXTRACTOR:

Token values:

  1. Values: Dive into value.
  2. Operators: Apply function to current data.

Examples


META

  • question.display = ["$META#somekey"]

  • message.meta = '{"somekey":"Happy New Year"}'

    When a value is required, question.display should return ["$META#somekey"]


EXTRACTOR

  • Operators: ... |[find => identifier = keyname]|... | [TOKEN1]|[TOKEN2]|...|[TOKEN-N]

  • General Example: {a: { b: { c1: 'Hola', c2: 'Mundo' } } }

    To access the info of variable c1, use the following token: a|b|c1. It wil respond with Hola.


Function

The format of the function is as follows:

[ function_name => token = Syntax | token ]

The following list shows the available COTLang functions along with a brief description and example:

size:
Returns the size of an array.

$VALUE#array|[size=>*]

toString:
Returns the input in string type.
cast:
Returns the input in float or boolean type.

$VALUE#anyValue|[cast=>parseFloat]

map:
Map elements from one type to another.

$VALUE#populatedChannelUsers|[map=>email]

arrayToObject:
Returns the object in array.

$VALUE#data|[arrayToObject=>key=value]...

isDefinedFilter:

Return only values that are not 0, "", null or undefined.

$VALUE#data|[isDefinedFilter=>meta]

filter:
Return all the arguments that apply to the condition.

$VALUE#data|[filter=>contentType=application/vnd.cotalker.survey+text]

notEqualFilter:
Filter the unequal values ​​of an array.

$VALUE#data|[notEqualFilter=>contentType=application/vnd.cotalker.survey+text]

simpleNotEqualFilter:
Filter unequal values ​​from an array to a condition.

$VALUE#data|[simpleNotEqualFilter=>125938f23295sd0]

simpleEqualFilter:
Filter equal values ​​from an array to a condition.

$VALUE#data|[simpleEqualFilter=>125938f23295sd0]

concat:
Concatenate values.
find:
Return a particular element of the array.

$VALUE#data|[find=>identifier=minuta-fecha]

push:
Add an element on the back.

$VALUE#populatedChannelUsers|[map=>email]|[push=>string=ignacio@cotalker.com]

add:
Add an element on the back, if it doesn't exists.

$VALUE#populatedChannelUsers|[map=>email]|[add=>string=ignacio@cotalker.com]

math:

Perform a mathematical operation on the values. The operation ar add or subtract.

$VALUE#answer|anyNumber|[math=>add=2]

date:
Allows parsing dates.

$VALUE#createdAt|[date=>format=DD-MM-YYYY]

every:

Perform the operation on each element of the array. The operator can be >= x, > x, < x, <= x or === x. And the key are gte, gt, lt, lte or eq, respectively.

$VALUE#data|[filter=>contentType=application/vnd.cotalker.survey+textnumber]|[map=>responses]|[every=>lte=2]

some:

Return the values that apply to one of the following conditions: >= x, > x, < x, <= x or === x. And the key are gte, gt, lt, lte or eq, respectively.

$VALUE#data|[filter=>contentType=application/vnd.cotalker.survey+textnumber]|[map=>responses]|[some=>lte=2]

json:
Convert a JSON to string.

$VALUE#populatedChannelUsers|[json=>parse]

querystring:
Generate a query string from an object.

$VALUE#someValue|[querystring=>string]

cotanswer_list:
Generate text answer from an array.

$VALUE#answer_data|[cotanswer_list=>array]

gencode:
Generate a code from a string.

$VALUE#path|to|string|[gencode=>*]