bhoriwal 1.0.0 → 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/index.js CHANGED
@@ -1,2 +1,9 @@
1
- export { sendTextMessage } from "./src/sendText.js";
2
- export { sendImageMessage } from "./src/sendImage.js";
1
+ export * from "./src/text.js";
2
+ export * from "./src/checkPhone.js";
3
+ export * from "./src/template.js";
4
+ export * from "./src/bulkTemplate.js";
5
+ export * from "./src/media.js";
6
+ export * from "./src/read.js";
7
+ export * from "./src/reactions.js";
8
+ export * from "./src/block.js";
9
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bhoriwal",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Send WhatsApp text messages easily",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/block.js ADDED
@@ -0,0 +1,11 @@
1
+ import { getClient } from "./core.js";
2
+
3
+ export async function blockUser({ to, ...auth }) {
4
+ const client = getClient(auth);
5
+ return client.post("/blocked", { to });
6
+ }
7
+
8
+ export async function unblockUser({ to, ...auth }) {
9
+ const client = getClient(auth);
10
+ return client.delete(`/blocked?to=${to}`);
11
+ }
@@ -0,0 +1,26 @@
1
+ import { getClient } from "./core.js";
2
+
3
+ export async function sendBulkTemplateMessages({
4
+ toList,
5
+ templateName,
6
+ language = "en_US",
7
+ ...auth
8
+ }) {
9
+ const client = getClient(auth);
10
+
11
+ const results = [];
12
+ for (const to of toList) {
13
+ const res = await client.post("/messages", {
14
+ messaging_product: "whatsapp",
15
+ to,
16
+ type: "template",
17
+ template: {
18
+ name: templateName,
19
+ language: { code: language }
20
+ }
21
+ });
22
+ results.push(res.data);
23
+ }
24
+
25
+ return results;
26
+ }
@@ -0,0 +1,14 @@
1
+ import { getClient } from "./core.js";
2
+
3
+ export async function checkPhoneNumber(props) {
4
+ const client = getClient(props);
5
+
6
+ const res = await client.post("/messages", {
7
+ messaging_product: "whatsapp",
8
+ to: props.to,
9
+ type: "text",
10
+ text: { body: "Verification check" }
11
+ });
12
+
13
+ return res.data;
14
+ }
package/src/core.js ADDED
@@ -0,0 +1,15 @@
1
+ import axios from "axios";
2
+
3
+ export function getClient({ phoneNumberId, accessToken }) {
4
+ if (!phoneNumberId || !accessToken) {
5
+ throw new Error("phoneNumberId and accessToken are required");
6
+ }
7
+
8
+ return axios.create({
9
+ baseURL: `https://graph.facebook.com/v19.0/${phoneNumberId}`,
10
+ headers: {
11
+ Authorization: `Bearer ${accessToken}`,
12
+ "Content-Type": "application/json"
13
+ }
14
+ });
15
+ }
package/src/media.js ADDED
@@ -0,0 +1,20 @@
1
+ import { getClient } from "./core.js";
2
+
3
+ export async function sendMedia({
4
+ to,
5
+ type, // image | video | audio | document
6
+ link,
7
+ caption = "",
8
+ ...auth
9
+ }) {
10
+ const client = getClient(auth);
11
+
12
+ const payload = {
13
+ messaging_product: "whatsapp",
14
+ to,
15
+ type,
16
+ [type]: { link, caption }
17
+ };
18
+
19
+ return client.post("/messages", payload);
20
+ }
@@ -0,0 +1,13 @@
1
+ import { getClient } from "./core.js";
2
+
3
+ export async function reactOnMessage({ messageId, emoji, ...auth }) {
4
+ const client = getClient(auth);
5
+
6
+ return client.post("/messages", {
7
+ messaging_product: "whatsapp",
8
+ reaction: {
9
+ message_id: messageId,
10
+ emoji
11
+ }
12
+ });
13
+ }
package/src/read.js ADDED
@@ -0,0 +1,11 @@
1
+ import { getClient } from "./core.js";
2
+
3
+ export async function markAsRead({ messageId, ...auth }) {
4
+ const client = getClient(auth);
5
+
6
+ return client.post("/messages", {
7
+ messaging_product: "whatsapp",
8
+ status: "read",
9
+ message_id: messageId
10
+ });
11
+ }
package/src/sendText.js CHANGED
@@ -1,31 +1,14 @@
1
- import axios from "axios";
1
+ import { getClient } from "./core.js";
2
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
- }
3
+ export async function sendTextMessage({ to, message, ...auth }) {
4
+ const client = getClient(auth);
12
5
 
13
- const url = `https://graph.facebook.com/v19.0/${phoneNumberId}/messages`;
14
-
15
- const payload = {
6
+ const res = await client.post("/messages", {
16
7
  messaging_product: "whatsapp",
17
8
  to,
18
9
  type: "text",
19
- text: {
20
- body: message
21
- }
22
- };
23
-
24
- const headers = {
25
- Authorization: `Bearer ${accessToken}`,
26
- "Content-Type": "application/json"
27
- };
10
+ text: { body: message }
11
+ });
28
12
 
29
- const response = await axios.post(url, payload, { headers });
30
- return response.data;
13
+ return res.data;
31
14
  }
@@ -0,0 +1,31 @@
1
+ import axios from "axios";
2
+
3
+ export async function createTemplate({
4
+ accessToken,
5
+ businessAccountId,
6
+ name,
7
+ language,
8
+ body
9
+ }) {
10
+ return axios.post(
11
+ `https://graph.facebook.com/v19.0/${businessAccountId}/message_templates`,
12
+ {
13
+ name,
14
+ language,
15
+ category: "UTILITY",
16
+ components: [{ type: "BODY", text: body }]
17
+ },
18
+ { headers: { Authorization: `Bearer ${accessToken}` } }
19
+ );
20
+ }
21
+
22
+ export async function deleteTemplate({
23
+ accessToken,
24
+ businessAccountId,
25
+ name
26
+ }) {
27
+ return axios.delete(
28
+ `https://graph.facebook.com/v19.0/${businessAccountId}/message_templates?name=${name}`,
29
+ { headers: { Authorization: `Bearer ${accessToken}` } }
30
+ );
31
+ }
package/src/sendImage.js DELETED
@@ -1,28 +0,0 @@
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
- }