@meltwater/conversations-api-services 1.3.2 → 1.4.0
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/.github/workflows/release.yml +4 -6
- package/CLAUDE.md +70 -0
- package/dist/cjs/data-access/http/facebook.native.js +122 -106
- package/dist/cjs/data-access/http/instagram.native.js +92 -49
- package/dist/cjs/data-access/http/linkedin.native.js +135 -56
- package/dist/cjs/data-access/http/threads.native.js +53 -18
- package/dist/cjs/data-access/http/tiktok.native.js +18 -12
- package/dist/cjs/data-access/http/twitter.native.js +142 -40
- package/dist/cjs/data-access/http/youtube.native.js +19 -13
- package/dist/esm/data-access/http/facebook.native.js +123 -107
- package/dist/esm/data-access/http/instagram.native.js +93 -50
- package/dist/esm/data-access/http/linkedin.native.js +136 -57
- package/dist/esm/data-access/http/threads.native.js +54 -19
- package/dist/esm/data-access/http/tiktok.native.js +19 -13
- package/dist/esm/data-access/http/twitter.native.js +143 -41
- package/dist/esm/data-access/http/youtube.native.js +20 -14
- package/package.json +1 -3
- package/src/data-access/http/README.md +50 -0
- package/src/data-access/http/facebook.native.js +122 -144
- package/src/data-access/http/instagram.native.js +113 -93
- package/src/data-access/http/linkedin.native.js +144 -83
- package/src/data-access/http/threads.native.js +58 -27
- package/src/data-access/http/tiktok.native.js +19 -39
- package/src/data-access/http/twitter.native.js +145 -65
- package/src/data-access/http/youtube.native.js +21 -40
- package/dist/cjs/lib/hiddenComment.helper.js +0 -119
- package/dist/esm/lib/hiddenComment.helper.js +0 -112
- package/src/lib/hiddenComment.helper.js +0 -107
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import superagent from 'superagent';
|
|
2
2
|
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
3
|
-
import { loggerDebug,
|
|
3
|
+
import { loggerDebug, loggerInfo, MeltwaterAttributes } from '../../lib/logger.helpers.js';
|
|
4
4
|
const FACEBOOK_URL = 'https://graph.facebook.com';
|
|
5
5
|
export async function shareCount(token, externalId, logger) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return response.body.shares && response.body.shares.count;
|
|
9
|
-
} catch (error) {
|
|
10
|
-
loggerError(logger, `Facebook shareCount error recieved - ${error.code}`, error);
|
|
11
|
-
}
|
|
6
|
+
const response = await getApi(`${FACEBOOK_URL}/${removePrefix(externalId)}/?fields=shares`, token, undefined, {}, logger);
|
|
7
|
+
return response.body.shares && response.body.shares.count;
|
|
12
8
|
}
|
|
13
9
|
export async function reactions(token, externalIds, logger) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return response.body;
|
|
17
|
-
} catch (error) {
|
|
18
|
-
loggerError(logger, `Facebook reactions error recieved - ${error.code}`, error);
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
10
|
+
const response = await getApi(`${FACEBOOK_URL}?ids=${externalIds.map(externalId => removePrefix(externalId)).join(',')}&fields=` + `reactions.limit(0).summary(viewer_reaction).as(fb_post_reaction_of_user),` + `reactions.type(LOVE).limit(0).summary(total_count).as(fb_post_reactions_love),` + `reactions.type(WOW).limit(0).summary(total_count).as(fb_post_reactions_wow),` + `reactions.type(SAD).limit(0).summary(total_count).as(fb_post_reactions_sad),` + `reactions.type(LIKE).limit(0).summary(total_count).as(fb_post_reactions_like),` + `reactions.type(ANGRY).limit(0).summary(total_count).as(fb_post_reactions_angry),` + `reactions.type(HAHA).limit(0).summary(total_count).as(fb_post_reactions_haha)`, token, undefined, {}, logger);
|
|
11
|
+
return response.body;
|
|
21
12
|
}
|
|
22
13
|
export async function comment(token, _ref) {
|
|
23
14
|
let {
|
|
@@ -64,8 +55,12 @@ export async function privateMessage(token, _ref2, logger) {
|
|
|
64
55
|
});
|
|
65
56
|
const imageResponse = await superagent.get(attachment.link).responseType('arrayBuffer');
|
|
66
57
|
if (imageResponse.status !== 200) {
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
loggerInfo(logger, 'Failed to fetch image from CDN', {
|
|
59
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
60
|
+
recipientId,
|
|
61
|
+
status: imageResponse.status,
|
|
62
|
+
responseBody: imageResponse.body
|
|
63
|
+
})
|
|
69
64
|
});
|
|
70
65
|
throw new Error('Failed to fetch image from CDN');
|
|
71
66
|
}
|
|
@@ -161,37 +156,36 @@ export async function unlike(token, externalId, logger) {
|
|
|
161
156
|
return response.body;
|
|
162
157
|
}
|
|
163
158
|
export async function isUserBanned(token, authorId, pageId, logger) {
|
|
164
|
-
|
|
165
|
-
if
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return user;
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
if (user) {
|
|
183
|
-
return true;
|
|
184
|
-
} else {
|
|
185
|
-
return false;
|
|
159
|
+
if (!pageId) {
|
|
160
|
+
// if no pageId to check this call will fail
|
|
161
|
+
// should only happen with temp edge docs
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const response = await getApi(`${FACEBOOK_URL}/${pageId}/blocked`, token, undefined,
|
|
165
|
+
// payload
|
|
166
|
+
{
|
|
167
|
+
user: removePrefix(authorId)
|
|
168
|
+
}, logger);
|
|
169
|
+
if (response && response.body && response.body.data) {
|
|
170
|
+
const userNoPrefix = removePrefix(authorId);
|
|
171
|
+
const user = response.body.data.find(user => {
|
|
172
|
+
if (user.id == userNoPrefix) {
|
|
173
|
+
return user;
|
|
186
174
|
}
|
|
187
|
-
}
|
|
188
|
-
loggerInfo(logger, `Native Facebook API is User Banned Response was invalid`, {
|
|
189
|
-
responseBody: JSON.stringify(response.body)
|
|
190
175
|
});
|
|
191
|
-
|
|
192
|
-
|
|
176
|
+
if (user) {
|
|
177
|
+
return true;
|
|
178
|
+
} else {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
193
181
|
}
|
|
194
|
-
|
|
182
|
+
loggerInfo(logger, `Native Facebook API is User Banned Response was invalid`, {
|
|
183
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
184
|
+
authorId,
|
|
185
|
+
pageId,
|
|
186
|
+
responseBody: response.body
|
|
187
|
+
})
|
|
188
|
+
});
|
|
195
189
|
}
|
|
196
190
|
export async function getProfile(token, authorId, fields, logger) {
|
|
197
191
|
if (!authorId) {
|
|
@@ -208,16 +202,21 @@ export async function getProfile(token, authorId, fields, logger) {
|
|
|
208
202
|
try {
|
|
209
203
|
response = await superagent.get(`${FACEBOOK_URL}/${userNoPrefix}`).set('Accept', 'application/json').set('Content-Type', 'application/json').query(queryParams).send();
|
|
210
204
|
} catch (err) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
205
|
+
loggerInfo(logger, `Failed to call facebook api for userId`, {
|
|
206
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
207
|
+
userNoPrefix,
|
|
208
|
+
error: err?.response?.body?.error?.message ?? err?.message
|
|
209
|
+
})
|
|
210
|
+
});
|
|
216
211
|
return null;
|
|
217
212
|
}
|
|
218
213
|
if (response.status !== 200) {
|
|
219
|
-
|
|
220
|
-
|
|
214
|
+
loggerInfo(logger, `Failed to call facebook api for userId`, {
|
|
215
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
216
|
+
userNoPrefix,
|
|
217
|
+
status: response.status,
|
|
218
|
+
responseBody: response.body
|
|
219
|
+
})
|
|
221
220
|
});
|
|
222
221
|
let error = new Error(`Failed to call facebook api for userId ${userNoPrefix}`);
|
|
223
222
|
error.code = response.status;
|
|
@@ -247,49 +246,44 @@ export async function unban(token, sourceId, authorId, logger) {
|
|
|
247
246
|
}
|
|
248
247
|
export async function getAttachment(token, externalId, discussionType, logger) {
|
|
249
248
|
let result;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
249
|
+
switch (discussionType) {
|
|
250
|
+
case 're':
|
|
251
|
+
case 'qt':
|
|
252
|
+
result = await getApi(`${FACEBOOK_URL}/${removePrefix(externalId)}?fields=attachment`, token, undefined, undefined, logger);
|
|
253
|
+
return {
|
|
254
|
+
images: [{
|
|
255
|
+
source: result?.body?.attachment?.media?.source || result?.body?.attachment?.media?.image?.src
|
|
256
|
+
}]
|
|
257
|
+
};
|
|
258
|
+
case 'dm':
|
|
259
|
+
result = await getApi(`${FACEBOOK_URL}/${removePrefix(externalId)}?fields=attachments`, token, undefined, undefined, logger);
|
|
260
|
+
return {
|
|
261
|
+
images: result?.body?.attachments?.data.map(item => {
|
|
262
|
+
return {
|
|
263
|
+
source: item.image_data?.url
|
|
264
|
+
};
|
|
265
|
+
})
|
|
266
|
+
};
|
|
267
|
+
default:
|
|
268
|
+
// og
|
|
269
|
+
result = await getApi(`${FACEBOOK_URL}/${removePrefix(externalId)}/attachments?fields=media,subattachments,file_url`, token, undefined, undefined, logger);
|
|
270
|
+
|
|
271
|
+
// if subattachments exist, use them
|
|
272
|
+
const res = result?.body?.data[0];
|
|
273
|
+
if (res?.subattachments) {
|
|
262
274
|
return {
|
|
263
|
-
images:
|
|
275
|
+
images: res?.subattachments.data.map(item => {
|
|
264
276
|
return {
|
|
265
|
-
source: item
|
|
277
|
+
source: item?.media?.source || item?.media?.image?.src
|
|
266
278
|
};
|
|
267
279
|
})
|
|
268
280
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (res?.subattachments) {
|
|
276
|
-
return {
|
|
277
|
-
images: res?.subattachments.data.map(item => {
|
|
278
|
-
return {
|
|
279
|
-
source: item?.media?.source || item?.media?.image?.src
|
|
280
|
-
};
|
|
281
|
-
})
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
images: [{
|
|
286
|
-
source: res?.media?.source || res?.media?.image?.src
|
|
287
|
-
}]
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
} catch (error) {
|
|
291
|
-
loggerError(logger, `Error getting facebook attachment`, error);
|
|
292
|
-
throw error;
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
images: [{
|
|
284
|
+
source: res?.media?.source || res?.media?.image?.src
|
|
285
|
+
}]
|
|
286
|
+
};
|
|
293
287
|
}
|
|
294
288
|
}
|
|
295
289
|
async function getApi(apiUrl, accessToken, payload) {
|
|
@@ -302,16 +296,21 @@ async function getApi(apiUrl, accessToken, payload) {
|
|
|
302
296
|
...queryParams
|
|
303
297
|
}).send(payload);
|
|
304
298
|
} catch (err) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
299
|
+
loggerInfo(logger, `Failed to call facebook getApi`, {
|
|
300
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
301
|
+
apiUrl,
|
|
302
|
+
error: err?.response?.body?.error?.message ?? err?.message
|
|
303
|
+
})
|
|
304
|
+
});
|
|
310
305
|
throw err;
|
|
311
306
|
}
|
|
312
307
|
if (response.status !== 200) {
|
|
313
|
-
|
|
314
|
-
|
|
308
|
+
loggerInfo(logger, `Failed to call facebook api`, {
|
|
309
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
310
|
+
apiUrl,
|
|
311
|
+
status: response.status,
|
|
312
|
+
responseBody: response.body
|
|
313
|
+
})
|
|
315
314
|
});
|
|
316
315
|
let error = new Error(`Failed to call facebook api ${apiUrl}`);
|
|
317
316
|
error.code = response.status;
|
|
@@ -345,7 +344,10 @@ async function postApi(apiUrl, accessToken, payload, logger) {
|
|
|
345
344
|
// Handle specific case where content is already marked as spam
|
|
346
345
|
if (err?.response?.body?.error?.error_subcode === 1446036 && err?.response?.body?.error?.error_user_title === "Duplicate Mark Spam Request") {
|
|
347
346
|
loggerInfo(logger, `Content already marked as spam - treating as successful hide operation`, {
|
|
348
|
-
|
|
347
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
348
|
+
apiUrl,
|
|
349
|
+
responseBody: err.response.body
|
|
350
|
+
})
|
|
349
351
|
});
|
|
350
352
|
return {
|
|
351
353
|
status: 200,
|
|
@@ -355,12 +357,21 @@ async function postApi(apiUrl, accessToken, payload, logger) {
|
|
|
355
357
|
}
|
|
356
358
|
};
|
|
357
359
|
}
|
|
358
|
-
loggerDebug(logger, `Failed to call facebook api`,
|
|
360
|
+
loggerDebug(logger, `Failed to call facebook api`, {
|
|
361
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
362
|
+
apiUrl,
|
|
363
|
+
error: err?.message
|
|
364
|
+
})
|
|
365
|
+
});
|
|
359
366
|
throw err;
|
|
360
367
|
}
|
|
361
368
|
if (response.status !== 200) {
|
|
362
|
-
|
|
363
|
-
|
|
369
|
+
loggerInfo(logger, `Failed to call facebook api`, {
|
|
370
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
371
|
+
apiUrl,
|
|
372
|
+
status: response.status,
|
|
373
|
+
responseBody: response.body
|
|
374
|
+
})
|
|
364
375
|
});
|
|
365
376
|
throw new Error(`Failed to call facebook api ${response.body}`);
|
|
366
377
|
}
|
|
@@ -373,16 +384,21 @@ async function deleteApi(apiUrl, accessToken, payload, logger) {
|
|
|
373
384
|
access_token: accessToken
|
|
374
385
|
}).send(payload);
|
|
375
386
|
} catch (err) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
387
|
+
loggerInfo(logger, `Failed to call facebook api delete`, {
|
|
388
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
389
|
+
apiUrl,
|
|
390
|
+
error: err?.response?.body?.error?.message ?? err?.message
|
|
391
|
+
})
|
|
392
|
+
});
|
|
381
393
|
throw err;
|
|
382
394
|
}
|
|
383
395
|
if (response.status !== 200) {
|
|
384
|
-
|
|
385
|
-
|
|
396
|
+
loggerInfo(logger, `Failed to call facebook api delete`, {
|
|
397
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
398
|
+
apiUrl,
|
|
399
|
+
status: response.status,
|
|
400
|
+
responseBody: response.body
|
|
401
|
+
})
|
|
386
402
|
});
|
|
387
403
|
let error = new Error(`Failed to call facebook api delete`);
|
|
388
404
|
error.code = response.status;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import superagent from 'superagent';
|
|
2
2
|
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
3
|
-
import { loggerDebug,
|
|
3
|
+
import { loggerDebug, loggerInfo, loggerWarn, MeltwaterAttributes } from '../../lib/logger.helpers.js';
|
|
4
4
|
const INSTAGRAM_URL = 'https://graph.facebook.com';
|
|
5
5
|
async function requestApi(apiUrl, accessToken, text, data) {
|
|
6
6
|
let discussionType = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 're';
|
|
@@ -23,16 +23,26 @@ async function requestApi(apiUrl, accessToken, text, data) {
|
|
|
23
23
|
response = await superagent.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').send(data);
|
|
24
24
|
}
|
|
25
25
|
} catch (err) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
loggerInfo(logger, `Failed to call instagram api - requestApi`, {
|
|
27
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
28
|
+
apiUrl,
|
|
29
|
+
discussionType,
|
|
30
|
+
adCampaign: adCampaign || undefined,
|
|
31
|
+
text: text || undefined,
|
|
32
|
+
error: err?.response?.body?.error?.message ?? err?.message
|
|
33
|
+
})
|
|
34
|
+
});
|
|
31
35
|
throw err;
|
|
32
36
|
}
|
|
33
37
|
if (response.status !== 200) {
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
loggerInfo(logger, `Failed to call instagram api - requestApi bad status`, {
|
|
39
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
40
|
+
apiUrl,
|
|
41
|
+
discussionType,
|
|
42
|
+
adCampaign: adCampaign || undefined,
|
|
43
|
+
status: response.status,
|
|
44
|
+
responseBody: response.body
|
|
45
|
+
})
|
|
36
46
|
});
|
|
37
47
|
let error = new Error(`Failed to call instagram api`);
|
|
38
48
|
error.code = response.status;
|
|
@@ -50,16 +60,24 @@ async function getPost(apiUrl, accessToken, fields, logger) {
|
|
|
50
60
|
fields: fields
|
|
51
61
|
}).send();
|
|
52
62
|
} catch (err) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
63
|
+
const errObject = {
|
|
64
|
+
apiUrl,
|
|
65
|
+
fields,
|
|
66
|
+
error: err?.response?.body?.error ?? err?.message
|
|
67
|
+
};
|
|
68
|
+
loggerInfo(logger, `Failed to call instagram api - getPost`, {
|
|
69
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify(errObject)
|
|
70
|
+
});
|
|
58
71
|
throw err;
|
|
59
72
|
}
|
|
60
73
|
if (response.status !== 200) {
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
loggerInfo(logger, `Failed to call instagram api - getPost bad status`, {
|
|
75
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
76
|
+
apiUrl,
|
|
77
|
+
fields,
|
|
78
|
+
status: response.status,
|
|
79
|
+
responseBody: response.body
|
|
80
|
+
})
|
|
63
81
|
});
|
|
64
82
|
let error = new Error(`Failed to call instagram api`);
|
|
65
83
|
error.code = response.status;
|
|
@@ -73,7 +91,13 @@ async function getMessageData(accessToken, sourceId, inReplyToId, logger) {
|
|
|
73
91
|
response = await getPost(`${INSTAGRAM_URL}/${sourceId}`, accessToken, `mentioned_comment.comment_id(${inReplyToId}){id, text, timestamp, media{id,media_url}}`, logger);
|
|
74
92
|
return response.body;
|
|
75
93
|
} catch (err) {
|
|
76
|
-
|
|
94
|
+
loggerInfo(logger, `Failed to call instagram api - getMessageData`, {
|
|
95
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
96
|
+
sourceId,
|
|
97
|
+
inReplyToId,
|
|
98
|
+
error: err?.message
|
|
99
|
+
})
|
|
100
|
+
});
|
|
77
101
|
return null;
|
|
78
102
|
}
|
|
79
103
|
}
|
|
@@ -86,16 +110,25 @@ async function mentionRequestApi(apiUrl, accessToken, replayObject, text, logger
|
|
|
86
110
|
message: text
|
|
87
111
|
}).send();
|
|
88
112
|
} catch (err) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
113
|
+
const errObject = {
|
|
114
|
+
apiUrl,
|
|
115
|
+
replayObject,
|
|
116
|
+
text,
|
|
117
|
+
error: err?.response?.body?.error?.message ?? err?.message
|
|
118
|
+
};
|
|
119
|
+
loggerInfo(logger, `Failed to call instagram api - mentionRequestApi`, {
|
|
120
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify(errObject)
|
|
121
|
+
});
|
|
94
122
|
throw err;
|
|
95
123
|
}
|
|
96
124
|
if (response.status !== 200) {
|
|
97
|
-
|
|
98
|
-
|
|
125
|
+
loggerInfo(logger, `Failed to call instagram api - mentionRequestApi bad status`, {
|
|
126
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
127
|
+
apiUrl,
|
|
128
|
+
replayObject,
|
|
129
|
+
status: response.status,
|
|
130
|
+
responseBody: response.body
|
|
131
|
+
})
|
|
99
132
|
});
|
|
100
133
|
let error = new Error(`Failed to call instagram api`);
|
|
101
134
|
error.code = response.status;
|
|
@@ -112,16 +145,24 @@ async function hideApi(apiUrl, accessToken, hideStatus, logger) {
|
|
|
112
145
|
hide: hideStatus
|
|
113
146
|
}).send();
|
|
114
147
|
} catch (err) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
148
|
+
const errObject = {
|
|
149
|
+
apiUrl,
|
|
150
|
+
hideStatus,
|
|
151
|
+
error: err?.response?.body?.error ?? err?.message
|
|
152
|
+
};
|
|
153
|
+
loggerInfo(logger, `Failed to call instagram api - hideApi`, {
|
|
154
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify(errObject)
|
|
155
|
+
});
|
|
120
156
|
throw err;
|
|
121
157
|
}
|
|
122
158
|
if (response.status !== 200) {
|
|
123
|
-
|
|
124
|
-
|
|
159
|
+
loggerInfo(logger, `Failed to call instagram api - hideApi bad status`, {
|
|
160
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
161
|
+
apiUrl,
|
|
162
|
+
hideStatus,
|
|
163
|
+
status: response.status,
|
|
164
|
+
responseBody: response.body
|
|
165
|
+
})
|
|
125
166
|
});
|
|
126
167
|
let error = new Error(`Failed to call instagram api`);
|
|
127
168
|
error.code = response.status;
|
|
@@ -139,10 +180,17 @@ export async function getLikes(accessToken, externalId, logger) {
|
|
|
139
180
|
});
|
|
140
181
|
return response.body;
|
|
141
182
|
} catch (err) {
|
|
183
|
+
const errPayload = {
|
|
184
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
185
|
+
externalId,
|
|
186
|
+
status: err?.status,
|
|
187
|
+
error: err?.message
|
|
188
|
+
})
|
|
189
|
+
};
|
|
142
190
|
if (err?.status === 400) {
|
|
143
|
-
loggerWarn(logger, 'Warn getLikes Instagram Comment probably deleted on native',
|
|
191
|
+
loggerWarn(logger, 'Warn getLikes Instagram Comment probably deleted on native', errPayload);
|
|
144
192
|
} else {
|
|
145
|
-
|
|
193
|
+
loggerInfo(logger, 'Error getLikes Instagram', errPayload);
|
|
146
194
|
}
|
|
147
195
|
return 0;
|
|
148
196
|
}
|
|
@@ -255,25 +303,20 @@ export async function unhide(accessToken, externalId, logger) {
|
|
|
255
303
|
return response.body;
|
|
256
304
|
}
|
|
257
305
|
export async function getAttachment(token, externalId, logger) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (res?.children?.data?.length) {
|
|
262
|
-
return {
|
|
263
|
-
images: res.children.data.map(item => {
|
|
264
|
-
return {
|
|
265
|
-
source: item?.media_url
|
|
266
|
-
};
|
|
267
|
-
})
|
|
268
|
-
};
|
|
269
|
-
}
|
|
306
|
+
const result = await getPost(`${INSTAGRAM_URL}/${removePrefix(externalId)}`, token, 'media_url,children{media_url}', logger);
|
|
307
|
+
const res = result.body;
|
|
308
|
+
if (res?.children?.data?.length) {
|
|
270
309
|
return {
|
|
271
|
-
images:
|
|
272
|
-
|
|
273
|
-
|
|
310
|
+
images: res.children.data.map(item => {
|
|
311
|
+
return {
|
|
312
|
+
source: item?.media_url
|
|
313
|
+
};
|
|
314
|
+
})
|
|
274
315
|
};
|
|
275
|
-
} catch (error) {
|
|
276
|
-
loggerError(logger, `Error getting instagram attachment`, error);
|
|
277
|
-
throw error;
|
|
278
316
|
}
|
|
317
|
+
return {
|
|
318
|
+
images: [{
|
|
319
|
+
source: res?.media_url
|
|
320
|
+
}]
|
|
321
|
+
};
|
|
279
322
|
}
|