@@ -5,7 +5,7 @@ const Location = require('./types/location');
5
5
const { Template } = require ( './types/template' ) ;
6
6
const Text = require ( './types/text' ) ;
7
7
8
- const fetch = require ( 'cross-fetch' ) ;
8
+ const req = typeof fetch === "undefined" ? require ( 'cross-fetch' ) : fetch ;
9
9
10
10
/**
11
11
* Make a message post request to the API
@@ -33,7 +33,7 @@ function sendMessage(token, v, phoneID, to, object) {
33
33
} ) ;
34
34
35
35
// Make the post request
36
- return fetch ( `https://graph.facebook.com/${ v } /${ phoneID } /messages` , {
36
+ return req ( `https://graph.facebook.com/${ v } /${ phoneID } /messages` , {
37
37
method : "POST" ,
38
38
headers : {
39
39
'Authorization' : `Bearer ${ token } ` ,
@@ -55,7 +55,7 @@ function sendMessage(token, v, phoneID, to, object) {
55
55
* @returns {Promise } The fetch promise
56
56
*/
57
57
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` , {
59
59
method : "POST" ,
60
60
headers : {
61
61
'Authorization' : `Bearer ${ token } ` ,
@@ -87,7 +87,7 @@ function makeQR(token, v, phoneID, message, format) {
87
87
prefilled_message : message ,
88
88
} ;
89
89
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 ) } ` , {
91
91
method : "POST" ,
92
92
headers : {
93
93
'Authorization' : `Bearer ${ token } ` ,
@@ -107,7 +107,7 @@ function makeQR(token, v, phoneID, message, format) {
107
107
* @returns {Promise } The fetch promise
108
108
*/
109
109
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 ?? "" } ` , {
111
111
headers : {
112
112
'Authorization' : `Bearer ${ token } ` ,
113
113
} ,
@@ -127,7 +127,7 @@ function getQR(token, v, phoneID, id) {
127
127
* @returns {Promise } The fetch promise
128
128
*/
129
129
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 ) } ` , {
131
131
method : "POST" ,
132
132
headers : {
133
133
'Authorization' : `Bearer ${ token } ` ,
@@ -147,7 +147,7 @@ function updateQR(token, v, phoneID, id, message) {
147
147
* @returns {Promise } The fetch promise
148
148
*/
149
149
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 } ` , {
151
151
method : "DELETE" ,
152
152
headers : {
153
153
'Authorization' : `Bearer ${ token } ` ,
0 commit comments