@rkitwork/whatsapp-ramukjar-cloud-sdk 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -61
- package/dist/client.d.ts +10 -0
- package/dist/client.js +13 -0
- package/dist/helpers.d.ts +43 -0
- package/dist/helpers.js +14 -0
- package/dist/index.d.ts +4 -6
- package/dist/index.js +4 -6
- package/dist/payloads/audio.d.ts +7 -0
- package/dist/payloads/document.d.ts +8 -0
- package/dist/payloads/document.js +2 -0
- package/dist/payloads/image.d.ts +8 -0
- package/dist/payloads/image.js +2 -0
- package/dist/payloads/index.d.ts +19 -0
- package/dist/payloads/index.js +25 -0
- package/dist/payloads/interactive.d.ts +13 -0
- package/dist/payloads/interactive.js +2 -0
- package/dist/payloads/location.d.ts +9 -0
- package/dist/payloads/location.js +2 -0
- package/dist/payloads/reaction.d.ts +7 -0
- package/dist/payloads/reaction.js +2 -0
- package/dist/payloads/template.d.ts +10 -0
- package/dist/payloads/template.js +2 -0
- package/dist/payloads/text.d.ts +7 -0
- package/dist/payloads/text.js +2 -0
- package/dist/payloads/video.d.ts +8 -0
- package/dist/payloads/video.js +2 -0
- package/dist/sender.d.ts +2 -0
- package/dist/sender.js +12 -0
- package/package.json +11 -12
- package/src/client.ts +22 -0
- package/src/helpers.ts +11 -0
- package/src/index.ts +4 -8
- package/src/payloads/audio.ts +4 -0
- package/src/payloads/document.ts +4 -0
- package/src/payloads/image.ts +4 -0
- package/src/payloads/index.ts +30 -0
- package/src/payloads/interactive.ts +9 -0
- package/src/payloads/location.ts +9 -0
- package/src/payloads/reaction.ts +7 -0
- package/src/payloads/template.ts +8 -0
- package/src/payloads/text.ts +4 -0
- package/src/payloads/video.ts +4 -0
- package/src/sender.ts +18 -0
- package/dist/core/WhatsAppClient.d.ts +0 -8
- package/dist/core/WhatsAppClient.js +0 -29
- package/dist/core/payloads.d.ts +0 -14
- package/dist/core/payloads.js +0 -71
- package/dist/core/types.d.ts +0 -109
- package/dist/express/webhook.d.ts +0 -3
- package/dist/express/webhook.js +0 -18
- package/dist/nest/webhook.controller.d.ts +0 -6
- package/dist/nest/webhook.controller.js +0 -41
- package/dist/nest/whatsapp.module.d.ts +0 -2
- package/dist/nest/whatsapp.module.js +0 -22
- package/dist/nest/whatsapp.service.d.ts +0 -4
- package/dist/nest/whatsapp.service.js +0 -23
- package/src/core/WhatsAppClient.ts +0 -31
- package/src/core/payloads.ts +0 -93
- package/src/core/types.ts +0 -102
- package/src/express/webhook.ts +0 -18
- package/src/nest/webhook.controller.ts +0 -16
- package/src/nest/whatsapp.module.ts +0 -10
- package/src/nest/whatsapp.service.ts +0 -14
- /package/dist/{core/types.js → payloads/audio.js} +0 -0
package/README.md
CHANGED
|
@@ -49,70 +49,9 @@ await whatsapp.sendMessage('RECIPIENT_NUMBER', textMessage('Hello World!'));
|
|
|
49
49
|
|
|
50
50
|
---
|
|
51
51
|
|
|
52
|
-
### 3. NestJS Webhook Controller (Optional)
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import { WebhookController } from '@rkitwork/whatsapp-ramukjar-cloud-sdk';
|
|
56
|
-
import { Module } from '@nestjs/common';
|
|
57
|
-
|
|
58
|
-
@Module({
|
|
59
|
-
controllers: [WebhookController],
|
|
60
|
-
})
|
|
61
|
-
export class AppModule {}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
#### Controller handles:
|
|
65
|
-
|
|
66
|
-
- `GET /webhook` → WhatsApp verification challenge
|
|
67
|
-
- `POST /webhook` → Incoming messages or events
|
|
68
52
|
|
|
69
53
|
---
|
|
70
54
|
|
|
71
|
-
### 4. ExpressJS Example (Optional)
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
import express from 'express';
|
|
75
|
-
import bodyParser from 'body-parser';
|
|
76
|
-
import { WebhookController } from '@rkitwork/whatsapp-ramukjar-cloud-sdk';
|
|
77
|
-
|
|
78
|
-
const app = express();
|
|
79
|
-
app.use(bodyParser.json());
|
|
80
|
-
|
|
81
|
-
app.get('/webhook', (req, res) => {
|
|
82
|
-
const challenge = req.query['hub.challenge'];
|
|
83
|
-
res.send(challenge);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
app.post('/webhook', (req, res) => {
|
|
87
|
-
console.log('Incoming webhook:', req.body);
|
|
88
|
-
res.sendStatus(200);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
app.listen(3000, () => console.log('Server running on http://localhost:3000'));
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
---
|
|
95
|
-
|
|
96
|
-
## Types & Payloads
|
|
97
|
-
|
|
98
|
-
- `textMessage(content: string)` → Returns WhatsApp text message payload
|
|
99
|
-
- `imageMessage(url: string, caption?: string)` → Returns image message payload
|
|
100
|
-
- `templateMessage(name: string, language: string, variables?: any[])` → Template message payload
|
|
101
|
-
- All payloads are fully typed in `payloads.ts`
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## Contributing
|
|
106
|
-
|
|
107
|
-
1. Fork the repository
|
|
108
|
-
2. `npm install` dependencies
|
|
109
|
-
3. Make changes in `src/`
|
|
110
|
-
4. Build the package:
|
|
111
|
-
|
|
112
|
-
```bash
|
|
113
|
-
npm run build
|
|
114
|
-
```
|
|
115
|
-
|
|
116
55
|
---
|
|
117
56
|
|
|
118
57
|
## Support / Donations
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WhatsAppPayload } from './payloads';
|
|
2
|
+
export declare class WhatsAppClient {
|
|
3
|
+
private readonly config;
|
|
4
|
+
constructor(config: {
|
|
5
|
+
token: string;
|
|
6
|
+
phoneNumberId: string;
|
|
7
|
+
apiVersion: string;
|
|
8
|
+
});
|
|
9
|
+
sendMessage(to: string, payload: WhatsAppPayload): Promise<any>;
|
|
10
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhatsAppClient = void 0;
|
|
4
|
+
const sender_1 = require("./sender");
|
|
5
|
+
class WhatsAppClient {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
}
|
|
9
|
+
sendMessage(to, payload) {
|
|
10
|
+
return (0, sender_1.sendMessage)(this.config.token, this.config.phoneNumberId, this.config.apiVersion, to, payload);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.WhatsAppClient = WhatsAppClient;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const WhatsApp: {
|
|
2
|
+
text: (body: string) => {
|
|
3
|
+
type: string;
|
|
4
|
+
text: {
|
|
5
|
+
body: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
image: (link: string, caption?: string) => {
|
|
9
|
+
type: string;
|
|
10
|
+
image: {
|
|
11
|
+
link: string;
|
|
12
|
+
caption: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
video: (link: string, caption?: string) => {
|
|
16
|
+
type: string;
|
|
17
|
+
video: {
|
|
18
|
+
link: string;
|
|
19
|
+
caption: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
audio: (link: string) => {
|
|
23
|
+
type: string;
|
|
24
|
+
audio: {
|
|
25
|
+
link: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
document: (link: string, filename?: string) => {
|
|
29
|
+
type: string;
|
|
30
|
+
document: {
|
|
31
|
+
link: string;
|
|
32
|
+
filename: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
location: (lat: number, lng: number, name?: string) => {
|
|
36
|
+
type: string;
|
|
37
|
+
location: {
|
|
38
|
+
latitude: number;
|
|
39
|
+
longitude: number;
|
|
40
|
+
name: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhatsApp = void 0;
|
|
4
|
+
exports.WhatsApp = {
|
|
5
|
+
text: (body) => ({ type: 'text', text: { body } }),
|
|
6
|
+
image: (link, caption) => ({ type: 'image', image: { link, caption } }),
|
|
7
|
+
video: (link, caption) => ({ type: 'video', video: { link, caption } }),
|
|
8
|
+
audio: (link) => ({ type: 'audio', audio: { link } }),
|
|
9
|
+
document: (link, filename) => ({ type: 'document', document: { link, filename } }),
|
|
10
|
+
location: (lat, lng, name) => ({
|
|
11
|
+
type: 'location',
|
|
12
|
+
location: { latitude: lat, longitude: lng, name }
|
|
13
|
+
})
|
|
14
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './nest/whatsapp.module';
|
|
6
|
-
export * from './nest/whatsapp.service';
|
|
1
|
+
export * from './client';
|
|
2
|
+
export * from './sender';
|
|
3
|
+
export * from './helpers';
|
|
4
|
+
export * from './payloads';
|
package/dist/index.js
CHANGED
|
@@ -14,9 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./nest/whatsapp.module"), exports);
|
|
22
|
-
__exportStar(require("./nest/whatsapp.service"), exports);
|
|
17
|
+
__exportStar(require("./client"), exports);
|
|
18
|
+
__exportStar(require("./sender"), exports);
|
|
19
|
+
__exportStar(require("./helpers"), exports);
|
|
20
|
+
__exportStar(require("./payloads"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './text';
|
|
2
|
+
export * from './image';
|
|
3
|
+
export * from './video';
|
|
4
|
+
export * from './audio';
|
|
5
|
+
export * from './document';
|
|
6
|
+
export * from './template';
|
|
7
|
+
export * from './interactive';
|
|
8
|
+
export * from './location';
|
|
9
|
+
export * from './reaction';
|
|
10
|
+
import { TextMessage } from './text';
|
|
11
|
+
import { ImageMessage } from './image';
|
|
12
|
+
import { VideoMessage } from './video';
|
|
13
|
+
import { AudioMessage } from './audio';
|
|
14
|
+
import { DocumentMessage } from './document';
|
|
15
|
+
import { TemplateMessage } from './template';
|
|
16
|
+
import { InteractiveMessage } from './interactive';
|
|
17
|
+
import { LocationMessage } from './location';
|
|
18
|
+
import { ReactionMessage } from './reaction';
|
|
19
|
+
export type WhatsAppPayload = TextMessage | ImageMessage | VideoMessage | AudioMessage | DocumentMessage | TemplateMessage | InteractiveMessage | LocationMessage | ReactionMessage;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./text"), exports);
|
|
18
|
+
__exportStar(require("./image"), exports);
|
|
19
|
+
__exportStar(require("./video"), exports);
|
|
20
|
+
__exportStar(require("./audio"), exports);
|
|
21
|
+
__exportStar(require("./document"), exports);
|
|
22
|
+
__exportStar(require("./template"), exports);
|
|
23
|
+
__exportStar(require("./interactive"), exports);
|
|
24
|
+
__exportStar(require("./location"), exports);
|
|
25
|
+
__exportStar(require("./reaction"), exports);
|
package/dist/sender.d.ts
ADDED
package/dist/sender.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendMessage = sendMessage;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
async function sendMessage(token, phoneNumberId, apiVersion, to, payload) {
|
|
9
|
+
const url = `https://graph.facebook.com/${apiVersion}/${phoneNumberId}/messages`;
|
|
10
|
+
const response = await axios_1.default.post(url, { messaging_product: 'whatsapp', to, ...payload }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' } });
|
|
11
|
+
return response.data;
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rkitwork/whatsapp-ramukjar-cloud-sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A secure WhatsApp Cloud API SDK for NestJS and Express",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,20 +8,19 @@
|
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"prepublishOnly": "npm run build"
|
|
10
10
|
},
|
|
11
|
-
"keywords": [
|
|
11
|
+
"keywords": [
|
|
12
|
+
"whatsapp",
|
|
13
|
+
"sdk",
|
|
14
|
+
"nestjs",
|
|
15
|
+
"express",
|
|
16
|
+
"cloud-api"
|
|
17
|
+
],
|
|
12
18
|
"author": "rkitwork",
|
|
13
19
|
"license": "MIT",
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"@nestjs/common": ">=9.0.0",
|
|
16
|
-
"@nestjs/core": ">=9.0.0",
|
|
17
|
-
"express": ">=4.17.0"
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"typescript": "^5.3.3",
|
|
21
|
-
"@types/express": "^4.17.21",
|
|
22
|
-
"@types/node": "^20.0.0"
|
|
23
|
-
},
|
|
24
20
|
"dependencies": {
|
|
25
21
|
"axios": "^1.7.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.9.3"
|
|
26
25
|
}
|
|
27
26
|
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { sendMessage } from './sender';
|
|
2
|
+
import { WhatsAppPayload } from './payloads';
|
|
3
|
+
|
|
4
|
+
export class WhatsAppClient {
|
|
5
|
+
constructor(
|
|
6
|
+
private readonly config: {
|
|
7
|
+
token: string;
|
|
8
|
+
phoneNumberId: string;
|
|
9
|
+
apiVersion: string;
|
|
10
|
+
}
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
sendMessage(to: string, payload: WhatsAppPayload) {
|
|
14
|
+
return sendMessage(
|
|
15
|
+
this.config.token,
|
|
16
|
+
this.config.phoneNumberId,
|
|
17
|
+
this.config.apiVersion,
|
|
18
|
+
to,
|
|
19
|
+
payload
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const WhatsApp = {
|
|
2
|
+
text: (body: string) => ({ type: 'text', text: { body } }),
|
|
3
|
+
image: (link: string, caption?: string) => ({ type: 'image', image: { link, caption } }),
|
|
4
|
+
video: (link: string, caption?: string) => ({ type: 'video', video: { link, caption } }),
|
|
5
|
+
audio: (link: string) => ({ type: 'audio', audio: { link } }),
|
|
6
|
+
document: (link: string, filename?: string) => ({ type: 'document', document: { link, filename } }),
|
|
7
|
+
location: (lat: number, lng: number, name?: string) => ({
|
|
8
|
+
type: 'location',
|
|
9
|
+
location: { latitude: lat, longitude: lng, name }
|
|
10
|
+
})
|
|
11
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
|
|
5
|
-
export * from './express/webhook';
|
|
6
|
-
|
|
7
|
-
export * from './nest/whatsapp.module';
|
|
8
|
-
export * from './nest/whatsapp.service';
|
|
1
|
+
export * from './client';
|
|
2
|
+
export * from './sender';
|
|
3
|
+
export * from './helpers';
|
|
4
|
+
export * from './payloads';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export * from './text';
|
|
2
|
+
export * from './image';
|
|
3
|
+
export * from './video';
|
|
4
|
+
export * from './audio';
|
|
5
|
+
export * from './document';
|
|
6
|
+
export * from './template';
|
|
7
|
+
export * from './interactive';
|
|
8
|
+
export * from './location';
|
|
9
|
+
export * from './reaction';
|
|
10
|
+
|
|
11
|
+
import { TextMessage } from './text';
|
|
12
|
+
import { ImageMessage } from './image';
|
|
13
|
+
import { VideoMessage } from './video';
|
|
14
|
+
import { AudioMessage } from './audio';
|
|
15
|
+
import { DocumentMessage } from './document';
|
|
16
|
+
import { TemplateMessage } from './template';
|
|
17
|
+
import { InteractiveMessage } from './interactive';
|
|
18
|
+
import { LocationMessage } from './location';
|
|
19
|
+
import { ReactionMessage } from './reaction';
|
|
20
|
+
|
|
21
|
+
export type WhatsAppPayload =
|
|
22
|
+
| TextMessage
|
|
23
|
+
| ImageMessage
|
|
24
|
+
| VideoMessage
|
|
25
|
+
| AudioMessage
|
|
26
|
+
| DocumentMessage
|
|
27
|
+
| TemplateMessage
|
|
28
|
+
| InteractiveMessage
|
|
29
|
+
| LocationMessage
|
|
30
|
+
| ReactionMessage;
|
package/src/sender.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { WhatsAppPayload } from './payloads';
|
|
3
|
+
|
|
4
|
+
export async function sendMessage(
|
|
5
|
+
token: string,
|
|
6
|
+
phoneNumberId: string,
|
|
7
|
+
apiVersion: string,
|
|
8
|
+
to: string,
|
|
9
|
+
payload: WhatsAppPayload
|
|
10
|
+
) {
|
|
11
|
+
const url = `https://graph.facebook.com/${apiVersion}/${phoneNumberId}/messages`;
|
|
12
|
+
const response = await axios.post(
|
|
13
|
+
url,
|
|
14
|
+
{ messaging_product: 'whatsapp', to, ...payload },
|
|
15
|
+
{ headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' } }
|
|
16
|
+
);
|
|
17
|
+
return response.data;
|
|
18
|
+
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { WhatsAppPayload } from './types';
|
|
2
|
-
export declare class WhatsAppClient {
|
|
3
|
-
private readonly token;
|
|
4
|
-
private readonly phoneNumberId;
|
|
5
|
-
private readonly apiVersion;
|
|
6
|
-
constructor(token: string, phoneNumberId: string, apiVersion?: string);
|
|
7
|
-
sendMessage(to: string, payload: WhatsAppPayload): Promise<any>;
|
|
8
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WhatsAppClient = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
class WhatsAppClient {
|
|
9
|
-
constructor(token, phoneNumberId, apiVersion = 'v24.0') {
|
|
10
|
-
this.token = token;
|
|
11
|
-
this.phoneNumberId = phoneNumberId;
|
|
12
|
-
this.apiVersion = apiVersion;
|
|
13
|
-
}
|
|
14
|
-
async sendMessage(to, payload) {
|
|
15
|
-
const url = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}/messages`;
|
|
16
|
-
const response = await axios_1.default.post(url, {
|
|
17
|
-
messaging_product: 'whatsapp',
|
|
18
|
-
to,
|
|
19
|
-
...payload,
|
|
20
|
-
}, {
|
|
21
|
-
headers: {
|
|
22
|
-
Authorization: `Bearer ${this.token}`,
|
|
23
|
-
'Content-Type': 'application/json',
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
return response.data;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.WhatsAppClient = WhatsAppClient;
|
package/dist/core/payloads.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as T from './types';
|
|
2
|
-
export declare const textMessage: (body: string, preview?: boolean) => T.TextPayload;
|
|
3
|
-
export declare const imageMessage: (link: string, caption?: string) => T.ImagePayload;
|
|
4
|
-
export declare const audioMessage: (link: string) => T.AudioPayload;
|
|
5
|
-
export declare const videoMessage: (link: string, caption?: string) => T.VideoPayload;
|
|
6
|
-
export declare const documentMessage: (link: string, filename: string, caption?: string) => T.DocumentPayload;
|
|
7
|
-
export declare const locationMessage: (latitude: number, longitude: number, name?: string, address?: string) => T.LocationPayload;
|
|
8
|
-
export declare const contactMessage: (firstName: string, phone: string, lastName?: string) => T.ContactPayload;
|
|
9
|
-
export declare const buttonMessage: (bodyText: string, buttons: {
|
|
10
|
-
id: string;
|
|
11
|
-
title: string;
|
|
12
|
-
}[]) => T.ButtonPayload;
|
|
13
|
-
export declare const listMessage: (bodyText: string, buttonText: string, sections: T.ListPayload["interactive"]["action"]["sections"]) => T.ListPayload;
|
|
14
|
-
export declare const templateMessage: (name: string, language?: string, components?: any[]) => T.TemplatePayload;
|