0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00
logto/packages/connector-twilio-sms
2022-08-01 15:02:50 +00:00
..
docs chore(connectors): config template md files to json files (#987) 2022-05-31 12:58:24 +08:00
src chore(phrases): add translation ko_KR (#1677) 2022-07-30 14:48:50 +00:00
CHANGELOG.md release: v1.0.0-beta.3 2022-08-01 15:02:50 +00:00
jest.config.ts chore(connectors): remove unused jest-matcher-specific-error in connector packages (#1024) 2022-06-02 12:03:11 +08:00
logo.svg feat(core): serve connector logo (#931) 2022-05-24 13:54:37 +08:00
package.json release: v1.0.0-beta.3 2022-08-01 15:02:50 +00:00
README.md docs(connector): twilio readme zh-CN (#1520) 2022-07-12 12:16:12 +00:00
tsconfig.base.json feat(connector-twilio-sms): add twilio sms connector (#881) 2022-05-20 09:56:16 +08:00
tsconfig.build.json feat(connector-twilio-sms): add twilio sms connector (#881) 2022-05-20 09:56:16 +08:00
tsconfig.json chore(connectors): remove unused jest-matcher-specific-error in connector packages (#1024) 2022-06-02 12:03:11 +08:00
tsconfig.test.json chore(core): make the i18n optional for connector metadata (#1711) 2022-08-01 09:58:34 +00:00

Twilio short message service connector

The official Logto connector for Twilio short message service.

Twilio 短信服务 Logto 官方连接器 中文文档

Table of contents

Get started

Twilio provides programmable communication tools for making and receiving phone calls, sending and receiving text messages, and other communication functions. We can send the "verification code" text messages through its web service APIs.

Register Twilio account

Create a new account on Twilio. (Jump to the next step if you already have one.)

Set up senders' phone numbers

Go to the Twilio console page and sign in with your Twilio account.

Purchase a phone number under "Phone Numbers" -> "Manage" -> "Buy a number".

Tip

Sometimes you may encounter the situation that SMS service is not supported in specific countries or areas. Pick a number from other regions to bypass.

Once we have a valid number claimed, nav to the "Messaging" -> "Services". Create a new Message Service by clicking on the button.

Give a friendly service name and choose Notify my users as our service purpose. Following the next step, choose Phone Number as Sender Type, and add the phone number we just claimed to this service as a sender.

Note

Each phone number can only be linked with one messaging service.

Get account credentials

We will need the API credentials to make the connector work. Let's begin from the Twilio console page.

Click on the "Account" menu in the top-right corner, then go to the "API keys & tokens" page to get your Account SID and Auth token.

Back to "Messaging" -> "Services" settings page starting from the sidebar, and find the Sid of your service.

Compose the connector JSON

Fill out the accountSID, authToken and fromMessagingServiceSID fields with Account SID, Auth token and Sid of the corresponding messaging service.

You can add multiple SMS connector templates for different cases. Here is an example of adding a single template:

  • Fill out the content field with arbitrary string-typed contents. Do not forget to leave {{code}} placeholder for random passcode.
  • Fill out the usageType field with either Register, SignIn or Test for different use cases.

Here is an example of Twilio SMS connector config JSON.

{
    "accountSID": "<your-account-sid>",
    "authToken": "<your-auth-token>",
    "fromMessagingServiceSID": "<messaging-service-sid>",
    "templates": [
        {
            "content": "<arbitrary-register-template-contents: your passcode is {{code}}>",
            "usageType": "Register"
        },
        {
            "content": "<arbitrary-sign-in-template-contents: your passcode is {{code}}>",
            "usageType": "SignIn"
        },
        {
            "content": "<arbitrary-test-template-contents: your passcode is {{code}}>",
            "usageType": "Test"
        }
    ]
}

Test Twilio SMS connector

You can enter a phone number and click on "Send" to see whether the settings can work before "Save and Done".

That's it. Don't forget to Enable connector in sign-in experience.

Config types

Name Type
accountSID string
authToken string
fromMessagingServiceSID string
templates Templates[]
Template Properties Type Enum values
content string N/A
usageType enum string 'Register' | 'SignIn' | 'Test'

Reference

Twilio 短信连接器

开始上手

Twilio 提供可编程的通信工具,用于拨打和接听电话、发送和接收文本信息以及其他通信功能。我们可以通过其网络服务 API 发送 "验证码" 文本信息。

创建 Twilio 帐号

Twilio 创建新帐号。(如果你已经有账号了请跳到下一步。)

设置 sender 号码

前往 Twilio 控制台 并登录 Twilio 账号。

依次进入 "Phone Numbers" -> "Manage" -> "Buy a number",购买电话号码。

小贴士

有时候你会碰到某些国家或区域的号码不支持短信服务的情况,挑选一个其他区域的号码来绕过该限制。

获取了有效号码之后,按照导航前往 "Messaging" -> "Services",点按 "Create Messaging Service" 按钮新建一个短信服务。

填写一个服务名称然后在服务用途选择 Notify my users

继续下一步,为 Sender Type 选择 Phone number 并把之前获取的手机号添加为这个发信服务的 sender

注意

每个号码只能绑定到唯一一个发信服务。

获取帐号凭据

我们需要获取 API 凭据来使得连接器正常工作。从 Twilio 控制台 开始获取密钥的流程。

点按页面右上角的 "Account" 菜单并前往 "API keys & tokens" 页面,通过验证后获取 Account SIDAuth token

通过侧边栏回到 "Messaging" -> "Services" 设置页面,找到发信服务的 Sid

编写连接器的 JSON

用发信服务中获取的 Account SIDAuth tokenSid 信息分别对应填写 accountSIDauthTokenfromMessagingServiceSID 栏。

你可以添加多个短信连接器的内容模板以应对不同的使用场景。这里我们以添加单个内容模板举例:

  • 用任意字符型内容填写 content 栏。不要忘了用 {{code}} 占位符为随机生成的验证码预留位置。
  • RegisterSignInTest 填入 usageType 栏以声明不同的使用场景。

这是一个 Twilio 短信服务连接器 JSON 配置的样例。

{
    "accountSID": "<your-account-sid>",
    "authToken": "<your-auth-token>",
    "fromMessagingServiceSID": "<messaging-service-sid>",
    "templates": [
        {
            "content": "<arbitrary-register-template-contents: your passcode is {{code}}>",
            "usageType": "Register"
        },
        {
            "content": "<arbitrary-sign-in-template-contents: your passcode is {{code}}>",
            "usageType": "SignIn"
        },
        {
            "content": "<arbitrary-test-template-contents: your passcode is {{code}}>",
            "usageType": "Test"
        }
    ]
}

测试 Twilio 短信连接器

你可以在「保存并完成」之前输入一个手机号码并点按「发送」来测试配置是否可以正常工作。

大功告成!快去 启用短信或邮件验证码登录 吧。

配置类型

名称 类型
accountSID string
authToken string
fromMessagingServiceSID string
templates Templates[]
模板属性 类型 枚举值
content string N/A
usageType enum string 'Register' | 'SignIn' | 'Test'

参考