@tiledesk/tiledesk-whatsapp-connector 0.1.3 → 0.1.6
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 +13 -18
- package/package.json +1 -1
- package/template/configure.html +1 -1
- package/tiledesk/TiledeskChannel.js +6 -4
- package/tiledesk/TiledeskWhatsapp.js +10 -5
package/index.js
CHANGED
|
@@ -42,7 +42,7 @@ router.use(bodyParser.urlencoded({ extended: true }));
|
|
|
42
42
|
var API_URL = null;
|
|
43
43
|
var GRAPH_URL = null;
|
|
44
44
|
var BASE_URL = null;
|
|
45
|
-
var log =
|
|
45
|
+
var log = true;
|
|
46
46
|
|
|
47
47
|
const db = new KVBaseMongo(kvbase_collection);
|
|
48
48
|
/*
|
|
@@ -165,9 +165,9 @@ router.post('/update', async (req, res) => {
|
|
|
165
165
|
subscription_id: settings.subscriptionId,
|
|
166
166
|
}
|
|
167
167
|
if (log) {
|
|
168
|
-
console.log("Replacements: ", replacements);
|
|
168
|
+
console.log("Replacements: ", replacements);
|
|
169
169
|
}
|
|
170
|
-
|
|
170
|
+
|
|
171
171
|
var html = template(replacements);
|
|
172
172
|
res.send(html);
|
|
173
173
|
})
|
|
@@ -192,9 +192,9 @@ router.post('/update', async (req, res) => {
|
|
|
192
192
|
tdClient.subscribe(subscription_info).then((data) => {
|
|
193
193
|
let subscription = data;
|
|
194
194
|
if (log) {
|
|
195
|
-
console.log("\nSubscription: ", subscription)
|
|
195
|
+
console.log("\nSubscription: ", subscription)
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
|
|
198
198
|
let settings = {
|
|
199
199
|
project_id: projectId,
|
|
200
200
|
token: token,
|
|
@@ -223,9 +223,9 @@ router.post('/update', async (req, res) => {
|
|
|
223
223
|
subscription_id: settings.subscriptionId,
|
|
224
224
|
}
|
|
225
225
|
if (log) {
|
|
226
|
-
console.log("Replacements: ", replacements);
|
|
226
|
+
console.log("Replacements: ", replacements);
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
|
|
229
229
|
var html = template(replacements);
|
|
230
230
|
res.send(html);
|
|
231
231
|
})
|
|
@@ -240,7 +240,7 @@ router.post('/update', async (req, res) => {
|
|
|
240
240
|
router.post('/disconnect', async (req, res) => {
|
|
241
241
|
console.log("\n/disconnect")
|
|
242
242
|
if (log) {
|
|
243
|
-
console.log("/disconnect body: ", req.body)
|
|
243
|
+
console.log("/disconnect body: ", req.body)
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
let projectId = req.body.project_id;
|
|
@@ -277,9 +277,9 @@ router.post('/disconnect', async (req, res) => {
|
|
|
277
277
|
proxy_url: proxy_url,
|
|
278
278
|
}
|
|
279
279
|
if (log) {
|
|
280
|
-
console.log("Replacements: ", replacements);
|
|
280
|
+
console.log("Replacements: ", replacements);
|
|
281
281
|
}
|
|
282
|
-
|
|
282
|
+
|
|
283
283
|
var html = template(replacements);
|
|
284
284
|
res.send(html);
|
|
285
285
|
})
|
|
@@ -487,7 +487,7 @@ router.post("/webhook/:project_id", async (req, res) => {
|
|
|
487
487
|
// tdClient.getRequests
|
|
488
488
|
const tdChannel = new TiledeskChannel({ settings: settings, API_URL: API_URL })
|
|
489
489
|
const response = await tdChannel.send(tiledeskJsonMessage, message_info);
|
|
490
|
-
if (log) {
|
|
490
|
+
if (log) {
|
|
491
491
|
console.log("Send response: ", response)
|
|
492
492
|
}
|
|
493
493
|
|
|
@@ -550,7 +550,7 @@ function startApp(settings, callback) {
|
|
|
550
550
|
if (!settings.MONGODB_URL) {
|
|
551
551
|
throw new Error("settings.MONGODB_URL is mandatory");
|
|
552
552
|
}
|
|
553
|
-
|
|
553
|
+
|
|
554
554
|
if (!settings.API_URL) {
|
|
555
555
|
throw new Error("settings.API_URL is mandatory");
|
|
556
556
|
} else {
|
|
@@ -586,11 +586,6 @@ function startApp(settings, callback) {
|
|
|
586
586
|
|
|
587
587
|
function readHTMLFile(templateName, callback) {
|
|
588
588
|
console.log("Reading file: ", templateName)
|
|
589
|
-
console.log("appRoot: ", appRoot)
|
|
590
|
-
let file = appRoot + '/template' + templateName;
|
|
591
|
-
console.log("file: ", file);
|
|
592
|
-
console.log("*** appRoot: ", appRoot.toString());
|
|
593
|
-
console.log("type: ", typeof(appRoot))
|
|
594
589
|
fs.readFile(__dirname + '/template' + templateName, { encoding: 'utf-8' },
|
|
595
590
|
function(err, html) {
|
|
596
591
|
if (err) {
|
|
@@ -602,4 +597,4 @@ function readHTMLFile(templateName, callback) {
|
|
|
602
597
|
})
|
|
603
598
|
}
|
|
604
599
|
|
|
605
|
-
module.exports = { router: router, startApp: startApp};
|
|
600
|
+
module.exports = { router: router, startApp: startApp };
|
package/package.json
CHANGED
package/template/configure.html
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
<div>
|
|
44
44
|
|
|
45
45
|
<h1 style="margin-top: 0px; margin-bottom: 2px; min-width: 500px;">WhatsApp Business (Test)</h1>
|
|
46
|
-
<h7 style="color: rgb(140, 140, 140);">by Tiledesk (v. 0.1.
|
|
46
|
+
<h7 style="color: rgb(140, 140, 140);">by Tiledesk (v. 0.1.5)</h7>
|
|
47
47
|
|
|
48
48
|
{{#if wab_token}}
|
|
49
49
|
<div style="margin-top: 20px;">
|
|
@@ -32,7 +32,7 @@ class TiledeskChannel {
|
|
|
32
32
|
throw new Error('config.API_URL is mandatory');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
this.log =
|
|
35
|
+
this.log = true;
|
|
36
36
|
if (config.log) {
|
|
37
37
|
this.log = config.log;
|
|
38
38
|
}
|
|
@@ -97,18 +97,20 @@ class TiledeskChannel {
|
|
|
97
97
|
method: 'GET'
|
|
98
98
|
}).then((response) => {
|
|
99
99
|
|
|
100
|
-
if (log) {
|
|
100
|
+
if (this.log) {
|
|
101
101
|
console.log("[Tiledesk Channel] get request response: ", response.data);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
let request_id;
|
|
105
105
|
if (response.data.requests[0]) {
|
|
106
106
|
request_id = response.data.requests[0].request_id;
|
|
107
|
+
console.log("Old request id: ", request_id);
|
|
107
108
|
} else {
|
|
108
109
|
request_id = new_request_id;
|
|
110
|
+
console.log("New request id: ", request_id);
|
|
109
111
|
}
|
|
110
112
|
|
|
111
|
-
if (log) {
|
|
113
|
+
if (this.log) {
|
|
112
114
|
console.log("[Tiledesk Channel] tiledeskMessage:", tiledeskMessage);
|
|
113
115
|
}
|
|
114
116
|
|
|
@@ -122,7 +124,7 @@ class TiledeskChannel {
|
|
|
122
124
|
method: 'POST'
|
|
123
125
|
}).then((response) => {
|
|
124
126
|
|
|
125
|
-
if (log) {
|
|
127
|
+
if (this.log) {
|
|
126
128
|
console.log("[Tiledesk Channel] send message response: ", response.data);
|
|
127
129
|
}
|
|
128
130
|
|
|
@@ -32,10 +32,15 @@ class TiledeskWhatsapp {
|
|
|
32
32
|
// this.media = config.channelMedia;
|
|
33
33
|
this.token = config.token;
|
|
34
34
|
this.GRAPH_URL = config.GRAPH_URL
|
|
35
|
+
|
|
36
|
+
this.log = false;
|
|
37
|
+
if (config.log) {
|
|
38
|
+
this.log = config.log;
|
|
39
|
+
}
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
async sendMessage(phone_number_id, message) {
|
|
38
|
-
if (log) {
|
|
43
|
+
if (this.log) {
|
|
39
44
|
console.log("[Tiledesk Whatsapp] Sending message...", message);
|
|
40
45
|
} else {
|
|
41
46
|
console.log("[Tiledesk Whatsapp] Sending message...");
|
|
@@ -58,7 +63,7 @@ class TiledeskWhatsapp {
|
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
async downloadMedia(mediaId) {
|
|
61
|
-
if (log) {
|
|
66
|
+
if (this.log) {
|
|
62
67
|
console.log("[Tiledesk Whatsapp] Download media with id: ", mediaId);
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -128,7 +133,7 @@ class TiledeskWhatsapp {
|
|
|
128
133
|
}
|
|
129
134
|
|
|
130
135
|
return await axios.post(url, form, request_config).then((response) => {
|
|
131
|
-
if (log) {
|
|
136
|
+
if (this.log) {
|
|
132
137
|
console.log("[Tiledesk Whatsapp] upload response: ", response.data);
|
|
133
138
|
}
|
|
134
139
|
|
|
@@ -146,7 +151,7 @@ class TiledeskWhatsapp {
|
|
|
146
151
|
|
|
147
152
|
// HTTP REQUEST
|
|
148
153
|
static async myrequest(options, callback, log) {
|
|
149
|
-
if (log) {
|
|
154
|
+
if (this.log) {
|
|
150
155
|
console.log("API URL: ", options.url);
|
|
151
156
|
console.log("** Options: ", options);
|
|
152
157
|
}
|
|
@@ -157,7 +162,7 @@ class TiledeskWhatsapp {
|
|
|
157
162
|
params: options.params,
|
|
158
163
|
headers: options.headers
|
|
159
164
|
}).then((res) => {
|
|
160
|
-
if (log) {
|
|
165
|
+
if (this.log) {
|
|
161
166
|
console.log("Response for url:", options.url);
|
|
162
167
|
console.log("Response headers:\n", res.headers);
|
|
163
168
|
}
|