@tiledesk/tiledesk-whatsapp-connector 1.0.19 → 1.0.20

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/.env CHANGED
@@ -1,2 +1,2 @@
1
1
  # CUSTOM ENV
2
- NPM_PUBLISH_TOKEN=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
2
+ NPM_PUBLISH_TOKEN=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
package/index.js CHANGED
@@ -845,7 +845,6 @@ router.post('/webhook', async (req, res) => {
845
845
 
846
846
  const util = new TiledeskWhatsapp({
847
847
  token: settings.wab_token,
848
- ID_PROJECT: settings.project_id,
849
848
  GRAPH_URL: GRAPH_URL,
850
849
  API_URL: API_URL
851
850
  });
@@ -859,8 +858,7 @@ router.post('/webhook', async (req, res) => {
859
858
  }
860
859
 
861
860
  const file_path = path.join(__dirname, "tmp", filename);
862
- const uploadFolder = whatsappChannelMessage.type === "image" ? "images" : "files";
863
- const media_url = await util.uploadMedia(file_path, uploadFolder);
861
+ const media_url = await util.uploadMedia(file_path, settings.project_id, settings.token);
864
862
  winston.debug(`(wab) media_url: ${media_url}`);
865
863
 
866
864
  tiledeskJsonMessage = await tlr.toTiledesk(whatsappChannelMessage, firstname, media_url);
@@ -1021,7 +1019,6 @@ router.post("/webhook/:project_id", async (req, res) => {
1021
1019
  let media;
1022
1020
  const util = new TiledeskWhatsapp({
1023
1021
  token: settings.wab_token,
1024
- ID_PROJECT: settings.project_id,
1025
1022
  GRAPH_URL: GRAPH_URL,
1026
1023
  API_URL: API_URL
1027
1024
  });
@@ -1035,7 +1032,7 @@ router.post("/webhook/:project_id", async (req, res) => {
1035
1032
  }
1036
1033
 
1037
1034
  let file_path = path.join(__dirname, "tmp", filename);
1038
- const image_url = await util.uploadMedia(file_path, "images");
1035
+ const image_url = await util.uploadMedia(file_path, settings.project_id, settings.token);
1039
1036
  winston.debug("(wab) image_url: " + image_url);
1040
1037
 
1041
1038
  tiledeskJsonMessage = await tlr.toTiledesk(whatsappChannelMessage, firstname, image_url);
@@ -1051,7 +1048,7 @@ router.post("/webhook/:project_id", async (req, res) => {
1051
1048
  }
1052
1049
  let file_path = path.join(__dirname, "tmp", filename);
1053
1050
 
1054
- const media_url = await util.uploadMedia(file_path, "files");
1051
+ const media_url = await util.uploadMedia(file_path, settings.project_id, settings.token);
1055
1052
  winston.debug("(wab) media_url: " + media_url);
1056
1053
 
1057
1054
  tiledeskJsonMessage = await tlr.toTiledesk(whatsappChannelMessage, firstname, media_url);
@@ -1067,7 +1064,7 @@ router.post("/webhook/:project_id", async (req, res) => {
1067
1064
  }
1068
1065
  let file_path = path.join(__dirname, "tmp", filename);
1069
1066
 
1070
- const media_url = await util.uploadMedia(file_path, "files");
1067
+ const media_url = await util.uploadMedia(file_path, settings.project_id, settings.token);
1071
1068
  winston.debug("(wab) media_url: " + media_url);
1072
1069
 
1073
1070
  tiledeskJsonMessage = await tlr.toTiledesk(whatsappChannelMessage, firstname, media_url);
@@ -1083,7 +1080,7 @@ router.post("/webhook/:project_id", async (req, res) => {
1083
1080
  }
1084
1081
  let file_path = path.join(__dirname, "tmp", filename);
1085
1082
 
1086
- const media_url = await util.uploadMedia(file_path, "files");
1083
+ const media_url = await util.uploadMedia(file_path, settings.project_id, settings.token);
1087
1084
  winston.debug("(wab) media_url: " + media_url);
1088
1085
 
1089
1086
  tiledeskJsonMessage = await tlr.toTiledesk(whatsappChannelMessage, firstname, media_url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-whatsapp-connector",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "Tiledesk Whatsapp connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -36,15 +36,10 @@ class TiledeskWhatsapp {
36
36
  throw new Error('config.API_URL is mandatory');
37
37
  }
38
38
 
39
- if (!config.ID_PROJECT) {
40
- throw new Error('config.ID_PROJECT is mandatory');
41
- }
42
-
43
39
  // this.media = config.channelMedia;
44
40
  this.token = config.token;
45
41
  this.GRAPH_URL = config.GRAPH_URL
46
42
  this.api_url = config.API_URL;
47
- this.id_project = config.ID_PROJECT;
48
43
 
49
44
 
50
45
  this.log = false;
@@ -148,8 +143,8 @@ class TiledeskWhatsapp {
148
143
  })
149
144
  }
150
145
 
151
- async uploadMedia(path) {
152
- let url = `${this.api_url}/${this.id_project}/files/chat`;
146
+ async uploadMedia(path, id_project, token) {
147
+ let url = `${this.api_url}/${id_project}/files/chat`;
153
148
  winston.debug("(wab) [TiledeskWhatsapp] Uploading file...");
154
149
 
155
150
  const form = new FormData();
@@ -158,7 +153,8 @@ class TiledeskWhatsapp {
158
153
  maxContentLength: Infinity,
159
154
  maxBodyLength: Infinity,
160
155
  header: {
161
- ...form.getHeaders()
156
+ ...form.getHeaders(),
157
+ 'Authorization': token
162
158
  }
163
159
  }
164
160