Skip to content

Commit 30666e7

Browse files
committed
Let's keep testing in production
1 parent fda9eae commit 30666e7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

fetch.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Location = require('./types/location');
55
const { Template } = require('./types/template');
66
const Text = require('./types/text');
77

8-
const fetch = require('cross-fetch');
8+
const req = typeof fetch === "undefined" ? require('cross-fetch') : fetch;
99

1010
/**
1111
* Make a message post request to the API
@@ -33,7 +33,7 @@ function sendMessage(token, v, phoneID, to, object) {
3333
});
3434

3535
// Make the post request
36-
return fetch(`https://graph.facebook.com/${v}/${phoneID}/messages`, {
36+
return req(`https://graph.facebook.com/${v}/${phoneID}/messages`, {
3737
method: "POST",
3838
headers: {
3939
'Authorization': `Bearer ${token}`,
@@ -55,7 +55,7 @@ function sendMessage(token, v, phoneID, to, object) {
5555
* @returns {Promise} The fetch promise
5656
*/
5757
function readMessage(token, v, phoneID, message_id) {
58-
return fetch(`https://graph.facebook.com/${v}/${phoneID}/messages`, {
58+
return req(`https://graph.facebook.com/${v}/${phoneID}/messages`, {
5959
method: "POST",
6060
headers: {
6161
'Authorization': `Bearer ${token}`,
@@ -87,7 +87,7 @@ function makeQR(token, v, phoneID, message, format) {
8787
prefilled_message: message,
8888
};
8989

90-
return fetch(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls?${new URLSearchParams(params)}`, {
90+
return req(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls?${new URLSearchParams(params)}`, {
9191
method: "POST",
9292
headers: {
9393
'Authorization': `Bearer ${token}`,
@@ -107,7 +107,7 @@ function makeQR(token, v, phoneID, message, format) {
107107
* @returns {Promise} The fetch promise
108108
*/
109109
function getQR(token, v, phoneID, id) {
110-
return fetch(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls/${id ?? ""}`, {
110+
return req(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls/${id ?? ""}`, {
111111
headers: {
112112
'Authorization': `Bearer ${token}`,
113113
},
@@ -127,7 +127,7 @@ function getQR(token, v, phoneID, id) {
127127
* @returns {Promise} The fetch promise
128128
*/
129129
function updateQR(token, v, phoneID, id, message) {
130-
return fetch(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls/${id}?prefilled_message=${encodeURI(message)}`, {
130+
return req(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls/${id}?prefilled_message=${encodeURI(message)}`, {
131131
method: "POST",
132132
headers: {
133133
'Authorization': `Bearer ${token}`,
@@ -147,7 +147,7 @@ function updateQR(token, v, phoneID, id, message) {
147147
* @returns {Promise} The fetch promise
148148
*/
149149
function deleteQR(token, v, phoneID, id) {
150-
return fetch(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls/${id}`, {
150+
return req(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls/${id}`, {
151151
method: "DELETE",
152152
headers: {
153153
'Authorization': `Bearer ${token}`,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "whatsapp-api-js",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"author": "Secreto31126",
55
"description": "A Whatsapp Official API helper for Node.js",
66
"license": "MIT",

0 commit comments

Comments
 (0)