@@ -18,17 +18,13 @@ type SendSmsContext = {
1818 } ;
1919} ;
2020
21- type SmsCapturePayload = {
21+ type SmsDevMessagePayload = {
2222 to : string ;
2323 from : string ;
24- text : string ;
25- type : SmsType ;
26- metadata : {
27- userId : string | null ;
28- } ;
24+ body : string ;
2925} ;
3026
31- const DEFAULT_CAPTURE_API_URL = 'http://localhost:8091 ' ;
27+ const DEFAULT_SMS_DEV_API_URL = 'http://localhost:4001 ' ;
3228const DEFAULT_SMS_FROM = 'Constructive' ;
3329
3430function parseBoolean ( value : string | undefined ) : boolean | undefined {
@@ -57,7 +53,7 @@ function normalizePhone(params: SendSmsParams): string | null {
5753 return `${ params . phone_cc ?? '' } ${ params . phone_number } ` . replace ( / [ \s ( ) - ] / g, '' ) ;
5854}
5955
60- function buildCapturePayload ( params : SendSmsParams , env : SendSmsContext [ 'env' ] ) : SmsCapturePayload {
56+ function buildSmsDevPayload ( params : SendSmsParams , env : SendSmsContext [ 'env' ] ) : SmsDevMessagePayload {
6157 if ( ! params . sms_type ) {
6258 throw new Error ( 'Missing required field: sms_type' ) ;
6359 }
@@ -78,16 +74,12 @@ function buildCapturePayload(params: SendSmsParams, env: SendSmsContext['env']):
7874 return {
7975 to : phone ,
8076 from : env . SMS_FROM || DEFAULT_SMS_FROM ,
81- text : `Your verification code is ${ params . code } ` ,
82- type : params . sms_type ,
83- metadata : {
84- userId : params . user_id ?? null ,
85- } ,
77+ body : `Your verification code is ${ params . code } ` ,
8678 } ;
8779}
8880
8981async function sendSms ( params : SendSmsParams , context : SendSmsContext ) {
90- const payload = buildCapturePayload ( params , context . env ) ;
82+ const payload = buildSmsDevPayload ( params , context . env ) ;
9183 const isDryRun = parseBoolean ( context . env . SMS_SEND_DRY_RUN ) ?? false ;
9284
9385 context . log . info ( '[send-sms] Processing request' , {
@@ -103,8 +95,8 @@ async function sendSms(params: SendSmsParams, context: SendSmsContext) {
10395 } ;
10496 }
10597
106- const captureApiUrl = context . env . SMS_CAPTURE_API_URL || DEFAULT_CAPTURE_API_URL ;
107- const response = await fetch ( `${ captureApiUrl } /messages` , {
98+ const smsDevApiUrl = context . env . SMS_DEV_API_URL || DEFAULT_SMS_DEV_API_URL ;
99+ const response = await fetch ( `${ smsDevApiUrl } /v1 /messages` , {
108100 method : 'POST' ,
109101 headers : {
110102 'content-type' : 'application/json' ,
@@ -113,7 +105,7 @@ async function sendSms(params: SendSmsParams, context: SendSmsContext) {
113105 } ) ;
114106
115107 if ( ! response . ok ) {
116- throw new Error ( `SMS capture API error: ${ response . status } ` ) ;
108+ throw new Error ( `SMS dev API error: ${ response . status } ` ) ;
117109 }
118110
119111 return {
0 commit comments