Proto Script & Template Language

Proto script & template language allows user to use simple script to modify or process the values in the platform such as processing the response of the JSON API block, modify values in Modify Variable block, adding condition on Branch block and etc.

Proto Variables

  • Use a dot . to access attributes of a variable in addition to the standard Python __getitem__“subscript” syntax [ ]

Proto Script

You can use Proto Script in the following actions:

  • Bot Message
  • Branch
  • Carousel
  • Create Case
  • Email
  • JSON API
  • Hyperlink
  • Modify Variable
  • Survey

Proto Script Delimiter

  • { … } - to print out the variable/script values

Requires { … } delimiter

  • Bot Message
  • Carousel
  • Create Case
  • Email
  • Hyperlink
  • Survey

Do not require { … } delimiter

  • Branch
  • JSON API
  • Modify Variable
Proto ScriptDescription
_.len(x)the number of characters in a variable
_.replace(string, search, replacement)replaces a specified phrase with another specified phrase
_.fmt(string, value)formats the specified value(s) and insert them inside the string's placeholder
_.now(timezone, format)the current date/time. Example: _.now('Asia/Manila', '%Y %H')
_.formatTime(datetime, format, timezone)format datetime. Example: _.formatTime(_.str2datetime(timestamp), '%Y-%m-%d %H:%M:%S', 'America/Toronto')
_.str2datetime(timestring, format)convert string to datetime
_.upper(string)convert string to uppercase
_.lower(string)convert string to lowercase
_.json_stringify(data)json.dumps()
_.json_parse(data)json.loads()
_.join(separator, items)join all items in a tuple into a string, using a character as separator
_.split(string, separator)split a string into a list where each word is a list item
_.dt_diff(datetime1, datetime2, unit)calculate datetime difference. Unit - d for day, h for hour, m for minute , s for second.

Proto Script - Operators

Proto platform also support operators to perform operations on variables and values. The following are the Proto Script operator supported on Proto's platform.

  • Arithmetic Operators (except Modulus %)
  • Comparison Operators
  • Assignment Operators
  • Identity Operators
  • Logical Operators
  • Membership Operators

Proto Template Language

Besides Proto script, you can also use Proto template to process the values on Proto's platform. The following are the Proto Template operator supported on Proto's platform:

  • Arithmetic Operators
  • Comparison Operators
  • Assignment Operators
  • Identity Operators
  • Logical Operators
  • Membership Operators
  • Assignments - assign values to variables
  • For Loops
  • If…Else

Proto Template Delimiter

  • [% ... %] – to write the Proto Template statements

Support statement [% ... %]

  • Bot Message
  • Carousel
  • Create Case
  • Email
  • Survey

Does not support statement [% ... %]

  • Branch
  • JSON API
  • Modify Variable

If you add a minus sign (-) to the start or end of a block (e.g. a For Loops tag), a comment, or a variable expression, the whitespaces before or after that block will be removed.

[% for item in seq -%]
[% if item == "abc" -%]
   [% set count = 0%]   # you can use set to define a variable
[% elif item == "efg" -%]
   This is {item}
[% else -%]
	 This is {item}
[%- endif %]
[%- endfor %]

What’s Next

Be sure to check out Proto system variables next, that provides access to end-user's info right in the chatbot.