By default, Magnet Max notifies offline MMXChannel subscribers using push notifications (APNS, GCM). Push templates are FreeMarker templates that allow you to customize push notification content on the basis of an app, MMXChannel, and MMXMessage. For example, pushes can contain more information like: "John just replied to your message" or "Jane just posted a photo". This allows users to get more detailed and useful pushes in a few steps.
The default system push templates will be used if no other push templates are specified. Push templates always use the most descriptive template available and will override any global push templates. For example, if an app has a custom push template named "MyAppTemplate" and an MMXChannel has an associated push template named "MyChannelTemplate", the channel template will be used. On the other hand, if the MMXChannel does not have an associated push template, the app level template "MyAppTemplate" will be used. The same rule applies for MMXMessages.
To create an app wide template, select the Create Template button located in the top right corner of the Magnet Studio console and enter "MyAppTemplate" as the name for your template. Use the FreeMarker syntax to customize your push notification. (See Push Template Context Variables for accessible variables.)
To create a channel template, select the Create Template button located in the top right corner and enter "MyChannelTemplate" as the name for your template. In the Applies To section, select channels. Use the FreeMarker syntax to customize your push notification for MMXChannels. (See Push Template Context Variables for accessible variables.)
Now that you have two templates defined, you can try them out by applying them to the MMXChannel.
Create one channel with the default push config and one channel with a custom push config.
Now that we have two channels created, append the following code to the sendMessage
method to send a message to both channels.
If a channel subscriber is offline, the notification received will be different.
Important: If you have not done so already, configure your app for push notifications. See Set up GCM.
Using push templates on an MMXMessage is similar to using one on a channel. Go back to Magnet Studio create another push template following the steps above; name the push template "MyMessageTemplate". In the Applies To section select channels. See Push Template Context Variables for accessible variables.
Create custom values for your template or use the one below.
Specify the push config name when constructing the MMXMessage:
If some channel subscriber is offline, the notification received will be "bar - 2016-5-10".
Object | variable | Type | Description |
---|---|---|---|
application | |||
name | String | Server side application name | |
channel | |||
name | String | Channel name | |
desc | String | Channel description | |
msg | |||
from | String | User first and last name ("FirstName LastName") | |
date | java.util.Date | Base on server locale; user locale is not available. Use date/time/datetime formatter as ${msg.date?datetime} | |
content | java.util.Map | Dictionary containing MMXMessage messageContent (e.g. ${msg.content.content_key}) |