Additional Methods used in Botmaker
Here you will learn about other methods that are utilized within the Botmaker platform.
Estimated Reading Time: 03 minutos
Freemarker
We utilize Freemaker as a “template engine” for the bot’s responses. You can learn more about it in this link: Freemarker
There are certain functions written withing this technology used to facilitate common tasks, such as shortening URLs for example.
Methods
- JSON - ${json2(‘{a:“123”}’).a}
- Stringify - ${stringify(‘[{“f”: “a”},{“f”: “b”}]’?eval[0])[0…2]}
- AddToArray - ${addToArray([1,2,3],4)}
- IsEmpty - ${isEmpty(‘’)?then(‘s’,‘n’)}
- GetOrDefault - ${getOrDefault(null,‘default’)}
- DateISO - ${fromDateTimeToDateISO(‘13-12-2018’)}
- Today - ${today()}
- TodayAddDays - ${todayAddDays(1)}
- TodayDateAddDays - ${todayDateAddDays(1)}
- ShortenURL - ${shortenURL(‘https://www.google.com/’)}
- TimeDiff - ${timeDiff(‘10:00:00’, ‘-3’, ‘HH:mm:ss’, ‘m’, ‘83’)}
- Bold - *text *
- Italic - _text _
Regular Expressions
Regular expressions can be used in triggers of responses and conditions inside the responses. We also utilize them for validating data that is inputted by the client, or to find a certain combination of characters necessary for activating events, or storing said information inside variables.
You can learn more about regular expressions in this link: Regular Expressions
An example of their usage is to put the regular expression (.*) that references anything that the client may input.
Applications
Both functionalities can be combined for different objectives. One example of this is to search a certain code or word inside the client’s message to store it inside a variable and then be able to work with the stored data at a later point.
variable = ${lastUserSentence?matches(r"(.\b(cadenadetextoabuscar)\b.)")?groups[2]}