Easy Push: Push message evertwhere easily

jusfory1
Tera Expert

Hi all

 

The background of this article is that my project needs to push some message to the self-developed OA system within the enterprise, so I created a POC application EASY PUSH to achieve that purpose. The overall architecture is as follows:
 

The advantages are:

  1. Push messages are as easy to configure as emails,
  2. Push messages will be logged,
  3. Each push can have a unique watermark,
  4. There are push switches and forwarding settings in the global settings.

 

The premise for the application to push messages normally is:

The user registers the push device token of the corresponding app.

 

My Example:
As the internal OA system use the email address prefix as the recipient's unique identifier,i add business rule for sys_user to register device token when the email field changes;

 

(function executeRule(current, previous) {
    var pushAppName = 'my_rest_push';
    new EasyPushUtils(pushAppName)
        .registryDeviceUser(
             current.sys_id + '',
             current.email + ''
         );
})(current, previous);

 

 

The basic principle is:

Easy push.png
  1. Step 1. Push system call the internal scripted REST API through REST message with the generate push content when push notification be triggered.
    1. push app.png
    2. Screenshot 2024-07-15 at 13.59.46.png
    3. Screenshot 2024-07-15 at 14.02.07.png
  2. Step 2: After receiving the payload, the scripted REST API will call the pushService method to complete the push.
  3. Step 3: The pushService method call others function like integration hub, sub flow, sub action or other external REST API etc, event gs.info payload as logs.
I designed transform functions before the push content is generated and before the push service is called.

 

var EasyPushUtils = Class.create();
EasyPushUtils.prototype = Object.extendsObject(x_838241_easy_push.EasyPushSNC, {
    transformFunc_parsePushPayload: function(rawContent) {
        // function impletements
        this.log.info('>>> run transformFunc_parsePushPayload')
        return rawContent;
    },
    transformFunc_pushContentBuilder: function(json, current, message, attributes) {
        // function impletements
        this.log.info('>>> run transformFunc_pushContentBuilder')

        return json;
    },
    transformFunc_appendWaterMark: function(rpushReqID, requestID) {
        // function impletements
        this.log.info('>>> run transformFunc_appendWaterMark')

        return pushReqID + ' -- ' + requestID;
    },
    type: 'EasyPushUtils'
});

 

Problems I encountered:

  1. I imitated the unboxing example ServiceNowMobileApp Push to create the following REST message:
    • endpoint: https://${pushHost}/API/now/v1/push/${applicationName}/enqueue
    • I expected ${pushHost} should be the instance name, but the actual value is not; so i have to manually hard code for the endpoint for other dev uat sit instances;
    • The internal call of servicenow seems to use only the post resource endpoint, and does not use the configured authentication, which causes me to manually handle authentication and data verification in the called Scripted REST API;
  2. When Pushing notification, I cannot efficiently get the push message id. It happens that I have many similar push messages, which makes it difficult for me to modify it by reversing the result to locate the template;
  3.  Feedback: how to mark push as failed, what's the structure of REST message response body {feedback:[]}?

Result:

I built a real APP extend this APP for production instance, there are some screenshots

  • push message:
  • Screenshot 2024-07-15 at 14.14.44.png
  • push notification log:
  • Screenshot 2024-07-15 at 14.28.44.png
I will to publish this application after completing If you are interested in it.
The above is my sharing, thank you.
0 REPLIES 0