11# Sent Dm TypeScript API Library
22
3- [ ![ NPM version] ( < https://img.shields.io/npm/v/@sentdm/sentdm .svg?label=npm%20(stable) > )] ( https://npmjs.org/package/@sentdm/sentdm ) ![ npm bundle size] ( https://img.shields.io/bundlephobia/minzip/@sentdm/sentdm )
3+ [ ![ NPM version] ( < https://img.shields.io/npm/v/sent-dm .svg?label=npm%20(stable) > )] ( https://npmjs.org/package/sent-dm ) ![ npm bundle size] ( https://img.shields.io/bundlephobia/minzip/sent-dm )
44
55This library provides convenient access to the Sent Dm REST API from server-side TypeScript or JavaScript.
66
@@ -11,27 +11,35 @@ It is generated with [Stainless](https://www.stainless.com/).
1111## Installation
1212
1313``` sh
14- npm install @sentdm/sentdm
14+ npm install git+ssh://git@github.com:stainless-sdks/sent-dm-typescript.git
1515```
1616
17+ > [ !NOTE]
18+ > Once this package is [ published to npm] ( https://www.stainless.com/docs/guides/publish ) , this will become: ` npm install sent-dm `
19+
1720## Usage
1821
1922The full API of this library can be found in [ api.md] ( api.md ) .
2023
2124<!-- prettier-ignore -->
2225``` js
23- import SentDm from ' @sentdm/sentdm ' ;
26+ import SentDm from ' sent-dm ' ;
2427
2528const client = new SentDm ({
2629 apiKey: process .env [' SENT_DM_API_KEY' ], // This is the default and can be omitted
27- senderID: process .env [' SENT_DM_SENDER_ID' ], // This is the default and can be omitted
2830});
2931
30- await client .messages .sendToPhone ({
31- phoneNumber: ' +1234567890' ,
32- templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
33- templateVariables: { name: ' John Doe' , order_id: ' 12345' },
32+ const response = await client .messages .send ({
33+ channel: [' sms' , ' whatsapp' ],
34+ template: {
35+ id: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
36+ name: ' order_confirmation' ,
37+ parameters: { name: ' John Doe' , order_id: ' 12345' },
38+ },
39+ to: [' +14155551234' , ' +14155555678' ],
3440});
41+
42+ console .log (response .data );
3543```
3644
3745### Request & Response types
@@ -40,19 +48,22 @@ This library includes TypeScript definitions for all request params and response
4048
4149<!-- prettier-ignore -->
4250``` ts
43- import SentDm from ' @sentdm/sentdm ' ;
51+ import SentDm from ' sent-dm ' ;
4452
4553const client = new SentDm ({
4654 apiKey: process .env [' SENT_DM_API_KEY' ], // This is the default and can be omitted
47- senderID: process .env [' SENT_DM_SENDER_ID' ], // This is the default and can be omitted
4855});
4956
50- const params: SentDm .MessageSendToPhoneParams = {
51- phoneNumber: ' +1234567890' ,
52- templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
53- templateVariables: { name: ' John Doe' , order_id: ' 12345' },
57+ const params: SentDm .MessageSendParams = {
58+ channel: [' sms' ],
59+ template: {
60+ id: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
61+ name: ' order_confirmation' ,
62+ parameters: { name: ' John Doe' , order_id: ' 12345' },
63+ },
64+ to: [' +14155551234' ],
5465};
55- await client .messages .sendToPhone (params );
66+ const response : SentDm . MessageSendResponse = await client .messages .send (params );
5667```
5768
5869Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -66,10 +77,14 @@ a subclass of `APIError` will be thrown:
6677<!-- prettier-ignore -->
6778``` ts
6879const response = await client .messages
69- .sendToPhone ({
70- phoneNumber: ' +1234567890' ,
71- templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
72- templateVariables: { name: ' John Doe' , order_id: ' 12345' },
80+ .send ({
81+ channel: [' sms' ],
82+ template: {
83+ id: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
84+ name: ' order_confirmation' ,
85+ parameters: { name: ' John Doe' , order_id: ' 12345' },
86+ },
87+ to: [' +14155551234' ],
7388 })
7489 .catch (async (err ) => {
7590 if (err instanceof SentDm .APIError ) {
@@ -111,10 +126,14 @@ const client = new SentDm({
111126});
112127
113128// Or, configure per-request:
114- await client .messages .sendToPhone ({
115- phoneNumber: ' +1234567890' ,
116- templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
117- templateVariables: { name: ' John Doe' , order_id: ' 12345' },
129+ await client .messages .send ({
130+ channel: [' sms' ],
131+ template: {
132+ id: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
133+ name: ' order_confirmation' ,
134+ parameters: { name: ' John Doe' , order_id: ' 12345' },
135+ },
136+ to: [' +14155551234' ],
118137}, {
119138 maxRetries: 5 ,
120139});
@@ -132,10 +151,14 @@ const client = new SentDm({
132151});
133152
134153// Override per-request:
135- await client .messages .sendToPhone ({
136- phoneNumber: ' +1234567890' ,
137- templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
138- templateVariables: { name: ' John Doe' , order_id: ' 12345' },
154+ await client .messages .send ({
155+ channel: [' sms' ],
156+ template: {
157+ id: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
158+ name: ' order_confirmation' ,
159+ parameters: { name: ' John Doe' , order_id: ' 12345' },
160+ },
161+ to: [' +14155551234' ],
139162}, {
140163 timeout: 5 * 1000 ,
141164});
@@ -160,24 +183,32 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
160183const client = new SentDm ();
161184
162185const response = await client .messages
163- .sendToPhone ({
164- phoneNumber: ' +1234567890' ,
165- templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
166- templateVariables: { name: ' John Doe' , order_id: ' 12345' },
186+ .send ({
187+ channel: [' sms' ],
188+ template: {
189+ id: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
190+ name: ' order_confirmation' ,
191+ parameters: { name: ' John Doe' , order_id: ' 12345' },
192+ },
193+ to: [' +14155551234' ],
167194 })
168195 .asResponse ();
169196console .log (response .headers .get (' X-My-Header' ));
170197console .log (response .statusText ); // access the underlying Response object
171198
172- const { data : result, response : raw } = await client .messages
173- .sendToPhone ({
174- phoneNumber: ' +1234567890' ,
175- templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
176- templateVariables: { name: ' John Doe' , order_id: ' 12345' },
199+ const { data : response, response : raw } = await client .messages
200+ .send ({
201+ channel: [' sms' ],
202+ template: {
203+ id: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
204+ name: ' order_confirmation' ,
205+ parameters: { name: ' John Doe' , order_id: ' 12345' },
206+ },
207+ to: [' +14155551234' ],
177208 })
178209 .withResponse ();
179210console .log (raw .headers .get (' X-My-Header' ));
180- console .log (result );
211+ console .log (response . data );
181212```
182213
183214### Logging
@@ -194,7 +225,7 @@ The log level can be configured in two ways:
1942252 . Using the ` logLevel ` client option (overrides the environment variable if set)
195226
196227``` ts
197- import SentDm from ' @sentdm/sentdm ' ;
228+ import SentDm from ' sent-dm ' ;
198229
199230const client = new SentDm ({
200231 logLevel: ' debug' , // Show all log messages
@@ -222,7 +253,7 @@ When providing a custom logger, the `logLevel` option still controls which messa
222253below the configured level will not be sent to your logger.
223254
224255``` ts
225- import SentDm from ' @sentdm/sentdm ' ;
256+ import SentDm from ' sent-dm ' ;
226257import pino from ' pino' ;
227258
228259const logger = pino ();
@@ -257,7 +288,7 @@ parameter. This library doesn't validate at runtime that the request matches the
257288send will be sent as-is.
258289
259290``` ts
260- client .messages .sendToPhone ({
291+ client .messages .send ({
261292 // ...
262293 // @ts-expect-error baz is not yet public
263294 baz: ' undocumented option' ,
@@ -291,7 +322,7 @@ globalThis.fetch = fetch;
291322Or pass it to the client:
292323
293324``` ts
294- import SentDm from ' @sentdm/sentdm ' ;
325+ import SentDm from ' sent-dm ' ;
295326import fetch from ' my-fetch' ;
296327
297328const client = new SentDm ({ fetch });
@@ -302,7 +333,7 @@ const client = new SentDm({ fetch });
302333If you want to set custom ` fetch ` options without overriding the ` fetch ` function, you can provide a ` fetchOptions ` object when instantiating the client or making a request. (Request-specific options override client options.)
303334
304335``` ts
305- import SentDm from ' @sentdm/sentdm ' ;
336+ import SentDm from ' sent-dm ' ;
306337
307338const client = new SentDm ({
308339 fetchOptions: {
@@ -319,7 +350,7 @@ options to requests:
319350<img src =" https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/node.svg " align =" top " width =" 18 " height =" 21 " > ** Node** <sup >[[ docs] ( https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md#example---proxyagent-with-fetch )] </sup >
320351
321352``` ts
322- import SentDm from ' @sentdm/sentdm ' ;
353+ import SentDm from ' sent-dm ' ;
323354import * as undici from ' undici' ;
324355
325356const proxyAgent = new undici .ProxyAgent (' http://localhost:8888' );
@@ -333,7 +364,7 @@ const client = new SentDm({
333364<img src =" https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/bun.svg " align =" top " width =" 18 " height =" 21 " > ** Bun** <sup >[[ docs] ( https://bun.sh/guides/http/proxy )] </sup >
334365
335366``` ts
336- import SentDm from ' @sentdm/sentdm ' ;
367+ import SentDm from ' sent-dm ' ;
337368
338369const client = new SentDm ({
339370 fetchOptions: {
@@ -345,7 +376,7 @@ const client = new SentDm({
345376<img src =" https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/deno.svg " align =" top " width =" 18 " height =" 21 " > ** Deno** <sup >[[ docs] ( https://docs.deno.com/api/deno/~/Deno.createHttpClient )] </sup >
346377
347378``` ts
348- import SentDm from ' npm:@sentdm/sentdm ' ;
379+ import SentDm from ' npm:sent-dm ' ;
349380
350381const httpClient = Deno .createHttpClient ({ proxy: { url: ' http://localhost:8888' } });
351382const client = new SentDm ({
@@ -367,7 +398,7 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con
367398
368399We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
369400
370- We are keen for your feedback; please open an [ issue] ( https://www.github.com/sentdm /sent-dm-typescript/issues ) with questions, bugs, or suggestions.
401+ We are keen for your feedback; please open an [ issue] ( https://www.github.com/stainless-sdks /sent-dm-typescript/issues ) with questions, bugs, or suggestions.
371402
372403## Requirements
373404
0 commit comments