@meltwater/conversations-api-services 1.1.14 → 1.1.16
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/instagram.native.js +9 -5
- package/dist/cjs/data-access/http/linkedin.native.js +7 -5
- package/dist/esm/data-access/http/instagram.native.js +9 -5
- package/dist/esm/data-access/http/linkedin.native.js +7 -5
- package/package.json +1 -1
- package/src/data-access/http/instagram.native.js +18 -11
- package/src/data-access/http/linkedin.native.js +6 -5
|
@@ -23,16 +23,20 @@ async function requestApi(apiUrl, accessToken, text, data) {
|
|
|
23
23
|
let logger = arguments.length > 6 ? arguments[6] : undefined;
|
|
24
24
|
let response = {};
|
|
25
25
|
try {
|
|
26
|
-
let queryStringArgs = {
|
|
26
|
+
let queryStringArgs = accessToken ? {
|
|
27
27
|
access_token: accessToken
|
|
28
|
-
};
|
|
29
|
-
if (adCampaign) {
|
|
28
|
+
} : undefined;
|
|
29
|
+
if (adCampaign?.adAccountId) {
|
|
30
30
|
queryStringArgs.ad_id = adCampaign.adAccountId;
|
|
31
31
|
}
|
|
32
32
|
if (text) {
|
|
33
33
|
queryStringArgs[discussionType === 'dm' ? 'text' : 'message'] = text;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
if (queryStringArgs) {
|
|
36
|
+
response = await _superagent.default.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(queryStringArgs).send(data);
|
|
37
|
+
} else {
|
|
38
|
+
response = await _superagent.default.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').send(data);
|
|
39
|
+
}
|
|
36
40
|
} catch (err) {
|
|
37
41
|
if (err && err.response && err.response.body && err.response.body.error) {
|
|
38
42
|
(0, _loggerHelpers.loggerError)(logger, `Failed to call instagram api: ${err.response.body.error.message}`);
|
|
@@ -229,7 +233,7 @@ async function replyHelper(accessToken, payload, logger) {
|
|
|
229
233
|
return response.body;
|
|
230
234
|
}
|
|
231
235
|
async function privateMessage(accessToken, profileId, text, logger) {
|
|
232
|
-
const response = await requestApi(`${INSTAGRAM_URL}/v10.0/me/messages`,
|
|
236
|
+
const response = await requestApi(`${INSTAGRAM_URL}/v10.0/me/messages?access_token=${accessToken}`, undefined,
|
|
233
237
|
// this sends in query string leaving out :shrug:
|
|
234
238
|
undefined, {
|
|
235
239
|
recipient: {
|
|
@@ -32,7 +32,7 @@ async function like(token, externalId, socialAccountId, logger) {
|
|
|
32
32
|
actor: socialAccountId,
|
|
33
33
|
object: externalId
|
|
34
34
|
};
|
|
35
|
-
let query = `${
|
|
35
|
+
let query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(externalId)}/likes`;
|
|
36
36
|
try {
|
|
37
37
|
(0, _loggerHelpers.loggerDebug)(logger, `Linkedin trying to Like `, {
|
|
38
38
|
query,
|
|
@@ -59,7 +59,7 @@ async function unlike(token, externalId, socialAccountId, logger) {
|
|
|
59
59
|
actor: socialAccountId,
|
|
60
60
|
object: externalId
|
|
61
61
|
};
|
|
62
|
-
let query = `${
|
|
62
|
+
let query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(externalId)}/likes/${fixedEncodeURIComponent(payload.actor)}?actor=${fixedEncodeURIComponent(payload.actor)}`;
|
|
63
63
|
try {
|
|
64
64
|
(0, _loggerHelpers.loggerDebug)(logger, `Linkedin trying Delete Previous Like `, {
|
|
65
65
|
query,
|
|
@@ -83,7 +83,7 @@ async function deleteMessage(token, externalId, sourceId, inReplyToId, logger) {
|
|
|
83
83
|
const [, comment] = externalId.split(',');
|
|
84
84
|
const commentId = comment.split(')')[0];
|
|
85
85
|
let response;
|
|
86
|
-
const query = `${
|
|
86
|
+
const query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(inReplyToId)}/comments/${commentId}?actor=${fixedEncodeURIComponent(sourceId)}`;
|
|
87
87
|
try {
|
|
88
88
|
(0, _loggerHelpers.loggerDebug)(logger, `Linkedin trying Delete `, {
|
|
89
89
|
query
|
|
@@ -182,6 +182,8 @@ async function publish(token, discussionType, mediaId, inReplyToId, socialAccoun
|
|
|
182
182
|
}
|
|
183
183
|
let body = {
|
|
184
184
|
actor: socialAccountId,
|
|
185
|
+
object: inReplyToId,
|
|
186
|
+
// Required field for REST API
|
|
185
187
|
message: {
|
|
186
188
|
attributes: attributes,
|
|
187
189
|
text: textWithoutMentions || '' // Replace mention spans with the mention text
|
|
@@ -198,7 +200,7 @@ async function publish(token, discussionType, mediaId, inReplyToId, socialAccoun
|
|
|
198
200
|
type: 'IMAGE'
|
|
199
201
|
}];
|
|
200
202
|
}
|
|
201
|
-
let query = `${
|
|
203
|
+
let query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(inReplyToId)}/comments`;
|
|
202
204
|
|
|
203
205
|
// data-listener -> linkedin_api.client sendComment
|
|
204
206
|
let response;
|
|
@@ -474,7 +476,7 @@ async function getSocialStats(externalId, token, logger) {
|
|
|
474
476
|
async function likedByUser(token, externalId, authorExternalId, logger) {
|
|
475
477
|
let result;
|
|
476
478
|
try {
|
|
477
|
-
result = await _superagent.default.get(`${
|
|
479
|
+
result = await _superagent.default.get(`${LINKEDIN_API_REST}/reactions/(actor:${fixedEncodeURIComponent(authorExternalId)},entity:${fixedEncodeURIComponent(externalId)})`).set({
|
|
478
480
|
Authorization: `Bearer ${token}`,
|
|
479
481
|
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
480
482
|
'LinkedIn-Version': LINKEDIN_VERSION
|
|
@@ -8,16 +8,20 @@ async function requestApi(apiUrl, accessToken, text, data) {
|
|
|
8
8
|
let logger = arguments.length > 6 ? arguments[6] : undefined;
|
|
9
9
|
let response = {};
|
|
10
10
|
try {
|
|
11
|
-
let queryStringArgs = {
|
|
11
|
+
let queryStringArgs = accessToken ? {
|
|
12
12
|
access_token: accessToken
|
|
13
|
-
};
|
|
14
|
-
if (adCampaign) {
|
|
13
|
+
} : undefined;
|
|
14
|
+
if (adCampaign?.adAccountId) {
|
|
15
15
|
queryStringArgs.ad_id = adCampaign.adAccountId;
|
|
16
16
|
}
|
|
17
17
|
if (text) {
|
|
18
18
|
queryStringArgs[discussionType === 'dm' ? 'text' : 'message'] = text;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
if (queryStringArgs) {
|
|
21
|
+
response = await superagent.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(queryStringArgs).send(data);
|
|
22
|
+
} else {
|
|
23
|
+
response = await superagent.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').send(data);
|
|
24
|
+
}
|
|
21
25
|
} catch (err) {
|
|
22
26
|
if (err && err.response && err.response.body && err.response.body.error) {
|
|
23
27
|
loggerError(logger, `Failed to call instagram api: ${err.response.body.error.message}`);
|
|
@@ -214,7 +218,7 @@ async function replyHelper(accessToken, payload, logger) {
|
|
|
214
218
|
return response.body;
|
|
215
219
|
}
|
|
216
220
|
export async function privateMessage(accessToken, profileId, text, logger) {
|
|
217
|
-
const response = await requestApi(`${INSTAGRAM_URL}/v10.0/me/messages`,
|
|
221
|
+
const response = await requestApi(`${INSTAGRAM_URL}/v10.0/me/messages?access_token=${accessToken}`, undefined,
|
|
218
222
|
// this sends in query string leaving out :shrug:
|
|
219
223
|
undefined, {
|
|
220
224
|
recipient: {
|
|
@@ -10,7 +10,7 @@ export async function like(token, externalId, socialAccountId, logger) {
|
|
|
10
10
|
actor: socialAccountId,
|
|
11
11
|
object: externalId
|
|
12
12
|
};
|
|
13
|
-
let query = `${
|
|
13
|
+
let query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(externalId)}/likes`;
|
|
14
14
|
try {
|
|
15
15
|
loggerDebug(logger, `Linkedin trying to Like `, {
|
|
16
16
|
query,
|
|
@@ -37,7 +37,7 @@ export async function unlike(token, externalId, socialAccountId, logger) {
|
|
|
37
37
|
actor: socialAccountId,
|
|
38
38
|
object: externalId
|
|
39
39
|
};
|
|
40
|
-
let query = `${
|
|
40
|
+
let query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(externalId)}/likes/${fixedEncodeURIComponent(payload.actor)}?actor=${fixedEncodeURIComponent(payload.actor)}`;
|
|
41
41
|
try {
|
|
42
42
|
loggerDebug(logger, `Linkedin trying Delete Previous Like `, {
|
|
43
43
|
query,
|
|
@@ -61,7 +61,7 @@ export async function deleteMessage(token, externalId, sourceId, inReplyToId, lo
|
|
|
61
61
|
const [, comment] = externalId.split(',');
|
|
62
62
|
const commentId = comment.split(')')[0];
|
|
63
63
|
let response;
|
|
64
|
-
const query = `${
|
|
64
|
+
const query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(inReplyToId)}/comments/${commentId}?actor=${fixedEncodeURIComponent(sourceId)}`;
|
|
65
65
|
try {
|
|
66
66
|
loggerDebug(logger, `Linkedin trying Delete `, {
|
|
67
67
|
query
|
|
@@ -160,6 +160,8 @@ async function publish(token, discussionType, mediaId, inReplyToId, socialAccoun
|
|
|
160
160
|
}
|
|
161
161
|
let body = {
|
|
162
162
|
actor: socialAccountId,
|
|
163
|
+
object: inReplyToId,
|
|
164
|
+
// Required field for REST API
|
|
163
165
|
message: {
|
|
164
166
|
attributes: attributes,
|
|
165
167
|
text: textWithoutMentions || '' // Replace mention spans with the mention text
|
|
@@ -176,7 +178,7 @@ async function publish(token, discussionType, mediaId, inReplyToId, socialAccoun
|
|
|
176
178
|
type: 'IMAGE'
|
|
177
179
|
}];
|
|
178
180
|
}
|
|
179
|
-
let query = `${
|
|
181
|
+
let query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(inReplyToId)}/comments`;
|
|
180
182
|
|
|
181
183
|
// data-listener -> linkedin_api.client sendComment
|
|
182
184
|
let response;
|
|
@@ -452,7 +454,7 @@ export async function getSocialStats(externalId, token, logger) {
|
|
|
452
454
|
export async function likedByUser(token, externalId, authorExternalId, logger) {
|
|
453
455
|
let result;
|
|
454
456
|
try {
|
|
455
|
-
result = await superagent.get(`${
|
|
457
|
+
result = await superagent.get(`${LINKEDIN_API_REST}/reactions/(actor:${fixedEncodeURIComponent(authorExternalId)},entity:${fixedEncodeURIComponent(externalId)})`).set({
|
|
456
458
|
Authorization: `Bearer ${token}`,
|
|
457
459
|
'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
|
|
458
460
|
'LinkedIn-Version': LINKEDIN_VERSION
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meltwater/conversations-api-services",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.16",
|
|
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",
|
|
@@ -18,8 +18,8 @@ async function requestApi(
|
|
|
18
18
|
let response = {};
|
|
19
19
|
|
|
20
20
|
try {
|
|
21
|
-
let queryStringArgs = { access_token: accessToken };
|
|
22
|
-
if (adCampaign) {
|
|
21
|
+
let queryStringArgs =accessToken? { access_token: accessToken } : undefined;
|
|
22
|
+
if (adCampaign?.adAccountId) {
|
|
23
23
|
queryStringArgs.ad_id = adCampaign.adAccountId;
|
|
24
24
|
}
|
|
25
25
|
if (text) {
|
|
@@ -27,13 +27,20 @@ async function requestApi(
|
|
|
27
27
|
discussionType === 'dm' ? 'text' : 'message'
|
|
28
28
|
] = text;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
if(queryStringArgs){
|
|
31
|
+
response = await superagent
|
|
32
|
+
.post(apiUrl)
|
|
33
|
+
.set('Accept', 'application/json')
|
|
34
|
+
.set('Content-Type', 'application/json')
|
|
35
|
+
.query(queryStringArgs)
|
|
36
|
+
.send(data);
|
|
37
|
+
}else{
|
|
38
|
+
response = await superagent
|
|
39
|
+
.post(apiUrl)
|
|
40
|
+
.set('Accept', 'application/json')
|
|
41
|
+
.set('Content-Type', 'application/json')
|
|
42
|
+
.send(data);
|
|
43
|
+
}
|
|
37
44
|
} catch (err) {
|
|
38
45
|
if (
|
|
39
46
|
err &&
|
|
@@ -385,8 +392,8 @@ async function replyHelper(accessToken, payload, logger) {
|
|
|
385
392
|
|
|
386
393
|
export async function privateMessage(accessToken, profileId, text, logger) {
|
|
387
394
|
const response = await requestApi(
|
|
388
|
-
`${INSTAGRAM_URL}/v10.0/me/messages`,
|
|
389
|
-
|
|
395
|
+
`${INSTAGRAM_URL}/v10.0/me/messages?access_token=${accessToken}`,
|
|
396
|
+
undefined,
|
|
390
397
|
// this sends in query string leaving out :shrug:
|
|
391
398
|
undefined,
|
|
392
399
|
{
|
|
@@ -10,7 +10,7 @@ const LINKEDIN_VERSION = "202411";
|
|
|
10
10
|
export async function like(token, externalId, socialAccountId, logger) {
|
|
11
11
|
let response;
|
|
12
12
|
let payload = { actor: socialAccountId, object: externalId };
|
|
13
|
-
let query = `${
|
|
13
|
+
let query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(externalId)}/likes`
|
|
14
14
|
|
|
15
15
|
try {
|
|
16
16
|
loggerDebug(logger,`Linkedin trying to Like `, {
|
|
@@ -42,7 +42,7 @@ export async function like(token, externalId, socialAccountId, logger) {
|
|
|
42
42
|
export async function unlike(token, externalId, socialAccountId, logger) {
|
|
43
43
|
let response;
|
|
44
44
|
let payload = { actor: socialAccountId, object: externalId };
|
|
45
|
-
let query = `${
|
|
45
|
+
let query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(
|
|
46
46
|
externalId
|
|
47
47
|
)}/likes/${fixedEncodeURIComponent(
|
|
48
48
|
payload.actor
|
|
@@ -78,7 +78,7 @@ export async function deleteMessage(token, externalId, sourceId, inReplyToId, lo
|
|
|
78
78
|
const commentId = comment.split(')')[0];
|
|
79
79
|
|
|
80
80
|
let response;
|
|
81
|
-
const query = `${
|
|
81
|
+
const query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(
|
|
82
82
|
inReplyToId
|
|
83
83
|
)}/comments/${commentId}?actor=${fixedEncodeURIComponent(sourceId)}`;
|
|
84
84
|
|
|
@@ -207,6 +207,7 @@ async function publish(token,discussionType, mediaId,inReplyToId,socialAccountId
|
|
|
207
207
|
|
|
208
208
|
let body = {
|
|
209
209
|
actor: socialAccountId,
|
|
210
|
+
object: inReplyToId, // Required field for REST API
|
|
210
211
|
message: {
|
|
211
212
|
attributes: attributes,
|
|
212
213
|
text: textWithoutMentions || '' // Replace mention spans with the mention text
|
|
@@ -226,7 +227,7 @@ async function publish(token,discussionType, mediaId,inReplyToId,socialAccountId
|
|
|
226
227
|
];
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
let query = `${
|
|
230
|
+
let query = `${LINKEDIN_API_REST}/socialActions/${fixedEncodeURIComponent(inReplyToId)}/comments`;
|
|
230
231
|
|
|
231
232
|
// data-listener -> linkedin_api.client sendComment
|
|
232
233
|
let response;
|
|
@@ -619,7 +620,7 @@ export async function likedByUser(
|
|
|
619
620
|
try {
|
|
620
621
|
result = await superagent
|
|
621
622
|
.get(
|
|
622
|
-
`${
|
|
623
|
+
`${LINKEDIN_API_REST}/reactions/(actor:${fixedEncodeURIComponent(
|
|
623
624
|
authorExternalId
|
|
624
625
|
)},entity:${fixedEncodeURIComponent(externalId)})`
|
|
625
626
|
)
|