@meltwater/conversations-api-services 1.1.13 → 1.1.15
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/facebook.native.js +1 -1
- package/dist/cjs/data-access/http/instagram.native.js +9 -5
- package/dist/esm/data-access/http/facebook.native.js +1 -1
- package/dist/esm/data-access/http/instagram.native.js +9 -5
- package/package.json +1 -1
- package/src/data-access/http/facebook.native.js +1 -1
- package/src/data-access/http/instagram.native.js +18 -11
|
@@ -148,7 +148,7 @@ async function hide(token, externalId, logger) {
|
|
|
148
148
|
const response = await postApi(`${FACEBOOK_URL}/${(0, _externalIdHelpers.removePrefix)(externalId)}`, token, {
|
|
149
149
|
is_hidden: true
|
|
150
150
|
}, logger);
|
|
151
|
-
(0, _loggerHelpers.loggerInfo)(logger`Native Facebook API Hide Response`, {
|
|
151
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Native Facebook API Hide Response`, {
|
|
152
152
|
responseBody: JSON.stringify(response.body)
|
|
153
153
|
});
|
|
154
154
|
return response.body;
|
|
@@ -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: {
|
|
@@ -129,7 +129,7 @@ export async function hide(token, externalId, logger) {
|
|
|
129
129
|
const response = await postApi(`${FACEBOOK_URL}/${removePrefix(externalId)}`, token, {
|
|
130
130
|
is_hidden: true
|
|
131
131
|
}, logger);
|
|
132
|
-
loggerInfo(logger`Native Facebook API Hide Response`, {
|
|
132
|
+
loggerInfo(logger, `Native Facebook API Hide Response`, {
|
|
133
133
|
responseBody: JSON.stringify(response.body)
|
|
134
134
|
});
|
|
135
135
|
return response.body;
|
|
@@ -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: {
|
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.15",
|
|
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",
|
|
@@ -187,7 +187,7 @@ export async function hide(token, externalId, logger) {
|
|
|
187
187
|
logger
|
|
188
188
|
);
|
|
189
189
|
|
|
190
|
-
loggerInfo(logger
|
|
190
|
+
loggerInfo(logger,`Native Facebook API Hide Response`, {
|
|
191
191
|
responseBody: JSON.stringify(response.body),
|
|
192
192
|
});
|
|
193
193
|
return response.body;
|
|
@@ -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
|
{
|