@tiledesk/tiledesk-whatsapp-connector 0.1.12 ā 0.1.13
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 +1 -1
- package/package.json +1 -1
- package/tiledesk/TiledeskWhatsapp.js +10 -11
- package/tiledesk/TiledeskWhatsappTranslator.js +18 -1
- package/tmp/media-1y8yy2.jpeg +0 -0
package/index.js
CHANGED
|
@@ -343,7 +343,7 @@ router.post('/tiledesk', async (req, res) => {
|
|
|
343
343
|
|
|
344
344
|
const tlr = new TiledeskWhatsappTranslator();
|
|
345
345
|
|
|
346
|
-
|
|
346
|
+
let whatsappJsonMessage = await tlr.toWhatsapp(tiledeskChannelMessage, whatsapp_receiver);
|
|
347
347
|
console.log("whatsappJsonMessage: ", whatsappJsonMessage);
|
|
348
348
|
|
|
349
349
|
if (whatsappJsonMessage) {
|
package/package.json
CHANGED
|
@@ -33,7 +33,7 @@ class TiledeskWhatsapp {
|
|
|
33
33
|
// this.media = config.channelMedia;
|
|
34
34
|
this.token = config.token;
|
|
35
35
|
this.GRAPH_URL = config.GRAPH_URL
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
this.log = false;
|
|
38
38
|
if (config.log) {
|
|
39
39
|
this.log = config.log;
|
|
@@ -42,11 +42,11 @@ class TiledeskWhatsapp {
|
|
|
42
42
|
|
|
43
43
|
async sendMessage(phone_number_id, message) {
|
|
44
44
|
if (this.log) {
|
|
45
|
-
console.log("[Tiledesk Whatsapp] Sending message...", message);
|
|
45
|
+
console.log("[Tiledesk Whatsapp] Sending message...", message);
|
|
46
46
|
} else {
|
|
47
|
-
console.log("[Tiledesk Whatsapp] Sending message...");
|
|
47
|
+
console.log("[Tiledesk Whatsapp] Sending message...");
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
return await axios({
|
|
51
51
|
url: this.GRAPH_URL + phone_number_id + "/messages?access_token=" + this.token,
|
|
52
52
|
headers: {
|
|
@@ -65,7 +65,7 @@ class TiledeskWhatsapp {
|
|
|
65
65
|
|
|
66
66
|
async downloadMedia(mediaId) {
|
|
67
67
|
if (this.log) {
|
|
68
|
-
console.log("[Tiledesk Whatsapp] Download media with id: ", mediaId);
|
|
68
|
+
console.log("[Tiledesk Whatsapp] Download media with id: ", mediaId);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
return await axios({
|
|
@@ -75,7 +75,7 @@ class TiledeskWhatsapp {
|
|
|
75
75
|
'Authorization': "Bearer " + this.token
|
|
76
76
|
}
|
|
77
77
|
}).then(async (response) => {
|
|
78
|
-
console.log("response
|
|
78
|
+
console.log("response: ", response.data)
|
|
79
79
|
|
|
80
80
|
let download_url = response.data.url;
|
|
81
81
|
let mime_type = response.data.mime_type;
|
|
@@ -85,7 +85,7 @@ class TiledeskWhatsapp {
|
|
|
85
85
|
|
|
86
86
|
let example_path = path.join(__dirname, '..', 'tmp', type);
|
|
87
87
|
console.log("read file: ", example_path)
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
const writeStream = fs.createWriteStream(example_path);
|
|
90
90
|
console.log("[Tiledesk Whatsapp] Downloading file...");
|
|
91
91
|
|
|
@@ -98,7 +98,6 @@ class TiledeskWhatsapp {
|
|
|
98
98
|
responseType: 'stream'
|
|
99
99
|
}).then((response) => {
|
|
100
100
|
|
|
101
|
-
console.log("response 2: ", response.data)
|
|
102
101
|
return new Promise((resolve, reject) => {
|
|
103
102
|
response.data.pipe(writeStream);
|
|
104
103
|
let error = null;
|
|
@@ -116,7 +115,7 @@ class TiledeskWhatsapp {
|
|
|
116
115
|
})
|
|
117
116
|
})
|
|
118
117
|
}).catch((err) => {
|
|
119
|
-
console.log("axios err: ", err);
|
|
118
|
+
console.log("axios err: ", err);
|
|
120
119
|
})
|
|
121
120
|
}).catch((err) => {
|
|
122
121
|
console.log("axios err: ", err);
|
|
@@ -153,7 +152,7 @@ class TiledeskWhatsapp {
|
|
|
153
152
|
})
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
|
|
155
|
+
|
|
157
156
|
// HTTP REQUEST
|
|
158
157
|
static async myrequest(options, callback, log) {
|
|
159
158
|
if (this.log) {
|
|
@@ -178,7 +177,7 @@ class TiledeskWhatsapp {
|
|
|
178
177
|
}
|
|
179
178
|
else {
|
|
180
179
|
if (callback) {
|
|
181
|
-
callback(TiledeskClient.getErr({message: "Response status not 200"}, options, res), null, null);
|
|
180
|
+
callback(TiledeskClient.getErr({ message: "Response status not 200" }, options, res), null, null);
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
183
|
}).catch((err) => {
|
|
@@ -122,7 +122,24 @@ class TiledeskWhatsappTranslator {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
if (buttons_count
|
|
125
|
+
if (buttons_count == 0) {
|
|
126
|
+
|
|
127
|
+
for (let btn of buttons) {
|
|
128
|
+
if (btn.type == 'url') {
|
|
129
|
+
text = text + "\n\nš " + btn.value + " (" + btn.link + ")"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
whatsapp_message.text = { body: text };
|
|
134
|
+
|
|
135
|
+
if (this.log) {
|
|
136
|
+
console.log("[Translator] whatsapp message: ", whatsapp_message)
|
|
137
|
+
}
|
|
138
|
+
return whatsapp_message;
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (buttons_count > 0 && buttons_count < 4) {
|
|
126
143
|
|
|
127
144
|
for (let btn of buttons) {
|
|
128
145
|
let title = (btn.value.length > 20) ? btn.value.substr(0, 18) + '..' : btn.value;
|
|
Binary file
|