@meltwater/conversations-api-services 1.0.22 → 1.0.24
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/dist/cjs/data-access/http/linkedin.native.js +406 -0
- package/dist/cjs/data-access/http/youtube.native.js +94 -0
- package/dist/cjs/data-access/index.js +6 -1
- package/dist/esm/data-access/http/linkedin.native.js +387 -0
- package/dist/esm/data-access/http/youtube.native.js +83 -0
- package/dist/esm/data-access/index.js +3 -1
- package/package.json +1 -1
- package/src/data-access/http/linkedin.native.js +530 -0
- package/src/data-access/http/youtube.native.js +147 -0
- package/src/data-access/index.js +4 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.comment = comment;
|
|
7
|
+
exports.deleteMessage = deleteMessage;
|
|
8
|
+
exports.getMedia = getMedia;
|
|
9
|
+
exports.getOrganization = getOrganization;
|
|
10
|
+
exports.getProfile = getProfile;
|
|
11
|
+
exports.getSocialStats = getSocialStats;
|
|
12
|
+
exports.getVideoMedia = getVideoMedia;
|
|
13
|
+
exports.like = like;
|
|
14
|
+
exports.likedByUser = likedByUser;
|
|
15
|
+
exports.mediaUploadURL = mediaUploadURL;
|
|
16
|
+
exports.reply = reply;
|
|
17
|
+
exports.unlike = unlike;
|
|
18
|
+
exports.uploadMedia = uploadMedia;
|
|
19
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
20
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
21
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
+
const LINKEDIN_API = "https://api.linkedin.com/v2";
|
|
23
|
+
const LINKEDIN_API_VERSION = "2.0.0";
|
|
24
|
+
async function like(token, externalId, socialAccountId, logger) {
|
|
25
|
+
let response;
|
|
26
|
+
let payload = {
|
|
27
|
+
actor: socialAccountId,
|
|
28
|
+
object: externalId
|
|
29
|
+
};
|
|
30
|
+
let query = `${LINKEDIN_API}/socialActions/${fixedEncodeURIComponent(externalId)}/likes`;
|
|
31
|
+
try {
|
|
32
|
+
(0, _loggerHelpers.loggerDebug)(logger, `Linkedin trying to Like `, {
|
|
33
|
+
query,
|
|
34
|
+
payload: JSON.stringify(payload)
|
|
35
|
+
});
|
|
36
|
+
response = await _superagent.default.post(query).timeout(5000) // 5 seconds
|
|
37
|
+
.set({
|
|
38
|
+
Authorization: `Bearer ${token}`,
|
|
39
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
40
|
+
'LinkedIn-Version': '202311'
|
|
41
|
+
}).send(payload);
|
|
42
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Native Linkedin API Like Mutation Response`, {
|
|
43
|
+
response: JSON.stringify(response)
|
|
44
|
+
});
|
|
45
|
+
} catch (err) {
|
|
46
|
+
(0, _loggerHelpers.loggerError)(logger, `Linkedin Like or Unlike Exception`, err);
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
return response.connection || response;
|
|
50
|
+
}
|
|
51
|
+
async function unlike(token, externalId, socialAccountId, logger) {
|
|
52
|
+
let response;
|
|
53
|
+
let payload = {
|
|
54
|
+
actor: socialAccountId,
|
|
55
|
+
object: externalId
|
|
56
|
+
};
|
|
57
|
+
let query = `${LINKEDIN_API}/socialActions/${fixedEncodeURIComponent(externalId)}/likes/${fixedEncodeURIComponent(payload.actor)}?actor=${fixedEncodeURIComponent(payload.actor)}`;
|
|
58
|
+
try {
|
|
59
|
+
(0, _loggerHelpers.loggerDebug)(logger, `Linkedin trying Delete Previous Like `, {
|
|
60
|
+
query,
|
|
61
|
+
payload: JSON.stringify(payload)
|
|
62
|
+
});
|
|
63
|
+
response = await _superagent.default.delete(query).timeout(5000).set({
|
|
64
|
+
Authorization: `Bearer ${token}`,
|
|
65
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
66
|
+
'LinkedIn-Version': '202311'
|
|
67
|
+
});
|
|
68
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Native Linkedin API UNLike Mutation Response`, {
|
|
69
|
+
response: JSON.stringify(response)
|
|
70
|
+
});
|
|
71
|
+
} catch (err) {
|
|
72
|
+
(0, _loggerHelpers.loggerError)(logger, `Linkedin Like or Unlike Exception`, err);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
return response.connection || response;
|
|
76
|
+
}
|
|
77
|
+
async function deleteMessage(token, externalId, sourceId, inReplyToId, logger) {
|
|
78
|
+
const [, comment] = externalId.split(',');
|
|
79
|
+
const commentId = comment.split(')')[0];
|
|
80
|
+
let response;
|
|
81
|
+
const query = `${LINKEDIN_API}/socialActions/${fixedEncodeURIComponent(inReplyToId)}/comments/${commentId}?actor=${fixedEncodeURIComponent(sourceId)}`;
|
|
82
|
+
try {
|
|
83
|
+
(0, _loggerHelpers.loggerDebug)(logger, `Linkedin trying Delete `, {
|
|
84
|
+
query
|
|
85
|
+
});
|
|
86
|
+
response = await _superagent.default.delete(query).timeout(5000).set({
|
|
87
|
+
Authorization: `Bearer ${token}`,
|
|
88
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
89
|
+
'LinkedIn-Version': '202311'
|
|
90
|
+
});
|
|
91
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Native Linkedin API Delete Comment Response`, {
|
|
92
|
+
response: JSON.stringify(response)
|
|
93
|
+
});
|
|
94
|
+
} catch (err) {
|
|
95
|
+
(0, _loggerHelpers.loggerError)(logger, `Linkedin Delete exception details`, {
|
|
96
|
+
err
|
|
97
|
+
});
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
return response;
|
|
101
|
+
}
|
|
102
|
+
async function comment(token, mediaId, inReplyToId, socialAccountId, messageText, logger) {
|
|
103
|
+
return publish(token, 'qt', mediaId, inReplyToId, socialAccountId, messageText, logger);
|
|
104
|
+
}
|
|
105
|
+
async function reply(token, mediaId, inReplyToId, socialAccountId, messageText, logger) {
|
|
106
|
+
return publish(token, 're', mediaId, inReplyToId, socialAccountId, messageText, logger);
|
|
107
|
+
}
|
|
108
|
+
async function publish(token, discussionType, mediaId, inReplyToId, socialAccountId, messageText, logger) {
|
|
109
|
+
// for now this is needed to make the urns from the images api work until the docs are updated to reflect how to use these new ids.
|
|
110
|
+
if (mediaId) {
|
|
111
|
+
mediaId = mediaId.replace('urn:li:image:', 'urn:li:digitalmediaAsset:');
|
|
112
|
+
}
|
|
113
|
+
let body = {
|
|
114
|
+
actor: socialAccountId,
|
|
115
|
+
message: {
|
|
116
|
+
attributes: [],
|
|
117
|
+
text: messageText
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
if (discussionType === 're') {
|
|
121
|
+
body.parentComment = inReplyToId;
|
|
122
|
+
}
|
|
123
|
+
if (mediaId) {
|
|
124
|
+
body.content = [{
|
|
125
|
+
entity: {
|
|
126
|
+
digitalmediaAsset: mediaId
|
|
127
|
+
},
|
|
128
|
+
type: 'IMAGE'
|
|
129
|
+
}];
|
|
130
|
+
}
|
|
131
|
+
let query = `${LINKEDIN_API}/socialActions/${fixedEncodeURIComponent(inReplyToId)}/comments`;
|
|
132
|
+
|
|
133
|
+
// data-listener -> linkedin_api.client sendComment
|
|
134
|
+
let response;
|
|
135
|
+
let downloadUrl = '';
|
|
136
|
+
try {
|
|
137
|
+
response = await _superagent.default.post(query).timeout(5000).set({
|
|
138
|
+
Authorization: `Bearer ${token}`,
|
|
139
|
+
'Content-Type': 'application/json',
|
|
140
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
141
|
+
'LinkedIn-Version': '202311'
|
|
142
|
+
}).send(body);
|
|
143
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Native Linkedin API Publish Comment Response`, {
|
|
144
|
+
response: JSON.stringify(response)
|
|
145
|
+
});
|
|
146
|
+
response = {
|
|
147
|
+
status: 200,
|
|
148
|
+
message: JSON.parse(response.text)
|
|
149
|
+
};
|
|
150
|
+
if (mediaId) {
|
|
151
|
+
(0, _loggerHelpers.loggerInfo)(logger, `mediaId`, {
|
|
152
|
+
mediaId
|
|
153
|
+
});
|
|
154
|
+
downloadUrl = await getImageMedia(mediaId, token, logger);
|
|
155
|
+
(0, _loggerHelpers.loggerInfo)(logger, `downloadUrl`, {
|
|
156
|
+
downloadUrl
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
} catch (err) {
|
|
160
|
+
(0, _loggerHelpers.loggerError)(logger`Exception in linkedin publish `, err);
|
|
161
|
+
throw err;
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
response,
|
|
165
|
+
downloadUrl
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
async function getImageMedia(mediaId, token, logger) {
|
|
169
|
+
let response = {};
|
|
170
|
+
if (mediaId && mediaId.includes('digitalmediaAsset')) {
|
|
171
|
+
mediaId = mediaId.replace('urn:li:digitalmediaAsset:', 'urn:li:image:');
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
response = await _superagent.default.get(LINKEDIN_API + '/images/' + fixedEncodeURIComponent(mediaId)).timeout(5000) // 5 seconds
|
|
175
|
+
.set({
|
|
176
|
+
Authorization: `Bearer ${token}`,
|
|
177
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
178
|
+
'LinkedIn-Version': '202311'
|
|
179
|
+
});
|
|
180
|
+
} catch (error) {
|
|
181
|
+
(0, _loggerHelpers.loggerError)(logger, 'Error in getImageMedia', error);
|
|
182
|
+
}
|
|
183
|
+
let {
|
|
184
|
+
downloadUrl
|
|
185
|
+
} = response.body || {};
|
|
186
|
+
if (downloadUrl) {
|
|
187
|
+
return {
|
|
188
|
+
downloadUrl
|
|
189
|
+
};
|
|
190
|
+
} else {
|
|
191
|
+
(0, _loggerHelpers.loggerError)(logger, `Invalid response getting Linkedin media for mediaId: ${mediaId} `, {
|
|
192
|
+
response: JSON.stringify(response)
|
|
193
|
+
});
|
|
194
|
+
return {};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function getVideoMedia(mediaId, token, logger) {
|
|
198
|
+
let response = {};
|
|
199
|
+
let tempValue;
|
|
200
|
+
if (mediaId && mediaId.includes('digitalmediaMediaArtifact')) {
|
|
201
|
+
tempValue = mediaId.split('digitalmediaMediaArtifact:(')[1];
|
|
202
|
+
tempValue = tempValue.split(',urn:li:digitalmediaMediaArtifactClass')[0];
|
|
203
|
+
mediaId = tempValue;
|
|
204
|
+
}
|
|
205
|
+
if (mediaId && mediaId.includes('digitalmediaAsset')) {
|
|
206
|
+
mediaId = mediaId.replace('urn:li:digitalmediaAsset:', 'urn:li:video:');
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
response = await _superagent.default.get(LINKEDIN_API + '/videos/' + fixedEncodeURIComponent(mediaId)).timeout(5000) // 5 seconds
|
|
210
|
+
.set({
|
|
211
|
+
Authorization: `Bearer ${token}`,
|
|
212
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
213
|
+
'LinkedIn-Version': '202311'
|
|
214
|
+
});
|
|
215
|
+
} catch (error) {
|
|
216
|
+
(0, _loggerHelpers.loggerError)(logger, 'Error in getVideoMedia', error);
|
|
217
|
+
}
|
|
218
|
+
let {
|
|
219
|
+
thumbnail,
|
|
220
|
+
downloadUrl
|
|
221
|
+
} = response.body || {};
|
|
222
|
+
if (downloadUrl) {
|
|
223
|
+
return {
|
|
224
|
+
thumbnail,
|
|
225
|
+
downloadUrl
|
|
226
|
+
};
|
|
227
|
+
} else {
|
|
228
|
+
(0, _loggerHelpers.loggerError)(logger, `Invalid response getting Linkedin media for mediaId: ${mediaId} `, {
|
|
229
|
+
response: JSON.stringify(response)
|
|
230
|
+
});
|
|
231
|
+
return {};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async function getMedia(token, mediaId, type, logger) {
|
|
235
|
+
// needed due to issue with polled data
|
|
236
|
+
if (type.includes('video') && mediaId.includes('image')) {
|
|
237
|
+
type = 'image/jpeg';
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
if (type.includes('image')) {
|
|
241
|
+
const {
|
|
242
|
+
downloadUrl
|
|
243
|
+
} = await getImageMedia(mediaId, token, logger);
|
|
244
|
+
return {
|
|
245
|
+
downloadUrl
|
|
246
|
+
};
|
|
247
|
+
} else if (type.includes('video')) {
|
|
248
|
+
const {
|
|
249
|
+
thumbnail,
|
|
250
|
+
downloadUrl
|
|
251
|
+
} = await getVideoMedia(mediaId, token, logger);
|
|
252
|
+
return {
|
|
253
|
+
thumbnail,
|
|
254
|
+
downloadUrl
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return {};
|
|
258
|
+
} catch (error) {
|
|
259
|
+
(0, _loggerHelpers.loggerError)(logger, 'Error in getMedia', error);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async function mediaUploadURL(token, socialAccountId, logger) {
|
|
263
|
+
let query = `${LINKEDIN_API}/images?action=initializeUpload`;
|
|
264
|
+
let body = {
|
|
265
|
+
initializeUploadRequest: {
|
|
266
|
+
owner: socialAccountId
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
let response;
|
|
270
|
+
try {
|
|
271
|
+
response = await _superagent.default.post(query).timeout(5000).set({
|
|
272
|
+
Authorization: `Bearer ${token}`,
|
|
273
|
+
'Content-type': 'application/json',
|
|
274
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
275
|
+
'LinkedIn-Version': '202311'
|
|
276
|
+
}).send(body);
|
|
277
|
+
response = {
|
|
278
|
+
status: 200,
|
|
279
|
+
message: JSON.parse(response.text)
|
|
280
|
+
};
|
|
281
|
+
return response;
|
|
282
|
+
} catch (err) {
|
|
283
|
+
(0, _loggerHelpers.loggerError)(logger, `Exception linkedin media register `, err);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async function getProfile(urn, token, logger) {
|
|
287
|
+
let [,,, id] = urn.split(':');
|
|
288
|
+
let profile;
|
|
289
|
+
try {
|
|
290
|
+
profile = await _superagent.default.get(`${LINKEDIN_API}/people/(id:${id})`).query({
|
|
291
|
+
projection: '(id,localizedFirstName,localizedLastName,vanityName,profilePicture(displayImage~:playableStreams))'
|
|
292
|
+
}).timeout(5000).set({
|
|
293
|
+
Authorization: `Bearer ${token}`,
|
|
294
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
295
|
+
'LinkedIn-Version': '202311'
|
|
296
|
+
}).then(result => result.body);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed requesting LinkedIn API for profileId ${urn}`, error);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Finished requesting LinkedIn API for profileId ${urn}`);
|
|
302
|
+
return profile;
|
|
303
|
+
}
|
|
304
|
+
async function getOrganization(urn, token, logger) {
|
|
305
|
+
let [,,, id] = urn.split(':');
|
|
306
|
+
let organization;
|
|
307
|
+
try {
|
|
308
|
+
organization = await _superagent.default.get(`${LINKEDIN_API}/organizations/${id}`).query({
|
|
309
|
+
projection: '(id,localizedName,vanityName,logoV2(original~:playableStreams))'
|
|
310
|
+
}).timeout(5000) // 5 seconds
|
|
311
|
+
.set({
|
|
312
|
+
Authorization: `Bearer ${token}`,
|
|
313
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
314
|
+
'LinkedIn-Version': '202311'
|
|
315
|
+
}).then(result => result.body);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
if (error.response.body.message.includes('ADMIN_ONLY')) {
|
|
318
|
+
return {
|
|
319
|
+
id: 'private'
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed requesting LinkedIn API for organizationId ${urn}`, error);
|
|
323
|
+
}
|
|
324
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Finished requesting LinkedIn API for organizationId ${urn}`);
|
|
325
|
+
return organization;
|
|
326
|
+
}
|
|
327
|
+
async function getAllStats(externalId, token, logger) {
|
|
328
|
+
let response = {};
|
|
329
|
+
try {
|
|
330
|
+
response = await _superagent.default.get(LINKEDIN_API + '/socialMetadata/' + fixedEncodeURIComponent(externalId)).timeout(5000) // 5 seconds
|
|
331
|
+
.set({
|
|
332
|
+
Authorization: `Bearer ${token}`,
|
|
333
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
334
|
+
'LinkedIn-Version': '202311'
|
|
335
|
+
});
|
|
336
|
+
} catch (error) {
|
|
337
|
+
(0, _loggerHelpers.loggerError)(logger, 'Error in getAllStats', error);
|
|
338
|
+
}
|
|
339
|
+
let {
|
|
340
|
+
commentSummary,
|
|
341
|
+
reactionSummaries
|
|
342
|
+
} = response.body || {};
|
|
343
|
+
if (commentSummary && reactionSummaries) {
|
|
344
|
+
return {
|
|
345
|
+
commentSummary,
|
|
346
|
+
reactionSummaries
|
|
347
|
+
};
|
|
348
|
+
} else {
|
|
349
|
+
(0, _loggerHelpers.loggerError)(logger, `Invalid response getting all Linkedin Stats for externalId: ${externalId}`, {
|
|
350
|
+
response: JSON.stringify(response)
|
|
351
|
+
});
|
|
352
|
+
return {};
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async function getSocialStats(externalId, token, logger) {
|
|
356
|
+
try {
|
|
357
|
+
// get all stats (likes are not to be trusted) seems to only work
|
|
358
|
+
// for og posts.
|
|
359
|
+
const {
|
|
360
|
+
commentSummary,
|
|
361
|
+
reactionSummaries
|
|
362
|
+
} = await getAllStats(externalId, token, logger);
|
|
363
|
+
return {
|
|
364
|
+
commentSummary,
|
|
365
|
+
reactionSummaries
|
|
366
|
+
};
|
|
367
|
+
} catch (error) {
|
|
368
|
+
(0, _loggerHelpers.loggerError)(logger, 'Error in getSocialStats', error);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async function likedByUser(token, externalId, authorExternalId, logger) {
|
|
372
|
+
let result;
|
|
373
|
+
try {
|
|
374
|
+
result = await _superagent.default.get(`${LINKEDIN_API}/reactions/(actor:${fixedEncodeURIComponent(authorExternalId)},entity:${fixedEncodeURIComponent(externalId)})`).set({
|
|
375
|
+
Authorization: `Bearer ${token}`,
|
|
376
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
377
|
+
'LinkedIn-Version': '202311'
|
|
378
|
+
}).then(result => result.body);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
(0, _loggerHelpers.loggerError)(logger, 'Error in getLikesByUser', error);
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// query object is from AssetManager
|
|
387
|
+
async function uploadMedia(query, logger) {
|
|
388
|
+
const {
|
|
389
|
+
url,
|
|
390
|
+
token,
|
|
391
|
+
data
|
|
392
|
+
} = query;
|
|
393
|
+
return await _superagent.default.put(url).set({
|
|
394
|
+
Accept: '*/*',
|
|
395
|
+
'Content-Type': 'application/octet-stream',
|
|
396
|
+
Authorization: `Bearer ${token}`,
|
|
397
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
398
|
+
'LinkedIn-Version': '202311'
|
|
399
|
+
}).send(data).catch(err => {
|
|
400
|
+
(0, _loggerHelpers.loggerError)(logger, "Linkedin Error uploading Media", err);
|
|
401
|
+
throw err;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function fixedEncodeURIComponent(str) {
|
|
405
|
+
return encodeURIComponent(str).replace(/\(/g, '%28').replace(/\)/g, '%29');
|
|
406
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.comment = comment;
|
|
7
|
+
exports.likeVideo = likeVideo;
|
|
8
|
+
exports.reply = reply;
|
|
9
|
+
exports.sendRequest = sendRequest;
|
|
10
|
+
exports.unlikeVideo = unlikeVideo;
|
|
11
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
12
|
+
var _externalIdHelpers = require("../../lib/externalId.helpers.js");
|
|
13
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
const YOUTUBE_API_URL = "https://www.googleapis.com/youtube/v3/";
|
|
16
|
+
async function sendPost(token) {
|
|
17
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
18
|
+
let postData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
19
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
20
|
+
let response = {};
|
|
21
|
+
try {
|
|
22
|
+
response = await _superagent.default.post(YOUTUBE_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Authorization', `Bearer ${token}`).send(postData);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
25
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
26
|
+
} else {
|
|
27
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call youtube api for paramString ${paramString}`, err);
|
|
28
|
+
}
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
33
|
+
async function sendRequest(token) {
|
|
34
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
35
|
+
let logger = arguments.length > 2 ? arguments[2] : undefined;
|
|
36
|
+
let response = {};
|
|
37
|
+
try {
|
|
38
|
+
response = await _superagent.default.get(YOUTUBE_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Authorization', `Bearer ${token}`).send();
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
41
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
42
|
+
} else {
|
|
43
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call youtube api for paramString ${paramString}`, err);
|
|
44
|
+
}
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
if (response.status !== 200) {
|
|
48
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call facebook api`, {
|
|
49
|
+
responseBody: JSON.stringify(response.body)
|
|
50
|
+
});
|
|
51
|
+
let error = new Error(`Failed to call facebook api`);
|
|
52
|
+
error.code = response.status;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
return response.body;
|
|
56
|
+
}
|
|
57
|
+
async function likeVideo(token, externalId, logger) {
|
|
58
|
+
return setVideoRating(token, externalId, true, logger);
|
|
59
|
+
}
|
|
60
|
+
async function unlikeVideo(token, externalId, logger) {
|
|
61
|
+
return setVideoRating(token, externalId, false, logger);
|
|
62
|
+
}
|
|
63
|
+
async function setVideoRating(token, externalId) {
|
|
64
|
+
let like = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
65
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
66
|
+
const requestResult = await sendPost(token, `videos/rate?id=${(0, _externalIdHelpers.removePrefix)(externalId)}&rating=${like ? 'like' : 'dislike'}`, logger);
|
|
67
|
+
return requestResult;
|
|
68
|
+
}
|
|
69
|
+
async function comment(token, inReplyToId, textOriginal, logger) {
|
|
70
|
+
const {
|
|
71
|
+
body: publishedMessage
|
|
72
|
+
} = (await sendPost(token, 'commentThreads?part=snippet', {
|
|
73
|
+
snippet: {
|
|
74
|
+
videoId: inReplyToId,
|
|
75
|
+
topLevelComment: {
|
|
76
|
+
snippet: {
|
|
77
|
+
textOriginal
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, logger)) || {};
|
|
82
|
+
return publishedMessage;
|
|
83
|
+
}
|
|
84
|
+
async function reply(token, inReplyToId, textOriginal, logger) {
|
|
85
|
+
const {
|
|
86
|
+
body: publishedMessage
|
|
87
|
+
} = await sendPost(token, 'comments?part=snippet', {
|
|
88
|
+
snippet: {
|
|
89
|
+
textOriginal,
|
|
90
|
+
parentId: inReplyToId
|
|
91
|
+
}
|
|
92
|
+
}, logger);
|
|
93
|
+
return publishedMessage;
|
|
94
|
+
}
|
|
@@ -65,7 +65,7 @@ Object.defineProperty(exports, "LinkedInApiClient", {
|
|
|
65
65
|
return _linkedInApiClient.LinkedInApiClient;
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
|
-
exports.LinkedInHelpers = void 0;
|
|
68
|
+
exports.LinkedinNative = exports.LinkedInHelpers = void 0;
|
|
69
69
|
Object.defineProperty(exports, "MasfClient", {
|
|
70
70
|
enumerable: true,
|
|
71
71
|
get: function () {
|
|
@@ -85,6 +85,7 @@ Object.defineProperty(exports, "WarpZoneApiClient", {
|
|
|
85
85
|
return _WarpZoneApiClient.WarpZoneApiClient;
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
|
+
exports.YoutubeNative = void 0;
|
|
88
89
|
Object.defineProperty(exports, "assetManagerTvmRepository", {
|
|
89
90
|
enumerable: true,
|
|
90
91
|
get: function () {
|
|
@@ -119,6 +120,10 @@ var FacebookNative = _interopRequireWildcard(require("./http/facebook.native.js"
|
|
|
119
120
|
exports.FacebookNative = FacebookNative;
|
|
120
121
|
var TiktokNative = _interopRequireWildcard(require("./http/tiktok.native.js"));
|
|
121
122
|
exports.TiktokNative = TiktokNative;
|
|
123
|
+
var YoutubeNative = _interopRequireWildcard(require("./http/youtube.native.js"));
|
|
124
|
+
exports.YoutubeNative = YoutubeNative;
|
|
125
|
+
var LinkedinNative = _interopRequireWildcard(require("./http/linkedin.native.js"));
|
|
126
|
+
exports.LinkedinNative = LinkedinNative;
|
|
122
127
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
123
128
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
124
129
|
const DocumentHelperFunctions = exports.DocumentHelperFunctions = {
|