@meltwater/conversations-api-services 1.0.49 → 1.1.0
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/README.md +1 -1
- package/dist/cjs/data-access/http/facebook.native.js +1 -1
- package/dist/cjs/data-access/http/threads.native.js +71 -0
- package/dist/cjs/data-access/index.js +2 -0
- package/dist/esm/data-access/http/facebook.native.js +1 -1
- package/dist/esm/data-access/http/threads.native.js +64 -0
- package/dist/esm/data-access/index.js +2 -0
- package/package.json +1 -1
- package/src/data-access/http/facebook.native.js +1 -1
- package/src/data-access/http/threads.native.js +118 -0
- package/src/data-access/index.js +2 -0
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ async function shareCount(token, externalId, logger) {
|
|
|
25
25
|
try {
|
|
26
26
|
const response = await getApi(`${FACEBOOK_URL}/${(0, _externalIdHelpers.removePrefix)(externalId)}/?fields=shares`, token);
|
|
27
27
|
return response.body.shares && response.body.shares.count;
|
|
28
|
-
} catch (
|
|
28
|
+
} catch (error) {
|
|
29
29
|
(0, _loggerHelpers.loggerError)(logger, `Facebook shareCount error recieved - ${error.code}`, error);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.comment = comment;
|
|
7
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
8
|
+
var _externalIdHelpers = require("../../lib/externalId.helpers.js");
|
|
9
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const THREADS_URL = 'https://graph.threads.net/v1.0';
|
|
12
|
+
const THREADS_PUBLISH_URL = `${THREADS_URL}/me/threads_publish`;
|
|
13
|
+
async function requestApi(apiUrl, accessToken, inReplyToId, text, asset, logger) {
|
|
14
|
+
let response = {};
|
|
15
|
+
try {
|
|
16
|
+
let query = {
|
|
17
|
+
access_token: accessToken,
|
|
18
|
+
reply_to_id: inReplyToId,
|
|
19
|
+
text
|
|
20
|
+
};
|
|
21
|
+
if (!asset) {
|
|
22
|
+
query = {
|
|
23
|
+
...query,
|
|
24
|
+
media_type: 'TEXT'
|
|
25
|
+
};
|
|
26
|
+
} else if (asset.type === 'image') {
|
|
27
|
+
query = {
|
|
28
|
+
...query,
|
|
29
|
+
media_type: 'IMAGE',
|
|
30
|
+
image_url: asset.url,
|
|
31
|
+
alt_text: asset.altText ?? ''
|
|
32
|
+
};
|
|
33
|
+
} else if (asset.type === 'video') {
|
|
34
|
+
query = {
|
|
35
|
+
...query,
|
|
36
|
+
media_type: 'VIDEO',
|
|
37
|
+
video_url: asset.url,
|
|
38
|
+
alt_text: asset.altText ?? ''
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const containerResponse = await _superagent.default.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(query).send();
|
|
42
|
+
response = await _superagent.default.post(THREADS_PUBLISH_URL).set('Accept', 'application/json').set('Content-Type', 'application/json').query({
|
|
43
|
+
access_token: accessToken,
|
|
44
|
+
creation_id: containerResponse.body.id
|
|
45
|
+
}).send();
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
48
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call threads api: ${err.response.body.error.message}`);
|
|
49
|
+
} else {
|
|
50
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call threads api`, err);
|
|
51
|
+
}
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
if (response.status !== 200) {
|
|
55
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call threads api`, {
|
|
56
|
+
responseBody: JSON.stringify(response.body)
|
|
57
|
+
});
|
|
58
|
+
let error = new Error(`Failed to call threads api`);
|
|
59
|
+
error.code = response.status;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
(0, _loggerHelpers.loggerDebug)(logger, 'Threads Response status', response.status);
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
async function comment(accessToken, inReplyToId, text, asset, logger) {
|
|
66
|
+
let response = await requestApi(`${THREADS_URL}/me/threads`, accessToken, (0, _externalIdHelpers.removePrefix)(inReplyToId), text, asset, logger);
|
|
67
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Native Threads API Publish Comment Response`, {
|
|
68
|
+
responseBody: JSON.stringify(response.body)
|
|
69
|
+
});
|
|
70
|
+
return response.body;
|
|
71
|
+
}
|
|
@@ -29,6 +29,7 @@ var YoutubeNative = _interopRequireWildcard(require("./http/youtube.native.js"))
|
|
|
29
29
|
var LinkedinNative = _interopRequireWildcard(require("./http/linkedin.native.js"));
|
|
30
30
|
var TwitterNative = _interopRequireWildcard(require("./http/twitter.native.js"));
|
|
31
31
|
var InstagramNative = _interopRequireWildcard(require("./http/instagram.native.js"));
|
|
32
|
+
var ThreadsNative = _interopRequireWildcard(require("./http/threads.native.js"));
|
|
32
33
|
var AssetManagerClient = _interopRequireWildcard(require("./http/assetManager.client.js"));
|
|
33
34
|
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); }
|
|
34
35
|
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; }
|
|
@@ -45,6 +46,7 @@ const LinkedInHelpers = {
|
|
|
45
46
|
var _default = exports.default = {
|
|
46
47
|
InstagramNative,
|
|
47
48
|
FacebookNative,
|
|
49
|
+
ThreadsNative,
|
|
48
50
|
TiktokNative,
|
|
49
51
|
YoutubeNative,
|
|
50
52
|
LinkedinNative,
|
|
@@ -6,7 +6,7 @@ export async function shareCount(token, externalId, logger) {
|
|
|
6
6
|
try {
|
|
7
7
|
const response = await getApi(`${FACEBOOK_URL}/${removePrefix(externalId)}/?fields=shares`, token);
|
|
8
8
|
return response.body.shares && response.body.shares.count;
|
|
9
|
-
} catch (
|
|
9
|
+
} catch (error) {
|
|
10
10
|
loggerError(logger, `Facebook shareCount error recieved - ${error.code}`, error);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import superagent from 'superagent';
|
|
2
|
+
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
3
|
+
import { loggerDebug, loggerError, loggerInfo } from '../../lib/logger.helpers.js';
|
|
4
|
+
const THREADS_URL = 'https://graph.threads.net/v1.0';
|
|
5
|
+
const THREADS_PUBLISH_URL = `${THREADS_URL}/me/threads_publish`;
|
|
6
|
+
async function requestApi(apiUrl, accessToken, inReplyToId, text, asset, logger) {
|
|
7
|
+
let response = {};
|
|
8
|
+
try {
|
|
9
|
+
let query = {
|
|
10
|
+
access_token: accessToken,
|
|
11
|
+
reply_to_id: inReplyToId,
|
|
12
|
+
text
|
|
13
|
+
};
|
|
14
|
+
if (!asset) {
|
|
15
|
+
query = {
|
|
16
|
+
...query,
|
|
17
|
+
media_type: 'TEXT'
|
|
18
|
+
};
|
|
19
|
+
} else if (asset.type === 'image') {
|
|
20
|
+
query = {
|
|
21
|
+
...query,
|
|
22
|
+
media_type: 'IMAGE',
|
|
23
|
+
image_url: asset.url,
|
|
24
|
+
alt_text: asset.altText ?? ''
|
|
25
|
+
};
|
|
26
|
+
} else if (asset.type === 'video') {
|
|
27
|
+
query = {
|
|
28
|
+
...query,
|
|
29
|
+
media_type: 'VIDEO',
|
|
30
|
+
video_url: asset.url,
|
|
31
|
+
alt_text: asset.altText ?? ''
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const containerResponse = await superagent.post(apiUrl).set('Accept', 'application/json').set('Content-Type', 'application/json').query(query).send();
|
|
35
|
+
response = await superagent.post(THREADS_PUBLISH_URL).set('Accept', 'application/json').set('Content-Type', 'application/json').query({
|
|
36
|
+
access_token: accessToken,
|
|
37
|
+
creation_id: containerResponse.body.id
|
|
38
|
+
}).send();
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
41
|
+
loggerError(logger, `Failed to call threads api: ${err.response.body.error.message}`);
|
|
42
|
+
} else {
|
|
43
|
+
loggerError(logger, `Failed to call threads api`, err);
|
|
44
|
+
}
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
if (response.status !== 200) {
|
|
48
|
+
loggerError(logger, `Failed to call threads api`, {
|
|
49
|
+
responseBody: JSON.stringify(response.body)
|
|
50
|
+
});
|
|
51
|
+
let error = new Error(`Failed to call threads api`);
|
|
52
|
+
error.code = response.status;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
loggerDebug(logger, 'Threads Response status', response.status);
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
export async function comment(accessToken, inReplyToId, text, asset, logger) {
|
|
59
|
+
let response = await requestApi(`${THREADS_URL}/me/threads`, accessToken, removePrefix(inReplyToId), text, asset, logger);
|
|
60
|
+
loggerInfo(logger, `Native Threads API Publish Comment Response`, {
|
|
61
|
+
responseBody: JSON.stringify(response.body)
|
|
62
|
+
});
|
|
63
|
+
return response.body;
|
|
64
|
+
}
|
|
@@ -22,6 +22,7 @@ import * as YoutubeNative from './http/youtube.native.js';
|
|
|
22
22
|
import * as LinkedinNative from './http/linkedin.native.js';
|
|
23
23
|
import * as TwitterNative from './http/twitter.native.js';
|
|
24
24
|
import * as InstagramNative from './http/instagram.native.js';
|
|
25
|
+
import * as ThreadsNative from './http/threads.native.js';
|
|
25
26
|
import * as AssetManagerClient from './http/assetManager.client.js';
|
|
26
27
|
const DocumentHelperFunctions = {
|
|
27
28
|
...messageHelpers,
|
|
@@ -36,6 +37,7 @@ const LinkedInHelpers = {
|
|
|
36
37
|
export default {
|
|
37
38
|
InstagramNative,
|
|
38
39
|
FacebookNative,
|
|
40
|
+
ThreadsNative,
|
|
39
41
|
TiktokNative,
|
|
40
42
|
YoutubeNative,
|
|
41
43
|
LinkedinNative,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meltwater/conversations-api-services",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|
|
@@ -15,7 +15,7 @@ export async function shareCount(token, externalId, logger) {
|
|
|
15
15
|
token
|
|
16
16
|
);
|
|
17
17
|
return response.body.shares && response.body.shares.count;
|
|
18
|
-
} catch (
|
|
18
|
+
} catch (error) {
|
|
19
19
|
loggerError(
|
|
20
20
|
logger,
|
|
21
21
|
`Facebook shareCount error recieved - ${error.code}`,
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import superagent from 'superagent';
|
|
2
|
+
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
3
|
+
import { loggerDebug, loggerError, loggerInfo } from '../../lib/logger.helpers.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const THREADS_URL = 'https://graph.threads.net/v1.0';
|
|
7
|
+
const THREADS_PUBLISH_URL = `${THREADS_URL}/me/threads_publish`;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async function requestApi(
|
|
11
|
+
apiUrl,
|
|
12
|
+
accessToken,
|
|
13
|
+
inReplyToId,
|
|
14
|
+
text,
|
|
15
|
+
asset,
|
|
16
|
+
logger
|
|
17
|
+
) {
|
|
18
|
+
let response = {};
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
let query = {
|
|
22
|
+
access_token: accessToken,
|
|
23
|
+
reply_to_id: inReplyToId,
|
|
24
|
+
text,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (!asset) {
|
|
28
|
+
query = {
|
|
29
|
+
...query,
|
|
30
|
+
media_type: 'TEXT',
|
|
31
|
+
};
|
|
32
|
+
} else if (asset.type === 'image') {
|
|
33
|
+
query = {
|
|
34
|
+
...query,
|
|
35
|
+
media_type: 'IMAGE',
|
|
36
|
+
image_url: asset.url,
|
|
37
|
+
alt_text: asset.altText ?? '',
|
|
38
|
+
}
|
|
39
|
+
} else if (asset.type === 'video') {
|
|
40
|
+
query = {
|
|
41
|
+
...query,
|
|
42
|
+
media_type: 'VIDEO',
|
|
43
|
+
video_url: asset.url,
|
|
44
|
+
alt_text: asset.altText ?? '',
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const containerResponse = await superagent
|
|
49
|
+
.post(apiUrl)
|
|
50
|
+
.set('Accept', 'application/json')
|
|
51
|
+
.set('Content-Type', 'application/json')
|
|
52
|
+
.query(query)
|
|
53
|
+
.send();
|
|
54
|
+
|
|
55
|
+
response = await superagent
|
|
56
|
+
.post(THREADS_PUBLISH_URL)
|
|
57
|
+
.set('Accept', 'application/json')
|
|
58
|
+
.set('Content-Type', 'application/json')
|
|
59
|
+
.query({
|
|
60
|
+
access_token: accessToken,
|
|
61
|
+
creation_id: containerResponse.body.id,
|
|
62
|
+
})
|
|
63
|
+
.send();
|
|
64
|
+
|
|
65
|
+
} catch (err) {
|
|
66
|
+
if (
|
|
67
|
+
err &&
|
|
68
|
+
err.response &&
|
|
69
|
+
err.response.body &&
|
|
70
|
+
err.response.body.error
|
|
71
|
+
) {
|
|
72
|
+
loggerError(logger,
|
|
73
|
+
`Failed to call threads api: ${err.response.body.error.message}`
|
|
74
|
+
);
|
|
75
|
+
} else {
|
|
76
|
+
loggerError(logger,
|
|
77
|
+
`Failed to call threads api`,
|
|
78
|
+
err
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (response.status !== 200) {
|
|
85
|
+
loggerError(logger,
|
|
86
|
+
`Failed to call threads api`,
|
|
87
|
+
{ responseBody: JSON.stringify(response.body) }
|
|
88
|
+
);
|
|
89
|
+
let error = new Error(
|
|
90
|
+
`Failed to call threads api`
|
|
91
|
+
);
|
|
92
|
+
error.code = response.status;
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
loggerDebug(logger,'Threads Response status', response.status);
|
|
97
|
+
|
|
98
|
+
return response;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
export async function comment(accessToken, inReplyToId, text,asset, logger) {
|
|
103
|
+
let response = await requestApi(
|
|
104
|
+
`${THREADS_URL}/me/threads`,
|
|
105
|
+
accessToken,
|
|
106
|
+
removePrefix(inReplyToId),
|
|
107
|
+
text,
|
|
108
|
+
asset,
|
|
109
|
+
logger
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
loggerInfo(logger,
|
|
113
|
+
`Native Threads API Publish Comment Response`,
|
|
114
|
+
{ responseBody: JSON.stringify(response.body) }
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return response.body;
|
|
118
|
+
}
|
package/src/data-access/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import * as YoutubeNative from './http/youtube.native.js';
|
|
|
27
27
|
import * as LinkedinNative from './http/linkedin.native.js';
|
|
28
28
|
import * as TwitterNative from './http/twitter.native.js';
|
|
29
29
|
import * as InstagramNative from './http/instagram.native.js';
|
|
30
|
+
import * as ThreadsNative from './http/threads.native.js';
|
|
30
31
|
import * as AssetManagerClient from './http/assetManager.client.js';
|
|
31
32
|
|
|
32
33
|
const DocumentHelperFunctions = {
|
|
@@ -43,6 +44,7 @@ const LinkedInHelpers = {
|
|
|
43
44
|
export default {
|
|
44
45
|
InstagramNative,
|
|
45
46
|
FacebookNative,
|
|
47
|
+
ThreadsNative,
|
|
46
48
|
TiktokNative,
|
|
47
49
|
YoutubeNative,
|
|
48
50
|
LinkedinNative,
|