Handlebars Templates

Patriot supports handlebars templates for custom message formats.

This document outlines the following:

The data Patriot provides when rendering templates depends on the message context:

Context Data Type
Manual Messaging (including manual Bulk Messaging). StandardMessage
Response Plan task assignment message. Triggered when a signal logged with the appropriate response plan assigned. SignalMessage
Web Dispatch request/standdown email. PatrolDispatchMessage

Data Types

StandardMessage

Field Name Data Type Notes
User User The user the message is being sent to (if available)
Client Client The client the message is being sent to (if available)

NOTE: For standard messages some fields are only available when applicable; for example:

SignalMessage

Field Name Data Type Notes
User User The user the message is being sent to
Signal Signal The signal which triggered the message
MessageId string The Message ID is used for responding to First Response messages

PatrolDispatchMessage

Field Name Data Type Notes
MessageType string One of the following values:
"DISPATCH_REQUEST"
"STANDDOWN"
MessageTypeDescription string Human-friendly (and translatable) description of MessageType:
"Dispatch Request"
"Stand Down"
User User The user the message is being sent to
DispatchURL string The URL used to respond to the dispatch request
Dispatch PatrolDispatch The signal which triggered the message
StanddownReason string Only included if this is a STANDDOWN message type

User

Field Name Data Type Notes
UserId number
Name string
Email string
MobileEmail string
PhoneNo string
MobileNo string
FaxNo string
AfterHoursNo string
PagerNo string

Signal

Field Name Data Type Notes
Client Client
Activation Activation
SignalId number
ActionPlanId number
ActivationId number
DateTime DateTime
TypeNo number
ModuleNo number
ZoneUser number The zoneNo or userNo (depending on the signal type)
Description string
RawData string
Notes string

Client

Field Name Data Type Notes
ExternalRefNo number
ClientNoRaw string i.e. 123400301 for ClientNo 1234(3)-01
ClientNo string Formatted Client No i.e. 1234(3)-01
ClientId string i.e. 1234 for ClientNo 1234(3)-01
PortNo string i.e. 01 for ClientNo 1234(3)-01
AreaNo string i.e. 0003 for ClientNo 1234(3)-01
Name string
Alias string
AddressLine1 string
AddressLine2 string
AddressLine3 string
PostCode string
CityName string
StateName string
CountryName string
PostalAddressLine1 string
PostalAddressLine2 string
PostalAddressLine3 string
PostalCityName string
PhoneNo string
MobileNo string
OkPassword string
HoldUpPassword string
Dealer User The client's dealer

PatrolDispatch

Field Name Data Type Notes
JobId number
ActivationId number
Description string
DispatchDateTime DateTime
StatusId number One of the following: 1 (Complete),2 (Dispatch Requested),3 (Accepted),4 (Cancelled),
StatusLabel string Textual representation of the StatusId
CustomerOrderNo string
DocketNo string
CompletedDateTime DateTime Only set if the dispatch has been completed (or cancelled)
WorkOrderCategory string
Client Client
Activation Activation

Activation

Field Name Data Type Notes
ActivationId number
Description string
DateTime DateTime
ZoneUser number The zoneNo or userNo (depending on the signal type)

Partial Templates

Partial templates are able to be reused by other templates. Patrial templates must be stored in <Storage Directory>/HandlebarsTemplates/Shared. Partials are referenced by their file name without extension (i.e. myPatrial.txt) can be used in the following manner: {{>myPartial}}

Custom Helpers

String Helpers

The following helpers return strings

Helper Name Parameters Notes Example Usage
format (dateTime: DateTime, format: String, [optional cultureName: String]) format can be either a standard or custom DateTime format string.

cultureName, if specified, must be a supported Culture Name
{{format Signal.DateTime 't'}} -> 12:34 PM
{{format Signal.DateTime 'MMMM dd, yyyy'}} -> June 10, 2011
format (number: Number, format: String, [optional cultureName: String]) format can be either a standard or custom Numeric format string.

cultureName, if specified, must be a supported Culture Name
{{format 123.456 '0.0'}} -> 123.5
{{format 123.456 '0.0' 'fr-FR'}} -> 123,5
format (value: IFormattable, format: String, [optional cultureName: String]) cultureName, if specified, must be a supported Culture Name
formatClientNo (rawClientNo: String) Converts a raw clientNo into a display clientNo (i.e. 1234BASE01 -> 1234-01)
{{formatClientNo Client.RawClientNo}}
substring (value: String, startIndex: Number, [optional length: Number]) Returns a substring of the provided value.

startIndex
Starts at this position in the string (0 for start for the beginning of string). A negative value can be provided to start N characters from the end of the string.

length
Takes this many characters after the provided startIndex. A negative value can be provided to take N characters before the startIndex
{{subString 'A long value' 2}} -> long value
{{subString 'A long value' 2 4}} -> long
{{subString 'A long value' 6 -4}} -> long
{{subString 'A long value' -10}} -> long value
{{subString 'A long value' -10 4}} -> long
{{subString 'A long value' -6 -4}} -> long
regexReplace (value: String, pattern: String, replacement: String, [optional options: RegexOptions]) pattern
Expects a .Net Regex Pattern

replacement
Expects a .Net Replacement Pattern
{{regexReplace 'A2' '[ABC]([123])' 'Z$1'}} -> Z2

Boolean Helpers

The following helpers return either True or False and are useful in conjunction with the built-in #if helper e.g.:

{{#if (equals Signal.TypeNo 123)}}Is Type 123{{/if}}

Helper Name Parameters Returns Notes
equals 2 or more values True if all parameters are equal
gt 2 or more values True if each parameter is greater than the preceding value
gte 2 or more values True if each parameter is greater than or equal to the preceding value
lt 2 or more values True if each parameter is less than the preceding value
lte 2 or more values True if each parameter is less than or equal to the preceding value
and 2 or more values True if all of the parameters are truthy
or 2 or more values True if any of the parameters are truthy
regexMatch (value: String, pattern: String, [optional options: RegexOptions]) True if value matches pattern pattern is a .Net Regex Pattern

Regex Options

RegexOptions are passed a string containing one or more of the following characters:

See here for more info

Including Map locations

You can include a link to the location of the site by using including the following details within anchor tags

href="https://www.google.com/maps/place/{{Dispatch.Client.AddressLine1}}, {{Dispatch.Client.CityName}}" >{{Dispatch.Client.AddressLine1}}, {{Dispatch.Client.CityName}}


Including Images

If the template is being used as an html template, it can also contain images. These are included using the src property of appropriate tags, for example

<img src="" alt="Alarm Header Image"/>

The image used needs to be copied onto a publicly accessible webserver, and the src property updated to use a url of the image location. So, a complete example would be

<img src="https://www.yourwebserver.com/image.png" alt="Alarm Header Image"/>

Example Templates

Response Plan task assignment examples

An example of a Text version of a template is

Hi {{User.Name}},

The following alarm has occurred at site '{{Signal.Client.Name}}':

{{format Signal.Activation.DateTime 'g'}}

{{Signal.Activation.Description}}

{{Signal.Description}}

Regards,

Alarm Monitoring Company

More examples for download

Web Dispatch examples

An example of a Text version of a template is

Hi {{User.Name}},

Please respond to the following {{MessageType}}:

{{format Dispatch.DispatchDateTime 'f'}}

{{Dispatch.Description}}

Zone No:{{Dispatch.Activation.ZoneUser}}

{{Dispatch.Client.Name}}

{{Dispatch.Client.AddressLine1}}

{{Dispatch.Client.AddressLine2}}

Regards,

Alarm Monitoring Company

For Web Dispatch, the format should be in html format, to allow for the inclusion of the DispatchURL to link to the responding web page. The above example is only intended to show examples of the the fields available.

More examples for download

Character Encoding

Template files are expected to be in UTF-8 character encoding. This is the default encoding used by most modern operating systems and text editors. However, some international customers may still be using software which saves template files in older ANSI character encodings. e.g. Windows-1253 / ISO 8859-7 (Greek)

To support this scenario Patriot will attempt to read the template files as UTF-8 but if that fails it will fallback to the locale specified in the regional settings of the user's PC. This locale setting can be found in Windows under Control Panel > Region > Administrative > Language for non-Unicode programs