You can use Push Kit to push information to users.
Before using the message service, you need to enable Push Kit. For details, please refer to Preparations.
Before development, ensure that you have completed the configurations specified in Preparations, enable service notifications, and select a subscription template.
Call the has.requestSubscribeMessage method to initiate message subscription.
has.requestSubscribeMessage({
tmplIds: ['xxx'],
success: (res) => {
console.info('requestSubscribeMessage success', res);
},
fail: (err) => {
console.error('requestSubscribeMessage fail', err);
},
complete: (res) => {
console.info('requestSubscribeMessage complete', res);
}
}); When a user agrees to subscribe to messages, the atomic service can push messages based on the account. For details, please refer to Pushing Account-based Subscription Notifications.
Pushing service updates is a business-to-customer (B2C) messaging capability provided for you. You can leverage it to deliver updates to users at key order milestones, so users stay informed about their order status.
You can obtain the unique code for pushing service updates in either of the following ways:
The development procedure is basically the same as that for pushing account-based service updates in an ArkTS atomic service.
This capability is supported since the ASCF runtime version 1.0.20. Before using it, you need to apply for the atomic service update message permission by referring to Applying for the Permission.
You need to set the open-type attribute of the button component that triggers the service to liveActivity and set the activity-type attribute to the corresponding sub-scenario ID (for details, please refer to Service Updates Scenario Templates). When a user taps the button, if the service update authorization code is successfully obtained, code will be returned through the bindcreateliveactivity callback. If the authorization code fails to be obtained, the error message will be returned through the binderror callback.
This code is unique to the service process. You must use this code to push service status updates to the corresponding user.
The system verifies the button component for compliance, including whether the user is misled to tap the button or whether the button is irrelevant to the message card to be activated. Therefore, proper use of the button component is required.
Sample code
<!--HXML file--> <button open-type="liveActivity" activity-type="100050001" bindcreateliveactivity="onLiveActivityCreate">Obtain the service update authorization code</button>
// JavaScript file
Page({
onLiveActivityCreate(evt) {
console.info(`Obtained service authorization code successfully: code=${evt.detail.code}`);
}
});