Skip to main content
Version: 1.6.x

Alibaba Cloud SMS

Alibaba Cloud SMS is an enterprise-level SMS notification service based on Alibaba Cloud SMS API, implementing SMS business scenarios such as verification code sending and notification reminders through the standard sendMessage interface. It integrates Alibaba Cloud SMS API, supports AccessKey authentication and signature verification mechanisms, provides complete error handling and log monitoring, ensuring message delivery reliability.

The hierarchical structure of Alibaba Cloud SMS elements is Meta (SMS.Meta) → Type (SMS.Aliyun) → Instance. Developers can quickly create Alibaba Cloud SMS instance elements through JitAI's visual development tools.

Of course, developers can also create their own Type elements or modify the official SMS.Aliyun element provided by JitAI in their own App to implement their own encapsulation.

Quick Start​

Creating Instance Elements​

Directory Structure​

Recommended Directory Structure
SMS/
└── YourSmsName/ # Custom SMS instance name
├── e.json # Element declaration file
└── sms.json # Alibaba Cloud SMS configuration file

e.json File​

Element Declaration File
{
"title": "My Alibaba Cloud SMS",
"type": "SMS.Aliyun",
"backendBundleEntry": "."
}

Business Configuration File​

sms.json Configuration File
{
"accessKey": "your_access_key",
"accessSecret": "your_access_secret",
"verifySign": "your_signature"
}

Usage Example​

Send SMS Example
# Get SMS element instance
sms_element = app.getElement("SMS.YourSmsName")

# Send SMS
result = sms_element.sendMessage(
phoneList=["13800138000", "13900139000"],
params={"code": "123456"},
verifyTemplateCode="SMS_123456789"
)

Element Configuration​

e.json Configuration​

Configuration ItemTypeRequiredDescription
titlestringYesElement display name
typestringYesFixed value "SMS.Aliyun"
backendBundleEntrystringYesFixed value "."

Business Configuration File​

Configuration ItemTypeRequiredDescription
accessKeystringYesAlibaba Cloud AccessKey
accessSecretstringYesAlibaba Cloud AccessSecret
verifySignstringYesSMS signature, needs to be applied in Alibaba Cloud console

Methods​

sendMessage​

Send SMS interface, sends SMS messages by passing phone number list, template parameters, and template code.

Parameter Details​

Parameter NameTypeCorresponding Native TypeRequiredDescription
phoneListJitListlistYesPhone number list, each phone number in string format
paramsJitDictdictYesSMS template parameters, key-value pair format
verifyTemplateCodeStextstrYesAlibaba Cloud SMS template code, needs to be passed in extend parameter

Return Value​

Returns Alibaba Cloud SMS API response result object, containing sending status and related information.

Usage Example​

Basic Sending Example
# Send verification code SMS
result = sms_element.sendMessage(
phoneList=["13800138000"],
params={"code": "6789"},
verifyTemplateCode="SMS_123456789"
)
Batch Sending Example
# Batch send notification SMS
result = sms_element.sendMessage(
phoneList=["13800138000", "13900139000", "13700137000"],
params={"name": "张三", "event": "系统维护"},
verifyTemplateCode="SMS_987654321"
)
Multi-parameter Template Example
# Complex template parameters
result = sms_element.sendMessage(
phoneList=["13800138000"],
params={
"username": "用户001",
"amount": "100.00",
"time": "2024-01-15 10:30"
},
verifyTemplateCode="SMS_ORDER_NOTIFY"
)

Properties​

None

Advanced Features​

Error Handling​

Alibaba Cloud SMS element provides complete error handling mechanism, including the following predefined error codes:

Error Handling Example
try:
result = sms_element.sendMessage(
phoneList=["13800138000"],
params={"code": "1234"},
verifyTemplateCode="SMS_123456789"
)
except Exception as e:
# Error code: 46001 - Parameter missing or phone number list empty
# Error code: 46002 - SMS sending failed, Alibaba Cloud API returned error
# Error code: 46003 - SMS sending request failed
log.error(f"SMS sending failed: {e}")

Template Management​

Before use, you need to create SMS templates and signatures in Alibaba Cloud SMS service console:

Template Configuration Description
# 1. Create SMS signature in Alibaba Cloud console, get verifySign
# 2. Create SMS template, get template code
# 3. Template examples:
# Verification code template: Verification code ${code}, valid for 5 minutes.
# Notification template: Dear ${name}, ${event} will be conducted at ${time}.

# Use corresponding template code and parameters when sending
result = sms_element.sendMessage(
phoneList=["13800138000"],
params={"code": "123456"}, # Corresponds to ${code} in template
verifyTemplateCode="SMS_123456789" # Template code assigned by Alibaba Cloud
)