Skip to main content

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

  1. Go to Workbench - Data Management, create a new target monitoring data model "Message Notification", using the name and age fields as trigger condition examples. image.png
  2. Go to Workbench - Notification Management to create a new notification policy. image.png
  3. 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. image.png
  • 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).
  1. After configuring the relevant information, save the notification policy. image.png
  2. Go to the data model management interface, add new data in the template model, and perform notification push testing. image.png
  3. After the notification policy is successfully triggered, the Workbench will receive internal messages. image.png
  4. The internal message panel allows querying all types of messages, including monitoring alerts and business notifications. image.png
  5. SMS notification display. image.png
  6. You can query the notification trigger history in the Notification Management interface. image.png

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. image.png
  • Function: Send notification messages.
  • Interface declaration: sendTemplateNotification(params: ITemplateNotifyReq, opts?: ICustomReqOpts).

2. Input Parameters

FieldTypeRequiredDescription
paramsITemplateNotifyReqRequiredRequest parameters
optsICustomReqOptsNoCustom configurations, currently supports setting the SDK request timeout, {timeout: number}

ITemplateNotifyReq

FieldTypeRequiredDescription
notifyIdstringRequiredAlert policy Id
dataRecordNoKey-value pairs for template variables in the alert policy
urlstringNoThe page URL to open after the user clicks the alert message

3. Response

Promise<CallFunctionResult<ResultT>>

FieldTypeRequiredDescription
resultResultTNoExecution result
requestIdstringNoUnique 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