k.utils.sms
SMS sending (multi-provider)
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API, auth/notification workflows | Provider credentials, signature, and approved template must be configured in Console SMS settings | Sending verification codes, order alerts, and international SMS |
k.utils.sms dispatches SMS messages using the provider configured in site Console SMS Settings. Approved templates and signatures must be set up with the corresponding provider.
Quick Start
k.api.post("sendCode", () => {
const ok = k.utils.sms.aliSMS.send("SMS_123456789", "13800138000", {
code: "493821"
})
return { sent: ok }
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
aliSMS.send(templateCode, phone, key, value) | Send Alibaba Cloud single-variable SMS (+86 optional for China numbers) | boolean |
aliSMS.send(templateCode, phone, bindings) | Send Alibaba Cloud multi-variable template SMS | boolean |
aliSMS.sendInternational(templateCode, phone, key, value) | Send Alibaba Cloud international SMS with international signature | boolean |
tencent.send(templateId, phone, parameters) | Send Tencent Cloud template SMS (pass {} or null if no args) | boolean |
chinaMobile.send(phoneOrList, content) | Send China Mobile SMS to one number or a list of numbers | boolean |
aliSMS
Alibaba Cloud SMS reads the Ali SMS settings from the site console. Domestic China numbers can omit +86; the runtime adds it automatically.
| Method | Description |
|---|---|
send(templateCode, phone, key, value) | Single-variable template |
send(templateCode, phone, bindings) | Multi-variable dictionary |
sendInternational(templateCode, phone, key, value) | International SMS |
| Parameter | Type | Required | Description |
|---|---|---|---|
templateCode | string | Yes | Alibaba Cloud SMS template code |
phone | string | Yes | Recipient phone number; China domestic numbers can omit +86 |
key | string | Required for single-var | Single template variable name |
value | string | Required for single-var | Single template variable value |
bindings | Record<string, any> | Required for multi-var | Multi-variable template parameter object |
Returns: boolean; returns true on success, and throws when settings are missing or the provider reports an error.
const ok = k.utils.sms.aliSMS.send(
"SMS_123456789",
"13800138000",
"code",
"493821"
)
return { sent: ok }Pass an object for templates with multiple variables:
const ok = k.utils.sms.aliSMS.send("SMS_ORDER_NOTICE", "13800138000", {
orderNo: "SO20260702001",
amount: "129.00"
})Use the configured international signature for international SMS:
k.utils.sms.aliSMS.sendInternational(
"SMS_GLOBAL_CODE",
"+14155550100",
"code",
"493821"
)tencent
Send Tencent Cloud template SMS; parameters is the template parameter object.
| Parameter | Type | Required | Description |
|---|---|---|---|
templateId | string | Yes | Tencent Cloud SMS template ID |
phone | string | Yes | Recipient phone number; China domestic numbers can omit +86 |
parameters | Record<string, any> | Yes | Template parameter object (pass {} or null for the 3rd argument when no parameters are needed); values are passed in enumeration order |
Returns: boolean; returns true when the provider status is Ok, and false otherwise (throws when Tencent SMS settings are missing).
const ok = k.utils.sms.tencent.send("1850001", "13800138000", {
code: "493821",
minutes: "5"
})
return { sent: ok }chinaMobile
Send SMS content via China Mobile to a single phone number or a list of phone numbers.
| Parameter | Type | Required | Description |
|---|---|---|---|
toPhoneNumber / toPhoneNumbers | string / string[] | Yes | Single phone number or array of phone numbers |
content | string | Yes | SMS message body |
Returns: boolean; returns true on success, and throws when the provider fails.
k.utils.sms.chinaMobile.send("13800138000", "Your verification code is 493821.")Send to multiple numbers:
k.utils.sms.chinaMobile.send(
["13800138000", "13900139000"],
"Your order has been shipped."
)TypeScript Definitions
interface SMS {
aliSMS: Ali;
tencent: Tencent;
chinaMobile: ChinaMobile;
}
interface Ali {
send(templateCode: string, ToPhoneNumber: string, bindingkey: string, bindingvalue: string): boolean;
send(templateCode: string, ToPhoneNumber: string, bindings: Record<string, any>): boolean;
sendInternational(templateCode: string, ToPhoneNumber: string, bindingkey: string, bindingvalue: string): boolean;
}
interface Tencent {
send(templateId: string, ToPhoneNumber: string, Parameters: any): boolean;
}
interface ChinaMobile {
send(toPhoneNumbers: string[], content: string): boolean;
send(toPhoneNumber: string, content: string): boolean;
}