Help Center/ Simple Message Notification/ Getting Started/ Publishing a Template Message
Updated on 2024-09-30 GMT+08:00

Publishing a Template Message

Scenarios

You can publish a template message to an SMN topic when:

Most of the content in the messages is fixed, and only a few parts vary with the occasions. In this scenario, you can create a message template and use variables as placeholders to indicate changeable content. Each time when you publish a message, you can select a template and set values only for variables without having to edit the message content repeatedly.

This topic describes how to create a topic and publish a template message.

For example, your organization holds expositions regularly, and you need to notify people of the time. Except for the time, most part of the message remains unchanged.

Operation Process

Procedure

Description

Making Preparations

Sign up for a HUAWEI ID, complete real-name authentication, enable Huawei Cloud services, and top up your account.

Step 1: Create a Topic

Create a topic Mytopic.

Step 2: Add a Subscription

Add SMS and email subscriptions to the topic.

Step 3: Create a Message Template

Create a message template named tem_001 and select Default, SMS, and Email for Protocol separately.

Step 4: Publish a Message

Publish a message to SMS and email endpoints: The Arts and Crafts Exposition will be held from {startdate} through {enddate}. We sincerely invite you to join us.

{startdate} indicates when the exposition will be started. {enddate} indicates when the exposition will be ended.

Step 5: Receive the Message

The subscription endpoints receive the message.

Making Preparations

  1. Sign up for Huawei Cloud and complete real-name authentication.

    Before using SMN, sign up for a HUAWEI ID, enable Huawei Cloud services, and complete real-name authentication.

    If you have enabled Huawei Cloud services and completed real-name authentication, skip this step.

  2. Top up your account.

    Ensure that the account balance is sufficient. If not, top up your account.

Step 1: Create a Topic

  1. Log in to the SMN console and go to the Create Topic page.
  2. Configure topic parameters.
    In this example, only some parameters are described. Retain the default values for other parameters. For details about the parameters, see Creating a Topic.
    Figure 1 Create Topic
    Table 1 Parameters for creating a topic

    Parameter

    Example Value

    Description

    Topic Name

    Mytopic

    Specifies the name of the topic to be created.

    Enterprise Project

    default

    This parameter is displayed only for enterprise users who have enabled enterprise project management.

  3. Click OK.

    After a topic is created, the system generates a topic URN, which uniquely identifies the topic and cannot be changed. The topic you created is displayed in the topic list.

Step 2: Add a Subscription

Add SMS and email subscriptions to the topic.

  1. In the topic list, locate Mytopic and click Add Subscription in the Operation column.
  2. Configure subscription parameters.

    In this example, only some parameters are described. Retain the default values for other parameters. For details about the parameters, see Creating a Topic.

    Figure 2 Add Subscription
    Table 2 Parameters for adding an SMS subscription

    Parameter

    Example Value

    Description

    Topic Name

    Mytopic

    Specifies the name of the topic you select to add subscriptions.

    Protocol

    SMS

    Select SMS from the Protocol drop-down list.

    For more supported protocols, see What Protocols Does SMN Support?

    Endpoint

    +8618612345678

    Enter a valid mobile number in the text box.

    • You can enter up to 10 endpoints, each on a separate line.
    • SMN does not check whether subscription endpoints exist when you add subscriptions.
  3. Click OK.

    After a subscription is added, the subscription endpoint receives a confirmation message. The recipient needs to click the subscription confirmation link on the subscription endpoint to confirm that they agree to receive messages published to the topic. On the SMN console, you can see that the subscription status is Confirmed.

  1. In the topic list, locate Mytopic and click Add Subscription in the Operation column.
  2. Configure subscription parameters.

    In this example, only some parameters are described. Retain the default values for other parameters. For details about the parameters, see Creating a Topic.

    Figure 3 Add Subscription
    Table 3 Parameters for adding an email subscription

    Parameter

    Example Value

    Description

    Topic Name

    Mytopic

    Specifies the name of the topic you select to add subscriptions.

    Protocol

    Email

    Select Email from the Protocol drop-down list.

    For more supported protocols, see What Protocols Does SMN Support?

    Endpoint

    username@example.com

    Enter a valid email address in the text box.

    • You can enter up to 10 endpoints, each on a separate line.
    • SMN does not check whether subscription endpoints exist when you add subscriptions.
  3. Click OK.

    After a subscription is added, the subscription endpoint receives a confirmation message. The recipient needs to click the subscription confirmation link on the subscription endpoint to confirm that they agree to receive messages published to the topic. On the SMN console, you can see that the subscription status is Confirmed.

Step 3: Create a Message Template

  1. In the navigation pane on the left, choose Topic Management > Message Templates.
  2. On the displayed page, click Create Message Template in the upper right corner.
  3. Configure message template parameters.

    In this example, only some parameters are described. Retain the default values for other parameters. For details about the parameters, see Message Template Management.

    Figure 4 Create Message Template
    Table 4 Parameters for creating a message template

    Parameter

    Example Value

    Description

    Template Name

    tem_001

    Specifies the name of the template to be created.

    Protocol

    • Default
    • SMS
    • Email

    Create a message template named tem_001 and select Default, SMS, and Email separately.

    Content

    The Arts and Crafts Exposition will be held from {startdate} through {enddate}. We sincerely invite you to join us.

    Customize the template content.

    Use {xxx} as the placeholder to create a template. When you use this template to publish messages, replace {xxx} with specific content. xxx must start with a letter or digit and can contain up to 21 characters, including only letters, digits, hyphens (-), periods (.), and underscores (_).

  4. Click OK.

    The template you created is displayed in the template list.

Step 4: Publish a Message

  1. In the navigation pane on the left, choose Topic Management > Topics.
  2. Locate Mytopic and click Publish Message in the Operation column.
    Figure 5 Publish Message
    Table 5 Parameters for publishing a message

    Parameter

    Example Value

    Description

    Topic Name

    Mytopic

    Specifies the name of the topic you select to publish a message.

    Message Format

    Template

    Specifies in which format messages will be sent.

    Message

    {
        "message_template_name": "tem_001",
        "tags": {
            "startdate": "08/02/2024",
            "enddate": "08/20/2024"
        }
    }

    You can manually enter a template message or click Generate template Message to automatically generate a message.

    For details, see Template Message Format.

  3. Click OK.

    For details about messages, see Messages Using Different Protocols.

Step 5: Receive the Message

Subscription endpoints of different protocols receive different messages.

  • SMS

    SMS messages only contain the message content.

  • Email

    Email messages contain the message subject, content, and a link to unsubscribe.