Asgard built-in helpers
Asgard provides eight helpers for the Handlebars template system.
📖 Handlebars basics
The Handlebars guide is worth reading first for the syntax itself.
Conversation history
history
Returns the channel's conversation history over an index range.
Parameters:
start: where to start, from 0, with negative values counting from the endend: where to stop, inclusive, with negative values counting from the end
historySize
Returns how many messages the channel's history holds.
Data handling
toJson
Converts any value into a JSON string.
urlEncode
URL-encodes a string.
xpathExtract
Looks up a value in an XML document with XPath.
Parameters:
xml: the XML documentpath: the XPath query
Example:
<!-- input XML: <root><item>1</item><item>2</item></root> -->
<!-- output: 1\n2 -->
vecToStr
Converts a vector array into a string.
Parameters:
vector: the vector arrayprefix: the opening charactersuffix: the closing characterdelimiter: the separator
Date and time
isoNow
Returns the current date and time in a given timezone, as an RFC3339 string.
isoToday
Returns the current date in a given timezone, as an RFC3339 string.
Worked examples
A system status report
Handling an API query
Good practice
- Conversation history: use
historyandhistorySizefor context awareness - Safety: always
urlEncodeanything going into a URL - Timezones: state the timezone explicitly
- JSON: use
toJsonso the output is valid JSON - XML: make sure the XPath is correct
- Vectors: pick the delimiter that suits the consumer
These helpers cover conversation history, data conversion and formatting inside a Handlebars template.