@meltwater/conversations-api-services 1.1.0 → 1.1.2
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 +27 -23
- package/dist/cjs/data-access/http/threads.native.js +21 -0
- package/dist/esm/data-access/http/facebook.native.js +27 -23
- package/dist/esm/data-access/http/threads.native.js +21 -0
- package/package.json +1 -1
- package/src/data-access/http/facebook.native.js +36 -32
- package/src/data-access/http/threads.native.js +35 -1
|
@@ -180,32 +180,36 @@ async function unlike(token, externalId, logger) {
|
|
|
180
180
|
return response.body;
|
|
181
181
|
}
|
|
182
182
|
async function isUserBanned(token, authorId, pageId, logger) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
const response = await getApi(`${FACEBOOK_URL}/${pageId}/blocked`, token, undefined,
|
|
189
|
-
// payload
|
|
190
|
-
{
|
|
191
|
-
user: (0, _externalIdHelpers.removePrefix)(authorId)
|
|
192
|
-
}, logger);
|
|
193
|
-
if (response && response.body && response.body.data) {
|
|
194
|
-
const userNoPrefix = (0, _externalIdHelpers.removePrefix)(authorId);
|
|
195
|
-
const user = response.body.data.find(user => {
|
|
196
|
-
if (user.id == userNoPrefix) {
|
|
197
|
-
return user;
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
if (user) {
|
|
201
|
-
return true;
|
|
202
|
-
} else {
|
|
183
|
+
try {
|
|
184
|
+
if (!pageId) {
|
|
185
|
+
// if no pageId to check this call will fail
|
|
186
|
+
// should only happen with temp edge docs
|
|
203
187
|
return false;
|
|
204
188
|
}
|
|
189
|
+
const response = await getApi(`${FACEBOOK_URL}/${pageId}/blocked`, token, undefined,
|
|
190
|
+
// payload
|
|
191
|
+
{
|
|
192
|
+
user: (0, _externalIdHelpers.removePrefix)(authorId)
|
|
193
|
+
}, logger);
|
|
194
|
+
if (response && response.body && response.body.data) {
|
|
195
|
+
const userNoPrefix = (0, _externalIdHelpers.removePrefix)(authorId);
|
|
196
|
+
const user = response.body.data.find(user => {
|
|
197
|
+
if (user.id == userNoPrefix) {
|
|
198
|
+
return user;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
if (user) {
|
|
202
|
+
return true;
|
|
203
|
+
} else {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Native Facebook API is User Banned Response was invalid`, {
|
|
208
|
+
responseBody: JSON.stringify(response.body)
|
|
209
|
+
});
|
|
210
|
+
} catch (err) {
|
|
211
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call facebook api isUserBanned for userId ${authorId} ${pageId}`, err);
|
|
205
212
|
}
|
|
206
|
-
(0, _loggerHelpers.loggerInfo)(logger, `Native Facebook API is User Banned Response was invalid`, {
|
|
207
|
-
responseBody: JSON.stringify(response.body)
|
|
208
|
-
});
|
|
209
213
|
return false;
|
|
210
214
|
}
|
|
211
215
|
async function getProfile(token, authorId, logger) {
|
|
@@ -10,6 +10,26 @@ var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
const THREADS_URL = 'https://graph.threads.net/v1.0';
|
|
12
12
|
const THREADS_PUBLISH_URL = `${THREADS_URL}/me/threads_publish`;
|
|
13
|
+
async function confirmCreationId(accessToken, creationId, logger) {
|
|
14
|
+
let retry = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
15
|
+
let response = {};
|
|
16
|
+
response = await _superagent.default.get(`${THREADS_URL}/${creationId}`).set('Accept', 'application/json').set('Content-Type', 'application/json').query({
|
|
17
|
+
access_token: accessToken,
|
|
18
|
+
fields: 'id,status,error_message'
|
|
19
|
+
}).send();
|
|
20
|
+
if (response.body.status == 'IN_PROGRESS' && retry < 11) {
|
|
21
|
+
// small wait for first attempt, sometimes its just a text post that doesn't take long
|
|
22
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Creation ID is in progress ${creationId} retry ${retry} Waiting ${retry ? 60 : 10} seconds`);
|
|
23
|
+
await new Promise(resolve => setTimeout(resolve, retry ? 60000 : 10000));
|
|
24
|
+
return await confirmCreationId(accessToken, creationId, logger, retry + 1);
|
|
25
|
+
} else if (response.body.status == 'IN_PROGRESS' && retry == 11) {
|
|
26
|
+
let error = new Error(`Creation ID is in progress BUT TAKING TOO LONG ${creationId}`);
|
|
27
|
+
error.code = response.status;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
(0, _loggerHelpers.loggerDebug)(logger, 'Threads Response status', response.status);
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
13
33
|
async function requestApi(apiUrl, accessToken, inReplyToId, text, asset, logger) {
|
|
14
34
|
let response = {};
|
|
15
35
|
try {
|
|
@@ -39,6 +59,7 @@ async function requestApi(apiUrl, accessToken, inReplyToId, text, asset, logger)
|
|
|
39
59
|
};
|
|
40
60
|
}
|
|
41
61
|
const containerResponse = await _superagent.default.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(query).send();
|
|
62
|
+
await confirmCreationId(accessToken, containerResponse.body.id, logger);
|
|
42
63
|
response = await _superagent.default.post(THREADS_PUBLISH_URL).set('Accept', 'application/json').set('Content-Type', 'application/json').query({
|
|
43
64
|
access_token: accessToken,
|
|
44
65
|
creation_id: containerResponse.body.id
|
|
@@ -161,32 +161,36 @@ export async function unlike(token, externalId, logger) {
|
|
|
161
161
|
return response.body;
|
|
162
162
|
}
|
|
163
163
|
export async function isUserBanned(token, authorId, pageId, logger) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
const response = await getApi(`${FACEBOOK_URL}/${pageId}/blocked`, token, undefined,
|
|
170
|
-
// payload
|
|
171
|
-
{
|
|
172
|
-
user: removePrefix(authorId)
|
|
173
|
-
}, logger);
|
|
174
|
-
if (response && response.body && response.body.data) {
|
|
175
|
-
const userNoPrefix = removePrefix(authorId);
|
|
176
|
-
const user = response.body.data.find(user => {
|
|
177
|
-
if (user.id == userNoPrefix) {
|
|
178
|
-
return user;
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
if (user) {
|
|
182
|
-
return true;
|
|
183
|
-
} else {
|
|
164
|
+
try {
|
|
165
|
+
if (!pageId) {
|
|
166
|
+
// if no pageId to check this call will fail
|
|
167
|
+
// should only happen with temp edge docs
|
|
184
168
|
return false;
|
|
185
169
|
}
|
|
170
|
+
const response = await getApi(`${FACEBOOK_URL}/${pageId}/blocked`, token, undefined,
|
|
171
|
+
// payload
|
|
172
|
+
{
|
|
173
|
+
user: removePrefix(authorId)
|
|
174
|
+
}, logger);
|
|
175
|
+
if (response && response.body && response.body.data) {
|
|
176
|
+
const userNoPrefix = removePrefix(authorId);
|
|
177
|
+
const user = response.body.data.find(user => {
|
|
178
|
+
if (user.id == userNoPrefix) {
|
|
179
|
+
return user;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
if (user) {
|
|
183
|
+
return true;
|
|
184
|
+
} else {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
loggerInfo(logger, `Native Facebook API is User Banned Response was invalid`, {
|
|
189
|
+
responseBody: JSON.stringify(response.body)
|
|
190
|
+
});
|
|
191
|
+
} catch (err) {
|
|
192
|
+
loggerError(logger, `Failed to call facebook api isUserBanned for userId ${authorId} ${pageId}`, err);
|
|
186
193
|
}
|
|
187
|
-
loggerInfo(logger, `Native Facebook API is User Banned Response was invalid`, {
|
|
188
|
-
responseBody: JSON.stringify(response.body)
|
|
189
|
-
});
|
|
190
194
|
return false;
|
|
191
195
|
}
|
|
192
196
|
export async function getProfile(token, authorId, logger) {
|
|
@@ -3,6 +3,26 @@ import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
|
3
3
|
import { loggerDebug, loggerError, loggerInfo } from '../../lib/logger.helpers.js';
|
|
4
4
|
const THREADS_URL = 'https://graph.threads.net/v1.0';
|
|
5
5
|
const THREADS_PUBLISH_URL = `${THREADS_URL}/me/threads_publish`;
|
|
6
|
+
async function confirmCreationId(accessToken, creationId, logger) {
|
|
7
|
+
let retry = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
8
|
+
let response = {};
|
|
9
|
+
response = await superagent.get(`${THREADS_URL}/${creationId}`).set('Accept', 'application/json').set('Content-Type', 'application/json').query({
|
|
10
|
+
access_token: accessToken,
|
|
11
|
+
fields: 'id,status,error_message'
|
|
12
|
+
}).send();
|
|
13
|
+
if (response.body.status == 'IN_PROGRESS' && retry < 11) {
|
|
14
|
+
// small wait for first attempt, sometimes its just a text post that doesn't take long
|
|
15
|
+
loggerInfo(logger, `Creation ID is in progress ${creationId} retry ${retry} Waiting ${retry ? 60 : 10} seconds`);
|
|
16
|
+
await new Promise(resolve => setTimeout(resolve, retry ? 60000 : 10000));
|
|
17
|
+
return await confirmCreationId(accessToken, creationId, logger, retry + 1);
|
|
18
|
+
} else if (response.body.status == 'IN_PROGRESS' && retry == 11) {
|
|
19
|
+
let error = new Error(`Creation ID is in progress BUT TAKING TOO LONG ${creationId}`);
|
|
20
|
+
error.code = response.status;
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
loggerDebug(logger, 'Threads Response status', response.status);
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
6
26
|
async function requestApi(apiUrl, accessToken, inReplyToId, text, asset, logger) {
|
|
7
27
|
let response = {};
|
|
8
28
|
try {
|
|
@@ -32,6 +52,7 @@ async function requestApi(apiUrl, accessToken, inReplyToId, text, asset, logger)
|
|
|
32
52
|
};
|
|
33
53
|
}
|
|
34
54
|
const containerResponse = await superagent.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(query).send();
|
|
55
|
+
await confirmCreationId(accessToken, containerResponse.body.id, logger);
|
|
35
56
|
response = await superagent.post(THREADS_PUBLISH_URL).set('Accept', 'application/json').set('Content-Type', 'application/json').query({
|
|
36
57
|
access_token: accessToken,
|
|
37
58
|
creation_id: containerResponse.body.id
|
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.2",
|
|
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",
|
|
@@ -242,42 +242,46 @@ export async function unlike(token, externalId, logger) {
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
export async function isUserBanned(token, authorId, pageId, logger) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
const response = await getApi(
|
|
251
|
-
`${FACEBOOK_URL}/${pageId}/blocked`,
|
|
252
|
-
token,
|
|
253
|
-
undefined, // payload
|
|
254
|
-
{
|
|
255
|
-
user: removePrefix(authorId),
|
|
256
|
-
},
|
|
257
|
-
logger
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
if (response && response.body && response.body.data) {
|
|
261
|
-
const userNoPrefix = removePrefix(authorId);
|
|
262
|
-
const user = response.body.data.find((user) => {
|
|
263
|
-
if (user.id == userNoPrefix) {
|
|
264
|
-
return user;
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
if (user) {
|
|
268
|
-
return true;
|
|
269
|
-
} else {
|
|
245
|
+
try{
|
|
246
|
+
if (!pageId) {
|
|
247
|
+
// if no pageId to check this call will fail
|
|
248
|
+
// should only happen with temp edge docs
|
|
270
249
|
return false;
|
|
271
250
|
}
|
|
272
|
-
|
|
251
|
+
const response = await getApi(
|
|
252
|
+
`${FACEBOOK_URL}/${pageId}/blocked`,
|
|
253
|
+
token,
|
|
254
|
+
undefined, // payload
|
|
255
|
+
{
|
|
256
|
+
user: removePrefix(authorId),
|
|
257
|
+
},
|
|
258
|
+
logger
|
|
259
|
+
);
|
|
273
260
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
261
|
+
if (response && response.body && response.body.data) {
|
|
262
|
+
const userNoPrefix = removePrefix(authorId);
|
|
263
|
+
const user = response.body.data.find((user) => {
|
|
264
|
+
if (user.id == userNoPrefix) {
|
|
265
|
+
return user;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
if (user) {
|
|
269
|
+
return true;
|
|
270
|
+
} else {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
279
273
|
}
|
|
280
|
-
|
|
274
|
+
|
|
275
|
+
loggerInfo(
|
|
276
|
+
logger,
|
|
277
|
+
`Native Facebook API is User Banned Response was invalid`,
|
|
278
|
+
{
|
|
279
|
+
responseBody: JSON.stringify(response.body),
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
}catch(err){
|
|
283
|
+
loggerError(logger, `Failed to call facebook api isUserBanned for userId ${authorId} ${pageId}`, err);
|
|
284
|
+
}
|
|
281
285
|
return false;
|
|
282
286
|
}
|
|
283
287
|
|
|
@@ -7,6 +7,40 @@ const THREADS_URL = 'https://graph.threads.net/v1.0';
|
|
|
7
7
|
const THREADS_PUBLISH_URL = `${THREADS_URL}/me/threads_publish`;
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
async function confirmCreationId(accessToken, creationId, logger, retry = 0) {
|
|
11
|
+
let response = {};
|
|
12
|
+
|
|
13
|
+
response = await superagent
|
|
14
|
+
.get(`${THREADS_URL}/${creationId}`)
|
|
15
|
+
.set('Accept', 'application/json')
|
|
16
|
+
.set('Content-Type', 'application/json')
|
|
17
|
+
.query({
|
|
18
|
+
access_token: accessToken,
|
|
19
|
+
fields: 'id,status,error_message',
|
|
20
|
+
})
|
|
21
|
+
.send();
|
|
22
|
+
if(response.body.status == 'IN_PROGRESS' && retry < 11){
|
|
23
|
+
// small wait for first attempt, sometimes its just a text post that doesn't take long
|
|
24
|
+
loggerInfo(logger,
|
|
25
|
+
`Creation ID is in progress ${creationId} retry ${retry} Waiting ${retry ? 60 : 10} seconds`
|
|
26
|
+
);
|
|
27
|
+
await new Promise((resolve) => setTimeout(resolve, retry ? 60000 : 10000));
|
|
28
|
+
return await confirmCreationId(accessToken, creationId, logger, retry + 1);
|
|
29
|
+
}else if(response.body.status == 'IN_PROGRESS' && retry == 11){
|
|
30
|
+
let error = new Error(
|
|
31
|
+
`Creation ID is in progress BUT TAKING TOO LONG ${creationId}`
|
|
32
|
+
);
|
|
33
|
+
error.code = response.status;
|
|
34
|
+
throw error
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
loggerDebug(logger,'Threads Response status', response.status);
|
|
39
|
+
|
|
40
|
+
return response;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
10
44
|
async function requestApi(
|
|
11
45
|
apiUrl,
|
|
12
46
|
accessToken,
|
|
@@ -51,7 +85,7 @@ async function requestApi(
|
|
|
51
85
|
.set('Content-Type', 'application/json')
|
|
52
86
|
.query(query)
|
|
53
87
|
.send();
|
|
54
|
-
|
|
88
|
+
await confirmCreationId(accessToken, containerResponse.body.id, logger);
|
|
55
89
|
response = await superagent
|
|
56
90
|
.post(THREADS_PUBLISH_URL)
|
|
57
91
|
.set('Accept', 'application/json')
|