File length: 6954 # Platform Configuration - SMS Delivery Source: https://supertokens.com/docs/platform-configuration/sms-delivery ## Overview SuperTokens sends SMS in different authentication scenarios. The method applies to the `Passwordless` and `MFA` recipes. The following page shows you how to configure the SMS delivery method and adjust the content that gets sent to your users. ## Delivery methods ### Default method If you provide no configuration for SMS delivery, the backend SDK sends SMSs by talking to SuperTokens servers on `https://api.supertokens.com`. This applies to both self hosted and managed services. :::info Important - This is a free service and is globally rate limited. This is not suitable for production use. If you do not receive an SMS using this method, then the SDK prints the SMS content on the terminal. - We do not log / store any of the info sent to the API that sends out emails on behalf of your app. - You cannot customize the SMS content when using this method. If you want to customize the content, please see one of the other methods in this section. ::: ### Twilio Using this method, you can provide your own Twilio account details to the backend SDK, and the SMS is sent using those. ```tsx supertokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ Passwordless.init({ flowType: "USER_INPUT_CODE", contactMethod: "PHONE", // highlight-start smsDelivery: { service: new TwilioService({ twilioSettings: { accountSid: "...", authToken: "...", opts: { // optionally extra config to pass to Twilio client }, // give either from or messagingServiceSid from: "...", messagingServiceSid: "...", }, }) }, // highlight-end }), Session.init() ] }); ``` ```go supertokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ Passwordless.init({ flowType: "USER_INPUT_CODE", contactMethod: "PHONE", // highlight-start smsDelivery: { service: new SupertokensService("") }, // highlight-end }), Session.init() ] }); ``` ```go supertokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ Passwordless.init({ flowType: "USER_INPUT_CODE", contactMethod: "PHONE", // highlight-start smsDelivery: { override: (originalImplementation) => { return { ...originalImplementation, sendSms: async function ({ codeLifetime, // amount of time the code is alive for (in MS) phoneNumber, urlWithLinkCode, // magic link userInputCode, // OTP }) { // TODO: create and send SMS } } } }, // highlight-end }), Session.init() ] }); ``` ```go supertokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ Passwordless.init({ flowType: "USER_INPUT_CODE", contactMethod: "PHONE", smsDelivery: { service: new TwilioService({ // @ts-ignore twilioSettings: { /*...*/ }, // highlight-start override: (originalImplementation) => { return { ...originalImplementation, getContent: async function ({ isFirstFactor, codeLifetime, // amount of time the code is alive for (in MS) phoneNumber, urlWithLinkCode, // magic link userInputCode, // OTP }) { if (isFirstFactor) { // send some custom SMS content return { toPhoneNumber: phoneNumber, body: "SMS BODY" } } else { // for second factor, urlWithLinkCode will always be // undefined since we only support OTP based for second factor return { toPhoneNumber: phoneNumber, body: "SMS BODY" } } // You can even call the original implementation and // modify its content: /*let originalContent = await originalImplementation.getContent(input) originalContent.body = "My custom body"; return originalContent;*/ } } } // highlight-end }) } }), Session.init() ] }); ``` ```go supertokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ Passwordless.init({ flowType: "USER_INPUT_CODE", contactMethod: "PHONE", // highlight-start smsDelivery: { override: (originalImplementation) => { return { ...originalImplementation, sendSms: async function (input) { // TODO: before sending SMS await originalImplementation.sendSms(input) // TODO: after sending SMS } } } }, // highlight-end }), Session.init() ] }); ``` ```go