User Trigger

Magnet Max offers user trigger capability. Users can define customized rules with actions (e.g., send a message to specific user) that can be triggered if the 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.

final Date date = new Date(); final UserRuleCondition condition = new UserRuleCondition .Builder() .locRadius(10) .type(UserRuleConditionType.TIME_AND_LOCATION) .timeBegin(date.getTime()) .duration(100) .locCheckUsersList(Arrays.asList(User.getCurrentUserId())) .locLatitude(46.963887) .locLongitude(32.070587) .address("<Address>") .build(); final UserRuleAction action = new UserRuleAction .Builder() .targetUsersList(Arrays.asList(User.getCurrentUserId())) .messageTitle("<Message title>") .messageBody("<Message body>") .type(UserRuleActionType.MESSAGE) .build(); final MMXSmartRule rule = new MMXSmartRule( "<Rule name>", Arrays.asList(condition), Arrays.asList(action) ); rule.create(new MaxCoreActionCallback<MMXSmartRule>() { @Override public void onResult(boolean isSuccess, Throwable error, MMXSmartRule rule) { //DO SOMETHING AFTER CREATING OF THE MMXSmartRule } });

Update Existing User Rule

The following updates an existing user rule.

final MMXSmartRule rule; //Rule which was created and got from server // ... // Update MMXSmartRule locally // ... rule.update(new MaxCoreActionCallback<MMXSmartRule>() { @Override public void onResult(boolean isSuccess, Throwable error, MMXSmartRule rule) { //DO SOMETHING AFTER UPDATING OF THE MMXSmartRule } });

Delete User Rule

The following deletes an existing user rule.

final MMXSmartRule rule; //Rule which was created and got from server rule.delete(new MaxCoreActionCallback<MMXSmartRule>() { @Override public void onResult(boolean isSuccess, Throwable error, MMXSmartRule rule) { //DO SOMETHING AFTER DELETING OF THE MMXSmartRule } });

Fetch User Rules

You can retrieve user rules by user, by rule ID, or all rules.

The following will fetch all existing rules created by the current user.

MMXSmartRule.getUserRules(new MaxCoreActionCallback<List<MMXSmartRule>>() { @Override public void onResult(boolean isSuccess, Throwable error, List<MMXSmartRule> rules) { //DO SOMETHING AFTER GETTING OF THE MMXSmartRule list } });

The following will fetch all existing rules by all users.

MMXSmartRule.getAllRules(new MaxCoreActionCallback<List<MMXSmartRule>>() { @Override public void onResult(boolean isSuccess, Throwable error, List<MMXSmartRule> rules) { //DO SOMETHING AFTER GETTING OF THE MMXSmartRule list } });

The following will fetch a user rule by a specific ID.

MMXSmartRule.get("<Rule ID>", new MaxCoreActionCallback<MMXSmartRule>() { @Override public void onResult(boolean isSuccess, Throwable error, MMXSmartRule rule) { //DO SOMETHING AFTER GETTING OF THE MMXSmartRule by ID } });

Trigger Rule Actions

The following notifies the server that rule actions should be triggered (e.g., user location condition in the rule is satisfied).

final MMXSmartRule rule; //Rule which was created and got from server rule.trigger(new MaxCoreActionCallback<MMXSmartRule>() { @Override public void onResult(boolean isSuccess, Throwable error, MMXSmartRule result) { //DO SOMETHING AFTER TRIGGERING OF THE MMXSmartRule } });