Skip to content

k.utils.sms ​

SMS sending (multi-provider)

Execution ContextPrerequisitesTypical Use
KScript API, auth/notification workflowsProvider credentials, signature, and approved template must be configured in Console SMS settingsSending 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 ​

js
k.api.post("sendCode", () => {
  const ok = k.utils.sms.aliSMS.send("SMS_123456789", "13800138000", {
    code: "493821"
  })
  return { sent: ok }
})

Quick Reference ​

Method / PropertyDescriptionReturns
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 SMSboolean
aliSMS.sendInternational(templateCode, phone, key, value)Send Alibaba Cloud international SMS with international signatureboolean
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 numbersboolean

aliSMS ​

Alibaba Cloud SMS reads the Ali SMS settings from the site console. Domestic China numbers can omit +86; the runtime adds it automatically.

MethodDescription
send(templateCode, phone, key, value)Single-variable template
send(templateCode, phone, bindings)Multi-variable dictionary
sendInternational(templateCode, phone, key, value)International SMS
ParameterTypeRequiredDescription
templateCodestringYesAlibaba Cloud SMS template code
phonestringYesRecipient phone number; China domestic numbers can omit +86
keystringRequired for single-varSingle template variable name
valuestringRequired for single-varSingle template variable value
bindingsRecord<string, any>Required for multi-varMulti-variable template parameter object

Returns: boolean; returns true on success, and throws when settings are missing or the provider reports an error.

js
const ok = k.utils.sms.aliSMS.send(
  "SMS_123456789",
  "13800138000",
  "code",
  "493821"
)

return { sent: ok }

Pass an object for templates with multiple variables:

js
const ok = k.utils.sms.aliSMS.send("SMS_ORDER_NOTICE", "13800138000", {
  orderNo: "SO20260702001",
  amount: "129.00"
})

Use the configured international signature for international SMS:

js
k.utils.sms.aliSMS.sendInternational(
  "SMS_GLOBAL_CODE",
  "+14155550100",
  "code",
  "493821"
)

tencent ​

Send Tencent Cloud template SMS; parameters is the template parameter object.

ParameterTypeRequiredDescription
templateIdstringYesTencent Cloud SMS template ID
phonestringYesRecipient phone number; China domestic numbers can omit +86
parametersRecord<string, any>YesTemplate 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).

js
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.

ParameterTypeRequiredDescription
toPhoneNumber / toPhoneNumbersstring / string[]YesSingle phone number or array of phone numbers
contentstringYesSMS message body

Returns: boolean; returns true on success, and throws when the provider fails.

js
k.utils.sms.chinaMobile.send("13800138000", "Your verification code is 493821.")

Send to multiple numbers:

js
k.utils.sms.chinaMobile.send(
  ["13800138000", "13900139000"],
  "Your order has been shipped."
)

TypeScript Definitions ​

ts
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;
}