@@ -28,13 +28,16 @@ export const sendSms = internalAction({
2828
2929### Twilio Phone Number
3030
31- Create a Twilio account and, if you haven't already, create a [ Twilio Phone Number] ( https://www.twilio.com/docs/phone-numbers ) .
31+ Create a Twilio account and, if you haven't already, create a
32+ [ Twilio Phone Number] ( https://www.twilio.com/docs/phone-numbers ) .
3233
33- Note the ** Phone Number SID** of the phone number you'll be using, you'll need it in a moment.
34+ Note the ** Phone Number SID** of the phone number you'll be using, you'll need
35+ it in a moment.
3436
3537### Convex App
3638
37- You'll need a Convex App to use the component. Follow any of the [ Convex quickstarts] ( https://docs.convex.dev/home ) to set one up.
39+ You'll need a Convex App to use the component. Follow any of the
40+ [ Convex quickstarts] ( https://docs.convex.dev/home ) to set one up.
3841
3942## Installation
4043
@@ -44,12 +47,13 @@ Install the component package:
4447npm install @convex - dev / twilio
4548```
4649
47- Create a ` convex.config.ts ` file in your app's ` convex/ ` folder and install the component by calling ` use ` :
50+ Create a ` convex.config.ts ` file in your app's ` convex/ ` folder and install the
51+ component by calling ` use ` :
4852
4953``` ts
5054// convex/convex.config.ts
5155import { defineApp } from " convex/server" ;
52- import twilio from " @convex-dev/twilio/convex.config" ;
56+ import twilio from " @convex-dev/twilio/convex.config.js " ;
5357
5458const app = defineApp ();
5559app .use (twilio );
@@ -78,7 +82,8 @@ export const twilio = new Twilio(components.twilio, {
7882});
7983```
8084
81- Register Twilio webhook handlers by creating an ` http.ts ` file in your ` convex/ ` folder and use the client you've exported above:
85+ Register Twilio webhook handlers by creating an ` http.ts ` file in your ` convex/ `
86+ folder and use the client you've exported above:
8287
8388``` ts
8489// http.ts
@@ -110,21 +115,30 @@ export const sendSms = internalAction({
110115});
111116```
112117
113- By querying the message (see [ below] ( #querying-messages ) ) you can check for the status ([ Twilio Statuses] ( https://www.twilio.com/docs/messaging/api/message-resource#message-status-values ) ). The component subscribes to status updates and writes the most up-to-date status into the database.
118+ By querying the message (see [ below] ( #querying-messages ) ) you can check for the
119+ status
120+ ([ Twilio Statuses] ( https://www.twilio.com/docs/messaging/api/message-resource#message-status-values ) ).
121+ The component subscribes to status updates and writes the most up-to-date status
122+ into the database.
114123
115124## Receiving Messages
116125
117- To receive messages, you will associate a webhook handler provided by the component with the Twilio phone number you'd like to use.
126+ To receive messages, you will associate a webhook handler provided by the
127+ component with the Twilio phone number you'd like to use.
118128
119- ` twilio.registerRoutes ` registers two webhook HTTP handlers in your your Convex app's deployment:
129+ ` twilio.registerRoutes ` registers two webhook HTTP handlers in your your Convex
130+ app's deployment:
120131
121- - ` YOUR_CONVEX_SITE_URL/twilio/message-status ` - capture and store delivery status of messages you ** send** .
122- - ` YOUR_CONVEX_SITE_URL/twilio/incoming-message ` - capture and store messages ** sent to** your Twilio phone number.
132+ - ` YOUR_CONVEX_SITE_URL/twilio/message-status ` - capture and store delivery
133+ status of messages you ** send** .
134+ - ` YOUR_CONVEX_SITE_URL/twilio/incoming-message ` - capture and store messages
135+ ** sent to** your Twilio phone number.
123136
124- Note: You may pass a custom ` httpPrefix ` to ` Twilio ` if you want to
125- route Twilio endpoints somewhere other than ` YOUR_CONVEX_SITE_URL/twilio/* ` .
137+ Note: You may pass a custom ` httpPrefix ` to ` Twilio ` if you want to route Twilio
138+ endpoints somewhere other than ` YOUR_CONVEX_SITE_URL/twilio/* ` .
126139
127- For instance, to route to ` YOUR_CONVEX_SITE_URL/custom-twilio/message-status ` , set:
140+ For instance, to route to ` YOUR_CONVEX_SITE_URL/custom-twilio/message-status ` ,
141+ set:
128142
129143``` ts
130144export const twilio = new Twilio (components .twilio , {
@@ -134,9 +148,12 @@ export const twilio = new Twilio(components.twilio, {
134148
135149You can associate it with your Twilio phone number in two ways:
136150
137- 1 . Using the [ Twilio console] ( https://console.twilio.com/ ) in the "Configure" tab of the phone number, under "Messaging Configuration" -> "A messsage comes in" -> "URL".
151+ 1 . Using the [ Twilio console] ( https://console.twilio.com/ ) in the "Configure"
152+ tab of the phone number, under "Messaging Configuration" -> "A messsage comes
153+ in" -> "URL".
138154
139- 2 . By calling ` registerIncomingSmsHandler ` exposed by the component client, passing it the phone number's SID:
155+ 2 . By calling ` registerIncomingSmsHandler ` exposed by the component client,
156+ passing it the phone number's SID:
140157
141158``` ts
142159export const registerIncomingSmsHandler = internalAction ({
@@ -149,9 +166,11 @@ export const registerIncomingSmsHandler = internalAction({
149166});
150167```
151168
152- Once it is configured, incoming messages will be captured by the component and logged in the ` messages ` table.
169+ Once it is configured, incoming messages will be captured by the component and
170+ logged in the ` messages ` table.
153171
154- You can execute your own logic upon receiving an incoming message, by providing a callback when instantiating the Twilio Component client:
172+ You can execute your own logic upon receiving an incoming message, by providing
173+ a callback when instantiating the Twilio Component client:
155174
156175``` ts
157176// convex/example.ts
@@ -181,7 +200,8 @@ but you can replay them manually from the Twilio "Error logs" console.
181200
182201To list all the mssages, use the ` list ` method in your Convex function.
183202
184- To list all the incoming or outgoing messages, use ` listIncoming ` and ` listOutgoing ` methods:
203+ To list all the incoming or outgoing messages, use ` listIncoming ` and
204+ ` listOutgoing ` methods:
185205
186206``` ts
187207// convex/messages.ts
0 commit comments