@@ -30,17 +30,21 @@ from sent_dm import SentDm
3030
3131client = SentDm(
3232 api_key = os.environ.get(" SENT_DM_API_KEY" ), # This is the default and can be omitted
33- sender_id = os.environ.get(" SENT_DM_SENDER_ID" ), # This is the default and can be omitted
3433)
3534
36- client.messages.send_to_phone(
37- phone_number = " +1234567890" ,
38- template_id = " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
39- template_variables = {
40- " name" : " John Doe" ,
41- " order_id" : " 12345" ,
35+ response = client.messages.send(
36+ channel = [" sms" , " whatsapp" ],
37+ template = {
38+ " id" : " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
39+ " name" : " order_confirmation" ,
40+ " parameters" : {
41+ " name" : " John Doe" ,
42+ " order_id" : " 12345" ,
43+ },
4244 },
45+ to = [" +14155551234" , " +14155555678" ],
4346)
47+ print (response.data)
4448```
4549
4650While you can provide an ` api_key ` keyword argument,
@@ -59,19 +63,23 @@ from sent_dm import AsyncSentDm
5963
6064client = AsyncSentDm(
6165 api_key = os.environ.get(" SENT_DM_API_KEY" ), # This is the default and can be omitted
62- sender_id = os.environ.get(" SENT_DM_SENDER_ID" ), # This is the default and can be omitted
6366)
6467
6568
6669async def main () -> None :
67- await client.messages.send_to_phone(
68- phone_number = " +1234567890" ,
69- template_id = " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
70- template_variables = {
71- " name" : " John Doe" ,
72- " order_id" : " 12345" ,
70+ response = await client.messages.send(
71+ channel = [" sms" , " whatsapp" ],
72+ template = {
73+ " id" : " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
74+ " name" : " order_confirmation" ,
75+ " parameters" : {
76+ " name" : " John Doe" ,
77+ " order_id" : " 12345" ,
78+ },
7379 },
80+ to = [" +14155551234" , " +14155555678" ],
7481 )
82+ print (response.data)
7583
7684
7785asyncio.run(main())
@@ -102,17 +110,21 @@ from sent_dm import AsyncSentDm
102110async def main () -> None :
103111 async with AsyncSentDm(
104112 api_key = os.environ.get(" SENT_DM_API_KEY" ), # This is the default and can be omitted
105- sender_id = os.environ.get(" SENT_DM_SENDER_ID" ), # This is the default and can be omitted
106113 http_client = DefaultAioHttpClient(),
107114 ) as client:
108- await client.messages.send_to_phone(
109- phone_number = " +1234567890" ,
110- template_id = " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
111- template_variables = {
112- " name" : " John Doe" ,
113- " order_id" : " 12345" ,
115+ response = await client.messages.send(
116+ channel = [" sms" , " whatsapp" ],
117+ template = {
118+ " id" : " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
119+ " name" : " order_confirmation" ,
120+ " parameters" : {
121+ " name" : " John Doe" ,
122+ " order_id" : " 12345" ,
123+ },
114124 },
125+ to = [" +14155551234" , " +14155555678" ],
115126 )
127+ print (response.data)
116128
117129
118130asyncio.run(main())
@@ -136,61 +148,17 @@ from sent_dm import SentDm
136148
137149client = SentDm()
138150
139- template_response_v2 = client.templates.create(
140- definition = {
141- " body" : {
142- " multi_channel" : {
143- " template" : " Hello {{ 1:variable}} , thank you for joining our service. We're excited to help you with your messaging needs!" ,
144- " type" : None ,
145- " variables" : [
146- {
147- " id" : 1 ,
148- " name" : " customerName" ,
149- " props" : {
150- " alt" : None ,
151- " media_type" : None ,
152- " sample" : " John Doe" ,
153- " short_url" : None ,
154- " url" : None ,
155- " variable_type" : " text" ,
156- },
157- " type" : " variable" ,
158- }
159- ],
160- },
161- " sms" : {},
162- " whatsapp" : {},
163- },
164- " authentication_config" : {},
165- " buttons" : [{}],
166- " definition_version" : " 1.0" ,
167- " footer" : {
168- " template" : " Best regards, The SentDM Team" ,
169- " type" : " text" ,
170- " variables" : [{}],
171- },
172- " header" : {
173- " template" : " Welcome to {{ 1:variable}} !" ,
174- " type" : " text" ,
175- " variables" : [
176- {
177- " id" : 1 ,
178- " name" : " companyName" ,
179- " props" : {
180- " alt" : None ,
181- " media_type" : None ,
182- " sample" : " SentDM" ,
183- " short_url" : None ,
184- " url" : None ,
185- " variable_type" : " text" ,
186- },
187- " type" : " variable" ,
188- }
189- ],
151+ response = client.messages.send(
152+ template = {
153+ " id" : " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
154+ " name" : " order_confirmation" ,
155+ " parameters" : {
156+ " name" : " John Doe" ,
157+ " order_id" : " 12345" ,
190158 },
191159 },
192160)
193- print (template_response_v2.definition )
161+ print (response.template )
194162```
195163
196164## Handling errors
@@ -209,13 +177,17 @@ from sent_dm import SentDm
209177client = SentDm()
210178
211179try :
212- client.messages.send_to_phone(
213- phone_number = " +1234567890" ,
214- template_id = " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
215- template_variables = {
216- " name" : " John Doe" ,
217- " order_id" : " 12345" ,
180+ client.messages.send(
181+ channel = [" sms" ],
182+ template = {
183+ " id" : " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
184+ " name" : " order_confirmation" ,
185+ " parameters" : {
186+ " name" : " John Doe" ,
187+ " order_id" : " 12345" ,
188+ },
218189 },
190+ to = [" +14155551234" ],
219191 )
220192except sent_dm.APIConnectionError as e:
221193 print (" The server could not be reached" )
@@ -259,13 +231,17 @@ client = SentDm(
259231)
260232
261233# Or, configure per-request:
262- client.with_options(max_retries = 5 ).messages.send_to_phone(
263- phone_number = " +1234567890" ,
264- template_id = " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
265- template_variables = {
266- " name" : " John Doe" ,
267- " order_id" : " 12345" ,
234+ client.with_options(max_retries = 5 ).messages.send(
235+ channel = [" sms" ],
236+ template = {
237+ " id" : " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
238+ " name" : " order_confirmation" ,
239+ " parameters" : {
240+ " name" : " John Doe" ,
241+ " order_id" : " 12345" ,
242+ },
268243 },
244+ to = [" +14155551234" ],
269245)
270246```
271247
@@ -289,13 +265,17 @@ client = SentDm(
289265)
290266
291267# Override per-request:
292- client.with_options(timeout = 5.0 ).messages.send_to_phone(
293- phone_number = " +1234567890" ,
294- template_id = " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
295- template_variables = {
296- " name" : " John Doe" ,
297- " order_id" : " 12345" ,
268+ client.with_options(timeout = 5.0 ).messages.send(
269+ channel = [" sms" ],
270+ template = {
271+ " id" : " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
272+ " name" : " order_confirmation" ,
273+ " parameters" : {
274+ " name" : " John Doe" ,
275+ " order_id" : " 12345" ,
276+ },
298277 },
278+ to = [" +14155551234" ],
299279)
300280```
301281
@@ -337,18 +317,22 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
337317from sent_dm import SentDm
338318
339319client = SentDm()
340- response = client.messages.with_raw_response.send_to_phone(
341- phone_number = " +1234567890" ,
342- template_id = " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
343- template_variables = {
344- " name" : " John Doe" ,
345- " order_id" : " 12345" ,
320+ response = client.messages.with_raw_response.send(
321+ channel = [" sms" ],
322+ template = {
323+ " id" : " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
324+ " name" : " order_confirmation" ,
325+ " parameters" : {
326+ " name" : " John Doe" ,
327+ " order_id" : " 12345" ,
328+ },
346329 },
330+ to = [" +14155551234" ],
347331)
348332print (response.headers.get(' X-My-Header' ))
349333
350- message = response.parse() # get the object that `messages.send_to_phone ()` would have returned
351- print (message)
334+ message = response.parse() # get the object that `messages.send ()` would have returned
335+ print (message.data )
352336```
353337
354338These methods return an [ ` APIResponse ` ] ( https://github.com/sentdm/sent-dm-python/tree/main/src/sent_dm/_response.py ) object.
@@ -362,13 +346,17 @@ The above interface eagerly reads the full response body when you make the reque
362346To stream the response body, use ` .with_streaming_response ` instead, which requires a context manager and only reads the response body once you call ` .read() ` , ` .text() ` , ` .json() ` , ` .iter_bytes() ` , ` .iter_text() ` , ` .iter_lines() ` or ` .parse() ` . In the async client, these are async methods.
363347
364348``` python
365- with client.messages.with_streaming_response.send_to_phone(
366- phone_number = " +1234567890" ,
367- template_id = " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
368- template_variables = {
369- " name" : " John Doe" ,
370- " order_id" : " 12345" ,
349+ with client.messages.with_streaming_response.send(
350+ channel = [" sms" ],
351+ template = {
352+ " id" : " 7ba7b820-9dad-11d1-80b4-00c04fd430c8" ,
353+ " name" : " order_confirmation" ,
354+ " parameters" : {
355+ " name" : " John Doe" ,
356+ " order_id" : " 12345" ,
357+ },
371358 },
359+ to = [" +14155551234" ],
372360) as response:
373361 print (response.headers.get(" X-My-Header" ))
374362
0 commit comments