bhoriwal 1.0.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 +17 -0
- package/index.js +2 -0
- package/package.json +21 -0
- package/src/sendImage.js +28 -0
- package/src/sendText.js +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# bhoriwal
|
|
2
|
+
|
|
3
|
+
Send WhatsApp text messages using WhatsApp Cloud API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
npm install bhoriwal
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
```js
|
|
10
|
+
const { sendWhatsAppMessage } = require("bhoriwal");
|
|
11
|
+
|
|
12
|
+
sendWhatsAppMessage({
|
|
13
|
+
phoneNumberId: "PHONE_NUMBER_ID",
|
|
14
|
+
accessToken: "ACCESS_TOKEN",
|
|
15
|
+
to: "919999999999",
|
|
16
|
+
message: "Hello World"
|
|
17
|
+
});
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bhoriwal",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Send WhatsApp text messages easily",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"whatsapp",
|
|
12
|
+
"message",
|
|
13
|
+
"nodejs",
|
|
14
|
+
"api"
|
|
15
|
+
],
|
|
16
|
+
"author": "Gulab",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"axios": "^1.13.2"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/sendImage.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
|
|
3
|
+
export async function sendImageMessage({
|
|
4
|
+
phoneNumberId,
|
|
5
|
+
accessToken,
|
|
6
|
+
to,
|
|
7
|
+
imageUrl,
|
|
8
|
+
caption = ""
|
|
9
|
+
}) {
|
|
10
|
+
const url = `https://graph.facebook.com/v19.0/${phoneNumberId}/messages`;
|
|
11
|
+
|
|
12
|
+
const payload = {
|
|
13
|
+
messaging_product: "whatsapp",
|
|
14
|
+
to,
|
|
15
|
+
type: "image",
|
|
16
|
+
image: {
|
|
17
|
+
link: imageUrl,
|
|
18
|
+
caption
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return axios.post(url, payload, {
|
|
23
|
+
headers: {
|
|
24
|
+
Authorization: `Bearer ${accessToken}`,
|
|
25
|
+
"Content-Type": "application/json"
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
package/src/sendText.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
|
|
3
|
+
export async function sendTextMessage({
|
|
4
|
+
phoneNumberId,
|
|
5
|
+
accessToken,
|
|
6
|
+
to,
|
|
7
|
+
message
|
|
8
|
+
}) {
|
|
9
|
+
if (!phoneNumberId || !accessToken || !to || !message) {
|
|
10
|
+
throw new Error("Missing required parameters");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const url = `https://graph.facebook.com/v19.0/${phoneNumberId}/messages`;
|
|
14
|
+
|
|
15
|
+
const payload = {
|
|
16
|
+
messaging_product: "whatsapp",
|
|
17
|
+
to,
|
|
18
|
+
type: "text",
|
|
19
|
+
text: {
|
|
20
|
+
body: message
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const headers = {
|
|
25
|
+
Authorization: `Bearer ${accessToken}`,
|
|
26
|
+
"Content-Type": "application/json"
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const response = await axios.post(url, payload, { headers });
|
|
30
|
+
return response.data;
|
|
31
|
+
}
|