Message Notification
Capabilities Introduction
"Message Notification" is a capability provided by the Cloud Development Platform that enables developers to send notifications via channels including but not limited to in-site messages and SMS, based on custom notification policies when relevant trigger rules are met.
Capabilities Features
Notification Policy Management
- It includes all message notification policies in the current environment, allowing you to enable/disable, edit, or delete policies (deleted policies become invalid and cannot be recovered).
- The main components of a notification policy include monitoring type, trigger action, trigger condition, notification content, notification recipient, and notification channel.
Notification Trigger History
- Records of successfully triggered notifications support querying notification records by time.
- Supports viewing and deletion of historical notification messages (irreversible).
Usage Instructions
1. Automatic Triggering
- Go to Workbench - Data Management, create a new target monitoring data model "Message Notification", using the name and age fields as trigger condition examples.
- Go to Workbench - Notification Management to create a new notification policy.
- Edit the relevant information of the notification policy. For example, set the trigger action of the data model to "new data" and the trigger condition to "name=rocky and age>55". Then, notification messages will only be triggered when newly added data in the target data model meets this condition.
- Triggering methods: Automatic triggering and manual triggering (default is automatic triggering).
- Monitoring type: Currently supports "data model". The model name selects a pre-created data model. Trigger actions include data creation, deletion, and modification. Trigger conditions support setting multiple fields simultaneously.
- Notification mechanism: Real-time push.
- Notification content: Fill in the corresponding copy based on the prompt content in the multi-line input box. Double curly braces "{{}}" represent template variables used to reference data model field values.
- Notification recipients: Refer to user objects that can receive notification messages. More users can be added in Workbench - User Permission Management.
- Notification channels: Currently supports Workbench internal messages and SMS notifications (sent to the mobile phone numbers bound to notification users).
- After configuring the relevant information, save the notification policy.
- Go to the data model management interface, add new data in the template model, and perform notification push testing.
- After the notification policy is successfully triggered, the Workbench will receive internal messages.
- The internal message panel allows querying all types of messages, including monitoring alerts and business notifications.
- SMS notification display.
- You can query the notification trigger history in the Notification Management interface.
2. Manual Triggering (SDK Trigger)
1. Interface Introduction
- Interface description: Message policies can be configured in the Weixin Cloud Development Cloud Console / Notification Management module. When selecting "Manual Triggering" as the trigger method, notifications will only be sent after actively calling the interface in business code.
- Function: Send notification messages.
- Interface declaration:
sendTemplateNotification(params: ITemplateNotifyReq, opts?: ICustomReqOpts)
.
2. Input Parameters
Field | Type | Required | Description |
---|---|---|---|
params | ITemplateNotifyReq | Required | Request parameters |
opts | ICustomReqOpts | No | Custom configurations, currently supports setting the SDK request timeout, {timeout: number} |
ITemplateNotifyReq
Field | Type | Required | Description |
---|---|---|---|
notifyId | string | Required | Alert policy Id |
data | Record | No | Key-value pairs for template variables in the alert policy |
url | string | No | The page URL to open after the user clicks the alert message |
3. Response
Promise<CallFunctionResult<ResultT>>
Field | Type | Required | Description |
---|---|---|---|
result | ResultT | No | Execution result |
requestId | string | No | Unique request Id for error troubleshooting |
Code execution errors will throw exceptions
4. Sample Code
// Cloud Function entry file
const tcb = require("@cloudbase/node-sdk");
const app = tcb.init({
secretId: "", // Tencent Cloud API fixed key pair, optional when executed within Cloud Functions
secretKey: "", // same as above
env: "", // CloudBase environment id
});
exports.main = async (event, context) => {
const result = await app.sendTemplateNotification({
notifyId: "xxx",
data: { orderId: "aaa", amount: 200 },
url: "https://cloud.tencent.com/solution/la",
});
return result;
};
Note
CloudBase database supports listening for update events of data that matches the query criteria in collections. For more information, refer to the documentation Real-time Updates