Skip to content

Commit 13319cc

Browse files
committed
Prettier: Update npm-publish.yml and index.js, and add test script to package.json
1 parent 319858a commit 13319cc

File tree

3 files changed

+62
-52
lines changed

3 files changed

+62
-52
lines changed

.github/workflows/npm-publish.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@
44
name: Node.js Package
55

66
on:
7-
release:
8-
types: [created]
7+
release:
8+
types: [created]
99

1010
jobs:
11-
build:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v3
15-
- uses: actions/setup-node@v3
16-
with:
17-
node-version: 16
18-
- run: npm ci
19-
- run: npm test
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: 16
18+
- run: npm ci
19+
- run: npm test
2020

21-
publish-npm:
22-
needs: build
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/checkout@v3
26-
- uses: actions/setup-node@v3
27-
with:
28-
node-version: 16
29-
registry-url: https://registry.npmjs.org/
30-
- run: npm ci
31-
- run: npm publish
32-
env:
33-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
21+
publish-npm:
22+
needs: build
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
- uses: actions/setup-node@v3
27+
with:
28+
node-version: 16
29+
registry-url: https://registry.npmjs.org/
30+
- run: npm ci
31+
- run: npm publish
32+
env:
33+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

index.js

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ class WhatsappCloud {
123123

124124
this._mustHaveTemplateName = (templateName) => {
125125
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+
);
127129
}
128130
};
129131
this._mustHaveComponents = (components) => {
@@ -133,7 +135,9 @@ class WhatsappCloud {
133135
};
134136
this._mustHaveLanguageCode = (languageCode) => {
135137
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+
);
137141
}
138142
};
139143
this._mustHaveMessageId = (messageId) => {
@@ -260,23 +264,28 @@ class WhatsappCloud {
260264

261265
return response;
262266
}
263-
async sendTemplate({templateName,languageCode,components,recipientPhone} ) {
267+
async sendTemplate({
268+
templateName,
269+
languageCode,
270+
components,
271+
recipientPhone,
272+
}) {
264273
this._mustHaverecipientPhone(recipientPhone);
265274
this._mustHaveTemplateName(templateName);
266-
this._mustHaveComponents(components)
267-
this._mustHaveLanguageCode(languageCode)
275+
this._mustHaveComponents(components);
276+
this._mustHaveLanguageCode(languageCode);
268277
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+
},
280289
};
281290

282291
let response = await this._fetchAssistant({
@@ -287,7 +296,6 @@ class WhatsappCloud {
287296

288297
return response;
289298
}
290-
291299

292300
async markMessageAsRead({ message_id }) {
293301
try {
@@ -323,10 +331,11 @@ class WhatsappCloud {
323331
async sendSimpleButtons({ recipientPhone, message, listOfButtons }) {
324332
this._mustHaveMessage(message);
325333
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+
330339
let validButtons = listOfButtons
331340
.map((button) => {
332341
if (!button.title) {
@@ -387,7 +396,7 @@ class WhatsappCloud {
387396
bodyText,
388397
footerText,
389398
listOfSections,
390-
actionTitle
399+
actionTitle,
391400
}) {
392401
this._mustHaverecipientPhone(recipientPhone);
393402

@@ -397,7 +406,6 @@ class WhatsappCloud {
397406
throw new Error('"headerText" is required in making a request');
398407
if (!footerText)
399408
throw new Error('"footerText" is required in making a request');
400-
401409

402410
let totalNumberOfItems = 0;
403411
let validSections = listOfSections
@@ -460,10 +468,8 @@ class WhatsappCloud {
460468
'The total number of items in the rows must be equal or less than 10.'
461469
);
462470
}
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');
467473
}
468474

469475
let samples = {
@@ -484,7 +490,10 @@ class WhatsappCloud {
484490
text: footerText,
485491
},
486492
action: {
487-
button: actionTitle!= undefined? actionTitle:'Select a product',
493+
button:
494+
actionTitle != undefined
495+
? actionTitle
496+
: 'Select a product',
488497
sections: validSections,
489498
},
490499
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"prettier": "prettier --ignore-path .prettierignore --config prettier.config.js --write .",
1010
"quickpush": "cls && git status && git add * && git commit * -m \"Updated Code\" && git push",
11+
"test": "echo \"Error: no test specified\" && exit 1",
1112
"npmpublish": "npm run prettier && np"
1213
},
1314
"dependencies": {

0 commit comments

Comments
 (0)