@@ -123,7 +123,9 @@ class WhatsappCloud {
123
123
124
124
this . _mustHaveTemplateName = ( templateName ) => {
125
125
if ( ! templateName ) {
126
- throw new Error ( '"templateName" is required in making a request' ) ;
126
+ throw new Error (
127
+ '"templateName" is required in making a request'
128
+ ) ;
127
129
}
128
130
} ;
129
131
this . _mustHaveComponents = ( components ) => {
@@ -133,7 +135,9 @@ class WhatsappCloud {
133
135
} ;
134
136
this . _mustHaveLanguageCode = ( languageCode ) => {
135
137
if ( ! languageCode ) {
136
- throw new Error ( '"languageCode" is required in making a request' ) ;
138
+ throw new Error (
139
+ '"languageCode" is required in making a request'
140
+ ) ;
137
141
}
138
142
} ;
139
143
this . _mustHaveMessageId = ( messageId ) => {
@@ -260,23 +264,28 @@ class WhatsappCloud {
260
264
261
265
return response ;
262
266
}
263
- async sendTemplate ( { templateName, languageCode, components, recipientPhone} ) {
267
+ async sendTemplate ( {
268
+ templateName,
269
+ languageCode,
270
+ components,
271
+ recipientPhone,
272
+ } ) {
264
273
this . _mustHaverecipientPhone ( recipientPhone ) ;
265
274
this . _mustHaveTemplateName ( templateName ) ;
266
- this . _mustHaveComponents ( components )
267
- this . _mustHaveLanguageCode ( languageCode )
275
+ this . _mustHaveComponents ( components ) ;
276
+ this . _mustHaveLanguageCode ( languageCode ) ;
268
277
let body = {
269
- " messaging_product" : " whatsapp" ,
270
- " recipient_type" : " individual" ,
271
- "to" : recipientPhone ,
272
- " type" : " template" ,
273
- " template" : {
274
- " name" : templateName ,
275
- " language" : {
276
- " code" : languageCode
277
- } ,
278
- " components" : components
279
- }
278
+ messaging_product : ' whatsapp' ,
279
+ recipient_type : ' individual' ,
280
+ to : recipientPhone ,
281
+ type : ' template' ,
282
+ template : {
283
+ name : templateName ,
284
+ language : {
285
+ code : languageCode ,
286
+ } ,
287
+ components : components ,
288
+ } ,
280
289
} ;
281
290
282
291
let response = await this . _fetchAssistant ( {
@@ -287,7 +296,6 @@ class WhatsappCloud {
287
296
288
297
return response ;
289
298
}
290
-
291
299
292
300
async markMessageAsRead ( { message_id } ) {
293
301
try {
@@ -323,10 +331,11 @@ class WhatsappCloud {
323
331
async sendSimpleButtons ( { recipientPhone, message, listOfButtons } ) {
324
332
this . _mustHaveMessage ( message ) ;
325
333
this . _mustHaverecipientPhone ( recipientPhone ) ;
326
-
327
- if ( ! listOfButtons ) throw new Error ( 'listOfButtons cannot be empty' ) ;
328
- if ( listOfButtons . length > 3 ) throw new Error ( 'listOfButtons cannot be bigger than 3 elements' ) ;
329
-
334
+
335
+ if ( ! listOfButtons ) throw new Error ( 'listOfButtons cannot be empty' ) ;
336
+ if ( listOfButtons . length > 3 )
337
+ throw new Error ( 'listOfButtons cannot be bigger than 3 elements' ) ;
338
+
330
339
let validButtons = listOfButtons
331
340
. map ( ( button ) => {
332
341
if ( ! button . title ) {
@@ -387,7 +396,7 @@ class WhatsappCloud {
387
396
bodyText,
388
397
footerText,
389
398
listOfSections,
390
- actionTitle
399
+ actionTitle,
391
400
} ) {
392
401
this . _mustHaverecipientPhone ( recipientPhone ) ;
393
402
@@ -397,7 +406,6 @@ class WhatsappCloud {
397
406
throw new Error ( '"headerText" is required in making a request' ) ;
398
407
if ( ! footerText )
399
408
throw new Error ( '"footerText" is required in making a request' ) ;
400
-
401
409
402
410
let totalNumberOfItems = 0 ;
403
411
let validSections = listOfSections
@@ -460,10 +468,8 @@ class WhatsappCloud {
460
468
'The total number of items in the rows must be equal or less than 10.'
461
469
) ;
462
470
}
463
- if ( actionTitle && actionTitle . length > 20 ) {
464
- throw new Error (
465
- 'Title should be less than 20 characters'
466
- ) ;
471
+ if ( actionTitle && actionTitle . length > 20 ) {
472
+ throw new Error ( 'Title should be less than 20 characters' ) ;
467
473
}
468
474
469
475
let samples = {
@@ -484,7 +490,10 @@ class WhatsappCloud {
484
490
text : footerText ,
485
491
} ,
486
492
action : {
487
- button : actionTitle != undefined ? actionTitle :'Select a product' ,
493
+ button :
494
+ actionTitle != undefined
495
+ ? actionTitle
496
+ : 'Select a product' ,
488
497
sections : validSections ,
489
498
} ,
490
499
} ,
0 commit comments