User Trigger
Magnet Max offers user trigger capability. Users can define customized rules with actions (e.g., send a message to a specific user) that can be triggered if time AND/OR location condition is satisfied.
By using the User Trigger function, it's easy to achieve the following use cases.
Case 1. A user wants to send a message to anyone in a target group:
- if target group user(s) are in a specific location AND/OR
- during a certain timeframe
Case 2. A user wants to get push notifications from anyone in the target group:
- if the user is in a specific location AND/OR
- during a certain timeframe
The Magnet Max SDK provides the following APIs to handle the user trigger function.
Create New User Rule
The following creates a new user rule.
var ruleConditions = [];
var ruleActions = [];
var userRule = new Max.UserRule();
ruleConditions.push({
"locRadius": 10,
"type": "TIME_AND_LOCATION", // "TIME", "LOCATION", "TIME_AND_LOCATION"
"timeBegin": 1489345621340,
"duration": 100,
"locCheckUsersList": ["UserID-1", "UserID-2", ...],
"locLatitude": 46.963887,
"locLongitude": 32.070587,
"address": "<Address>"
});
ruleActions.push({
"messageBody": "<Message body>",
"messageTitle": "<Message title>",
"type": "MESSAGE", // "MESSAGE", "SURVEY", "CHECKLIST",
"targetUsersList": ["UserID-1", "UserID-2", ...]
});
userRule.create("new rule", ruleConditions, ruleActions).success(function(userRuleObj) {
// do something with object userRuleObj
}).error(function(err) {
// handle error on failure
});
Update Existing User Rule
The following updates an existing user rule.
var userRule = ...;
// Update userRule locally
userRule.update(userRule).success(function(userRuleObj) {
// do something after updated object userRuleObj
}).error(function(err) {
// handle error on failure
});
Delete User Rule
The following deletes an existing user rule.
var userRule = ...;
userRule.delete().success(function() {
// do something after deleting
}).error(function(err) {
// handle error on failure
});
Fetch User Rules
You can retrieve user rules by user, by rule ID, or all rules.
The following will fetch all existing user rules created by the current user.
Max.UserRule.getUserRules().success(function(userRuleObjs) {
// do something after getting of the userRuleObj list
}).error(function(err) {
// handle error on failure
});
The following will fetch all existing rules created by all users:
Max.UserRule.getAllRules().success(function(userRuleObjs) {
// do something after getting of the userRuleObj list
}).error(function(err) {
// handle error on failure
});
The following will fetch a user rule by a specific ID:
var userRuleId = ...;
Max.UserRule.getRuleWithID(userRuleId).success(function(userRuleObj) {
// do something after getting of the userRuleObj
}).error(function(err) {
// handle error on failure
});
Trigger Rule Actions
The following notifies the server that rule actions should be triggered (e.g., user location condition in the rule is satisfied).
var userRule = ...;
userRule.trigger().success(function() {
// do something after trigger success
}).error(function(err) {
// handle error on failure
});