Connecting to SMN to Send SMS Messages
You can connect an application to Simple Message Notification (SMN) to send SMS messages. For example, send an SMS message "Hi Lily!" to a mobile number.
Prerequisites
- You have registered an account with SMN and obtained the values of IAM Username, Account Name, Project ID, and Project Name of the required SMN resources.
Figure 1 Obtaining the key information
- You have obtained the access key ID (AK) and secret access key (SK). For details, see Obtaining an AK/SK.
Billing
After connecting an application to the SMN connector, you must pay for the SMN service separately. For details, see Huawei Cloud Pricing. After an application is disabled, SMN is still billed based on the preset billing rules.
Creating an SMN Connector
- Log in to the application designer by referring to Logging In to the Application Designer.
- In the navigation pane, choose Integrations.
- Click Connector Instance under Connector.
- In the navigation pane, choose Message > SMN.
- In the right pane, click + to set parameters.
SMN can be interconnected using Key or Username and Password.
Figure 2 KeyTable 1 Parameters for creating an SMN connector (key) Parameter
Description
Name
Name of the connector to be created. The naming requirements are as follows:
- The value cannot exceed 64 characters, including the prefix namespace.
To prevent duplicate data names among different tenants, each tenant must define a unique namespace when first creating an application. A tenant can create only one namespace. After being created, the namespace cannot be modified.
- Start with a letter and can contain only letters, digits, and underscores (_). Do not end with an underscore (_).
Access Key ID
Access key ID of a user. Set this parameter to the value of AK obtained in Prerequisites.
Secret Access Key
Secret access key of a user. Set this parameter to the value of SK obtained in Prerequisites.
Project ID
Unique ID of a project. Set this parameter to the project ID obtained in Prerequisites.
Region
Region where SMN is deployed.
Description
Enter the description of the connector.
Value: 1–255 characters.
Package Current Configuration
If this parameter is selected, the connector will be packed together with applications. For example, if an application package is released to the runtime environment, the current configuration is synchronized to the runtime environment by default. If this option is not selected, the connector will not be packaged and released to the runtime environment. In this case, you need to create the corresponding connector by referring to Managing Connectors in Applications.
This parameter is selected by default. You are advised not to select this option in information-sensitive scenarios.
Figure 3 Username and PasswordTable 2 Parameters for creating an SMN connector (username and password) Parameter
Description
Name
Name of the connector to be created. The naming requirements are as follows:
- The value cannot exceed 64 characters, including the prefix namespace.
To prevent duplicate data names among different tenants, each tenant must define a unique namespace when first creating an application. A tenant can create only one namespace. After being created, the namespace cannot be modified.
- Start with a letter and can contain only letters, digits, and underscores (_). Do not end with an underscore (_).
Account Name
Account name for logging in to SMN. The value must be the same as the account name obtained in Prerequisites.
Project Name
Project name that corresponds to the region where the SMN resources to be used are deployed. The value must be the same as the project name obtained in Prerequisites.
User Name
Username for logging in to SMN. The value must be the same as the IAM username obtained in Prerequisites.
Password
Password for logging in to SMN.
Project ID
Unique ID of a project. The value must be the same as the project ID obtained in Prerequisites.
User Type
Type of the user to which the connector belongs.
Sign ID
ID of an SMS message signature. This parameter is mandatory only when User Type is set to Enterprise User. Obtain the value from SMN. If this parameter is left blank, Huawei Cloud enterprise users are used by default.
Region
Region where SMN is deployed.
Description
Enter the description of the connector.
Value: 1–255 characters.
Package Current Configuration
If this parameter is selected, the connector will be packed together with applications. For example, if an application package is released to the runtime environment, the current configuration is synchronized to the runtime environment by default.
This parameter is selected by default. You are advised not to select this option in information-sensitive scenarios.
- The value cannot exceed 64 characters, including the prefix namespace.
- Click the save button.
- (Optional) Test whether SMS messages can be sent.
- Click Send Test on the connector details page.
- Enter the recipient phone number and SMS message content and click Send.
If the recipient receives the SMS message, the test is successful.
Calling a Connector in a Flow
In a flow, call the connector to connect to SMN.
- Create a blank flow by referring to Creating a Blank Flow.
- On the left of the flow design page, choose Connector > Message and drag the SMN diagram element to the canvas.
The SMN diagram element is preset in the system for connecting to SMS to send messages.
Figure 4 Dragging the SMN diagram element to the canvas - Select the SMN diagram element and set basic information.
Figure 5 Basic information
- Label: Label of a diagram element displayed on the page.
- Name: Unique ID of the diagram element in the system. The ID cannot be the same as that of other diagram elements.
- Connector: Name of the connector used for flows.
- Click
and set parameters for calling SMN.
Figure 6 Configuring parameters- Action: Set it to SMSSendSMS, the preset SMS sending API in the system.
- Input Parameters: Set the input parameters of the API.
- When Target is set to endPoint, configure the mobile number of the SMS message recipient in Source, which can be defined as an input variable {!Phone}.
- If Target is set to message, configure the message content in Source, which can be defined as an input variable {!Message}.
- Output Parameters: Set the output parameters of the API. Set Source to result and Target to receive the SMS message sending result (whether the SMS message is successfully sent). You need to define a structure variable of an empty instance to receive the result.
- On the left of the flow design page, choose Logic and drag the Decision diagram element to the canvas.
The Decision diagram element evaluates the current condition, similar to an if statement.
When an SMS message is sent successfully, the system sets resCode to 0. The Decision element then checks if resCode is 0 and sets a flag (for example, sendFlag) to indicate whether the SMS was sent successfully for further operations.
- Click
, click
next to Formula, and add the GetResultCode formula variable. The expression is GET({!result},"resCode") for receiving the SMS message sending result.
Figure 7 Configuring the GetResultCode formula variable - Configure the success branch of the Decision diagram element. That is, success indicates that the value of resCode is 0, indicating that an SMS message is sent successfully.
Figure 8 Configuring the success branch
- Configure the failure branch of the Decision diagram element. The value error indicates that SMS messages fail to be sent.
Figure 9 Configuring the error branch
- Click
- On the left of the flow page, select Logic, drag the Assignment diagram element to the canvas, and configure it.
Create a common variable sendFlag. The Assignment diagram element creates variables and assigns values to them. The operation that meets the success branch is added. If the SMS message is sent successfully, the success flag is generated.
- Click
, click
next to Variable, and create a common variable sendFlag.
- Click
and configure a value assignment operation that meets the success condition. The value is Message sent successful.
Figure 10 Assignment - Click
- Click
and configure a value assignment operation that meets the error condition. The value is Message sent Failes.
Figure 11 Configuring Assignment - Connect all diagram elements, as shown in Figure 12.
- Click the blank area on the flow design page, click
, and set the input and output parameters of the flow.
Figure 13 Setting the input and output parameters of the flow - Click
to save the flow.
- Click
to activate the flow.
- Set the input parameters (recipient number and SMS message content), and click the run button.
{ "Phone": "18625908976", "Message": "HI, Lily!" }
Figure 14 indicates that the message is sent successfully.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot