@@ -30,6 +30,7 @@ const client = new SentDm({
3030await client .messages .sendToPhone ({
3131 phoneNumber: ' +1234567890' ,
3232 templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
33+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
3334});
3435```
3536
@@ -49,6 +50,7 @@ const client = new SentDm({
4950const params: SentDm .MessageSendToPhoneParams = {
5051 phoneNumber: ' +1234567890' ,
5152 templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
53+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
5254};
5355await client .messages .sendToPhone (params );
5456```
@@ -64,7 +66,11 @@ a subclass of `APIError` will be thrown:
6466<!-- prettier-ignore -->
6567``` ts
6668const response = await client .messages
67- .sendToPhone ({ phoneNumber: ' +1234567890' , templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' })
69+ .sendToPhone ({
70+ phoneNumber: ' +1234567890' ,
71+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
72+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
73+ })
6874 .catch (async (err ) => {
6975 if (err instanceof SentDm .APIError ) {
7076 console .log (err .status ); // 400
@@ -105,7 +111,11 @@ const client = new SentDm({
105111});
106112
107113// Or, configure per-request:
108- await client .messages .sendToPhone ({ phoneNumber: ' +1234567890' , templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' }, {
114+ await client .messages .sendToPhone ({
115+ phoneNumber: ' +1234567890' ,
116+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
117+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
118+ }, {
109119 maxRetries: 5 ,
110120});
111121```
@@ -122,7 +132,11 @@ const client = new SentDm({
122132});
123133
124134// Override per-request:
125- await client .messages .sendToPhone ({ phoneNumber: ' +1234567890' , templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' }, {
135+ await client .messages .sendToPhone ({
136+ phoneNumber: ' +1234567890' ,
137+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
138+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
139+ }, {
126140 timeout: 5 * 1000 ,
127141});
128142```
@@ -146,13 +160,21 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
146160const client = new SentDm ();
147161
148162const response = await client .messages
149- .sendToPhone ({ phoneNumber: ' +1234567890' , templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' })
163+ .sendToPhone ({
164+ phoneNumber: ' +1234567890' ,
165+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
166+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
167+ })
150168 .asResponse ();
151169console .log (response .headers .get (' X-My-Header' ));
152170console .log (response .statusText ); // access the underlying Response object
153171
154172const { data : result, response : raw } = await client .messages
155- .sendToPhone ({ phoneNumber: ' +1234567890' , templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' })
173+ .sendToPhone ({
174+ phoneNumber: ' +1234567890' ,
175+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
176+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
177+ })
156178 .withResponse ();
157179console .log (raw .headers .get (' X-My-Header' ));
158180console .log (result );
0 commit comments