@meltwater/conversations-api-services 1.0.43 → 1.0.45
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.
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.comment = comment;
|
|
7
7
|
exports.deleteMessage = deleteMessage;
|
|
8
8
|
exports.getMedia = getMedia;
|
|
9
|
+
exports.getMediaFromUrl = getMediaFromUrl;
|
|
9
10
|
exports.getOrganization = getOrganization;
|
|
10
11
|
exports.getOrganizations = getOrganizations;
|
|
11
12
|
exports.getProfile = getProfile;
|
|
@@ -14,6 +15,7 @@ exports.getVideoMedia = getVideoMedia;
|
|
|
14
15
|
exports.like = like;
|
|
15
16
|
exports.likedByUser = likedByUser;
|
|
16
17
|
exports.mediaUploadURL = mediaUploadURL;
|
|
18
|
+
exports.privateMessage = privateMessage;
|
|
17
19
|
exports.reply = reply;
|
|
18
20
|
exports.unlike = unlike;
|
|
19
21
|
exports.uploadMedia = uploadMedia;
|
|
@@ -108,6 +110,45 @@ async function comment(token, mediaId, inReplyToId, socialAccountId, messageText
|
|
|
108
110
|
async function reply(token, mediaId, inReplyToId, socialAccountId, messageText, logger) {
|
|
109
111
|
return publish(token, 're', mediaId, inReplyToId, socialAccountId, messageText, logger);
|
|
110
112
|
}
|
|
113
|
+
async function privateMessage(token, messageText, inReplyToId, sourceId, mediaId, logger) {
|
|
114
|
+
messageText = ProcessTextBody(messageText);
|
|
115
|
+
let parentUrnParts = inReplyToId.split('/');
|
|
116
|
+
const parentUrn = parentUrnParts[parentUrnParts.length - 1];
|
|
117
|
+
if (mediaId) {
|
|
118
|
+
mediaId = mediaId.replace('urn:li:image:', 'urn:li:digitalmediaAsset:');
|
|
119
|
+
}
|
|
120
|
+
let body = {
|
|
121
|
+
messagingThread: parentUrn,
|
|
122
|
+
organization: sourceId,
|
|
123
|
+
author: sourceId,
|
|
124
|
+
content: {
|
|
125
|
+
content: {
|
|
126
|
+
string: messageText
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
if (mediaId) {
|
|
131
|
+
body.attachments = [mediaId];
|
|
132
|
+
}
|
|
133
|
+
let response = await _superagent.default.post(`${LINKEDIN_API_REST}/pageMessages`).timeout(5000).set({
|
|
134
|
+
Authorization: `Bearer ${token}`,
|
|
135
|
+
'Content-Type': 'application/json',
|
|
136
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
137
|
+
'LinkedIn-Version': LINKEDIN_VERSION
|
|
138
|
+
}).send(body);
|
|
139
|
+
response = {
|
|
140
|
+
status: 200,
|
|
141
|
+
message: response.headers['x-restli-id']
|
|
142
|
+
};
|
|
143
|
+
let downloadUrl = '';
|
|
144
|
+
if (mediaId) {
|
|
145
|
+
downloadUrl = await getImageMedia(mediaId, token, logger);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
response,
|
|
149
|
+
downloadUrl
|
|
150
|
+
};
|
|
151
|
+
}
|
|
111
152
|
async function publish(token, discussionType, mediaId, inReplyToId, socialAccountId, messageText, logger) {
|
|
112
153
|
// 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.
|
|
113
154
|
if (mediaId) {
|
|
@@ -143,7 +184,7 @@ async function publish(token, discussionType, mediaId, inReplyToId, socialAccoun
|
|
|
143
184
|
actor: socialAccountId,
|
|
144
185
|
message: {
|
|
145
186
|
attributes: attributes,
|
|
146
|
-
text: textWithoutMentions // Replace mention spans with the mention text
|
|
187
|
+
text: textWithoutMentions || '' // Replace mention spans with the mention text
|
|
147
188
|
}
|
|
148
189
|
};
|
|
149
190
|
if (discussionType === 're') {
|
|
@@ -355,6 +396,18 @@ async function getOrganization(urn, token, logger) {
|
|
|
355
396
|
(0, _loggerHelpers.loggerInfo)(logger, `Finished requesting LinkedIn API for organizationId ${urn}`);
|
|
356
397
|
return organization;
|
|
357
398
|
}
|
|
399
|
+
async function getMediaFromUrl(token, url, logger) {
|
|
400
|
+
try {
|
|
401
|
+
const response = await _superagent.default.get(url).responseType('arraybuffer').set({
|
|
402
|
+
Authorization: `Bearer ${token}`,
|
|
403
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
404
|
+
'LinkedIn-Version': LINKEDIN_VERSION
|
|
405
|
+
});
|
|
406
|
+
return response;
|
|
407
|
+
} catch (error) {
|
|
408
|
+
(0, _loggerHelpers.loggerError)(logger, 'Error in getMediaFromUrl', error);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
358
411
|
async function getOrganizations(urn, token, logger) {
|
|
359
412
|
const [,,, id] = urn.split(':');
|
|
360
413
|
let organizations;
|
|
@@ -453,4 +506,7 @@ async function uploadMedia(query, logger) {
|
|
|
453
506
|
}
|
|
454
507
|
function fixedEncodeURIComponent(str) {
|
|
455
508
|
return encodeURIComponent(str).replace(/\(/g, '%28').replace(/\)/g, '%29');
|
|
509
|
+
}
|
|
510
|
+
function ProcessTextBody(bodyText) {
|
|
511
|
+
return bodyText.replace(/\\/g, '\\\\').replace(/#/g, '\\#').replace(/@/g, '\\@').replace(/\*/g, '\\*').replace(/~/g, '\\~').replace(/>/g, '\\>').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/_/g, '\\_').replace(/\[/g, '\\[').replace(/\]/g, '\\]').replace(/\{/g, '\\{').replace(/\}/g, '\\}').replace(/\|/g, '\\|');
|
|
456
512
|
}
|
|
@@ -88,6 +88,45 @@ export async function comment(token, mediaId, inReplyToId, socialAccountId, mess
|
|
|
88
88
|
export async function reply(token, mediaId, inReplyToId, socialAccountId, messageText, logger) {
|
|
89
89
|
return publish(token, 're', mediaId, inReplyToId, socialAccountId, messageText, logger);
|
|
90
90
|
}
|
|
91
|
+
export async function privateMessage(token, messageText, inReplyToId, sourceId, mediaId, logger) {
|
|
92
|
+
messageText = ProcessTextBody(messageText);
|
|
93
|
+
let parentUrnParts = inReplyToId.split('/');
|
|
94
|
+
const parentUrn = parentUrnParts[parentUrnParts.length - 1];
|
|
95
|
+
if (mediaId) {
|
|
96
|
+
mediaId = mediaId.replace('urn:li:image:', 'urn:li:digitalmediaAsset:');
|
|
97
|
+
}
|
|
98
|
+
let body = {
|
|
99
|
+
messagingThread: parentUrn,
|
|
100
|
+
organization: sourceId,
|
|
101
|
+
author: sourceId,
|
|
102
|
+
content: {
|
|
103
|
+
content: {
|
|
104
|
+
string: messageText
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
if (mediaId) {
|
|
109
|
+
body.attachments = [mediaId];
|
|
110
|
+
}
|
|
111
|
+
let response = await superagent.post(`${LINKEDIN_API_REST}/pageMessages`).timeout(5000).set({
|
|
112
|
+
Authorization: `Bearer ${token}`,
|
|
113
|
+
'Content-Type': 'application/json',
|
|
114
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
115
|
+
'LinkedIn-Version': LINKEDIN_VERSION
|
|
116
|
+
}).send(body);
|
|
117
|
+
response = {
|
|
118
|
+
status: 200,
|
|
119
|
+
message: response.headers['x-restli-id']
|
|
120
|
+
};
|
|
121
|
+
let downloadUrl = '';
|
|
122
|
+
if (mediaId) {
|
|
123
|
+
downloadUrl = await getImageMedia(mediaId, token, logger);
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
response,
|
|
127
|
+
downloadUrl
|
|
128
|
+
};
|
|
129
|
+
}
|
|
91
130
|
async function publish(token, discussionType, mediaId, inReplyToId, socialAccountId, messageText, logger) {
|
|
92
131
|
// 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.
|
|
93
132
|
if (mediaId) {
|
|
@@ -123,7 +162,7 @@ async function publish(token, discussionType, mediaId, inReplyToId, socialAccoun
|
|
|
123
162
|
actor: socialAccountId,
|
|
124
163
|
message: {
|
|
125
164
|
attributes: attributes,
|
|
126
|
-
text: textWithoutMentions // Replace mention spans with the mention text
|
|
165
|
+
text: textWithoutMentions || '' // Replace mention spans with the mention text
|
|
127
166
|
}
|
|
128
167
|
};
|
|
129
168
|
if (discussionType === 're') {
|
|
@@ -335,6 +374,18 @@ export async function getOrganization(urn, token, logger) {
|
|
|
335
374
|
loggerInfo(logger, `Finished requesting LinkedIn API for organizationId ${urn}`);
|
|
336
375
|
return organization;
|
|
337
376
|
}
|
|
377
|
+
export async function getMediaFromUrl(token, url, logger) {
|
|
378
|
+
try {
|
|
379
|
+
const response = await superagent.get(url).responseType('arraybuffer').set({
|
|
380
|
+
Authorization: `Bearer ${token}`,
|
|
381
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
382
|
+
'LinkedIn-Version': LINKEDIN_VERSION
|
|
383
|
+
});
|
|
384
|
+
return response;
|
|
385
|
+
} catch (error) {
|
|
386
|
+
loggerError(logger, 'Error in getMediaFromUrl', error);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
338
389
|
export async function getOrganizations(urn, token, logger) {
|
|
339
390
|
const [,,, id] = urn.split(':');
|
|
340
391
|
let organizations;
|
|
@@ -433,4 +484,7 @@ export async function uploadMedia(query, logger) {
|
|
|
433
484
|
}
|
|
434
485
|
function fixedEncodeURIComponent(str) {
|
|
435
486
|
return encodeURIComponent(str).replace(/\(/g, '%28').replace(/\)/g, '%29');
|
|
487
|
+
}
|
|
488
|
+
function ProcessTextBody(bodyText) {
|
|
489
|
+
return bodyText.replace(/\\/g, '\\\\').replace(/#/g, '\\#').replace(/@/g, '\\@').replace(/\*/g, '\\*').replace(/~/g, '\\~').replace(/>/g, '\\>').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/_/g, '\\_').replace(/\[/g, '\\[').replace(/\]/g, '\\]').replace(/\{/g, '\\{').replace(/\}/g, '\\}').replace(/\|/g, '\\|');
|
|
436
490
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meltwater/conversations-api-services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.45",
|
|
4
4
|
"description": "Repository to contain all conversations api services shared across our services",
|
|
5
5
|
"main": "dist/cjs/data-access/index.js",
|
|
6
6
|
"module": "dist/esm/data-access/index.js",
|
|
@@ -115,6 +115,61 @@ export async function comment(token, mediaId,inReplyToId,socialAccountId, messag
|
|
|
115
115
|
export async function reply(token, mediaId,inReplyToId,socialAccountId, messageText, logger){
|
|
116
116
|
return publish(token,'re', mediaId,inReplyToId,socialAccountId, messageText, logger)
|
|
117
117
|
}
|
|
118
|
+
export async function privateMessage(token, messageText, inReplyToId, sourceId, mediaId, logger){
|
|
119
|
+
messageText = ProcessTextBody(messageText);
|
|
120
|
+
let parentUrnParts = inReplyToId.split('/');
|
|
121
|
+
const parentUrn = parentUrnParts[parentUrnParts.length - 1];
|
|
122
|
+
|
|
123
|
+
if (mediaId) {
|
|
124
|
+
mediaId = mediaId.replace(
|
|
125
|
+
'urn:li:image:',
|
|
126
|
+
'urn:li:digitalmediaAsset:'
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let body = {
|
|
131
|
+
messagingThread: parentUrn,
|
|
132
|
+
organization: sourceId,
|
|
133
|
+
author: sourceId,
|
|
134
|
+
content: {
|
|
135
|
+
content: {
|
|
136
|
+
string: messageText,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
if (mediaId) {
|
|
142
|
+
body.attachments = [mediaId];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let response = await superagent
|
|
146
|
+
.post(`${LINKEDIN_API_REST}/pageMessages`)
|
|
147
|
+
.timeout(5000)
|
|
148
|
+
.set({
|
|
149
|
+
Authorization: `Bearer ${token}`,
|
|
150
|
+
'Content-Type': 'application/json',
|
|
151
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
152
|
+
'LinkedIn-Version': LINKEDIN_VERSION,
|
|
153
|
+
})
|
|
154
|
+
.send(body);
|
|
155
|
+
|
|
156
|
+
response = {
|
|
157
|
+
status: 200,
|
|
158
|
+
message: response.headers['x-restli-id'],
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
let downloadUrl = '';
|
|
162
|
+
|
|
163
|
+
if (mediaId) {
|
|
164
|
+
downloadUrl = await getImageMedia(
|
|
165
|
+
mediaId,
|
|
166
|
+
token,
|
|
167
|
+
logger
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {response, downloadUrl};
|
|
172
|
+
}
|
|
118
173
|
|
|
119
174
|
async function publish(token,discussionType, mediaId,inReplyToId,socialAccountId, messageText, logger) {
|
|
120
175
|
// 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.
|
|
@@ -154,7 +209,7 @@ async function publish(token,discussionType, mediaId,inReplyToId,socialAccountId
|
|
|
154
209
|
actor: socialAccountId,
|
|
155
210
|
message: {
|
|
156
211
|
attributes: attributes,
|
|
157
|
-
text: textWithoutMentions // Replace mention spans with the mention text
|
|
212
|
+
text: textWithoutMentions || '' // Replace mention spans with the mention text
|
|
158
213
|
}
|
|
159
214
|
};
|
|
160
215
|
if (discussionType === 're') {
|
|
@@ -455,6 +510,23 @@ export async function getOrganization(urn, token, logger) {
|
|
|
455
510
|
return organization;
|
|
456
511
|
}
|
|
457
512
|
|
|
513
|
+
export async function getMediaFromUrl(token, url, logger) {
|
|
514
|
+
try {
|
|
515
|
+
const response = await superagent
|
|
516
|
+
.get(url)
|
|
517
|
+
.responseType('arraybuffer')
|
|
518
|
+
.set({
|
|
519
|
+
Authorization: `Bearer ${token}`,
|
|
520
|
+
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
521
|
+
'LinkedIn-Version': LINKEDIN_VERSION,
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
return response;
|
|
525
|
+
} catch (error) {
|
|
526
|
+
loggerError(logger,'Error in getMediaFromUrl', error);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
458
530
|
export async function getOrganizations(urn, token, logger) {
|
|
459
531
|
const [, , , id] = urn.split(':');
|
|
460
532
|
let organizations;
|
|
@@ -586,4 +658,21 @@ export async function uploadMedia(query, logger) {
|
|
|
586
658
|
|
|
587
659
|
function fixedEncodeURIComponent(str) {
|
|
588
660
|
return encodeURIComponent(str).replace(/\(/g, '%28').replace(/\)/g, '%29');
|
|
661
|
+
}
|
|
662
|
+
function ProcessTextBody(bodyText) {
|
|
663
|
+
return bodyText
|
|
664
|
+
.replace(/\\/g, '\\\\')
|
|
665
|
+
.replace(/#/g, '\\#')
|
|
666
|
+
.replace(/@/g, '\\@')
|
|
667
|
+
.replace(/\*/g, '\\*')
|
|
668
|
+
.replace(/~/g, '\\~')
|
|
669
|
+
.replace(/>/g, '\\>')
|
|
670
|
+
.replace(/\(/g, '\\(')
|
|
671
|
+
.replace(/\)/g, '\\)')
|
|
672
|
+
.replace(/_/g, '\\_')
|
|
673
|
+
.replace(/\[/g, '\\[')
|
|
674
|
+
.replace(/\]/g, '\\]')
|
|
675
|
+
.replace(/\{/g, '\\{')
|
|
676
|
+
.replace(/\}/g, '\\}')
|
|
677
|
+
.replace(/\|/g, '\\|');
|
|
589
678
|
}
|