@meltwater/conversations-api-services 1.0.19 → 1.0.21
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/.github/workflows/release.yml +2 -0
- package/babel.config.js +18 -0
- package/dist/cjs/data-access/http/InstagramVideoClient.js +42 -0
- package/dist/cjs/data-access/http/WarpZoneApi.client.js +32 -0
- package/dist/cjs/data-access/http/amazonS3.js +44 -0
- package/dist/cjs/data-access/http/asset-manager-tvm.client.js +35 -0
- package/dist/cjs/data-access/http/companiesApi.client.js +38 -0
- package/dist/cjs/data-access/http/credentialsApi.client.js +102 -0
- package/dist/cjs/data-access/http/entitlementsApi.client.js +40 -0
- package/dist/cjs/data-access/http/facebook.native.js +344 -0
- package/dist/cjs/data-access/http/facebookApi.client.js +631 -0
- package/dist/cjs/data-access/http/featureToggleApi.client.js +31 -0
- package/dist/cjs/data-access/http/identityServices.client.js +97 -0
- package/dist/cjs/data-access/http/instagramApi.client.js +428 -0
- package/dist/cjs/data-access/http/ir.client.js +242 -0
- package/dist/cjs/data-access/http/linkedInApi.client.js +491 -0
- package/dist/cjs/data-access/http/masf.client.js +101 -0
- package/dist/cjs/data-access/http/tiktok.native.js +162 -0
- package/dist/cjs/data-access/http/tiktokApi.client.js +441 -0
- package/dist/cjs/data-access/index.js +132 -0
- package/dist/cjs/errors/engage-error.js +16 -0
- package/dist/cjs/errors/http-error.js +23 -0
- package/dist/cjs/lib/applicationTags.helpers.js +30 -0
- package/dist/cjs/lib/configuration.js +14 -0
- package/dist/cjs/lib/document-action-events.js +12 -0
- package/dist/cjs/lib/externalId.helpers.js +19 -0
- package/dist/cjs/lib/hidden.helpers.js +13 -0
- package/dist/cjs/lib/hiddenComment.helper.js +119 -0
- package/dist/cjs/lib/logger.helpers.js +68 -0
- package/dist/cjs/lib/logger.js +23 -0
- package/dist/cjs/lib/message.helpers.js +58 -0
- package/dist/cjs/lib/metrics.helper.js +97 -0
- package/dist/esm/data-access/http/InstagramVideoClient.js +34 -0
- package/dist/esm/data-access/http/WarpZoneApi.client.js +24 -0
- package/dist/esm/data-access/http/amazonS3.js +37 -0
- package/dist/esm/data-access/http/asset-manager-tvm.client.js +28 -0
- package/dist/esm/data-access/http/companiesApi.client.js +30 -0
- package/dist/esm/data-access/http/credentialsApi.client.js +92 -0
- package/dist/esm/data-access/http/entitlementsApi.client.js +32 -0
- package/dist/esm/data-access/http/facebook.native.js +325 -0
- package/dist/esm/data-access/http/facebookApi.client.js +621 -0
- package/dist/esm/data-access/http/featureToggleApi.client.js +23 -0
- package/dist/esm/data-access/http/identityServices.client.js +89 -0
- package/dist/esm/data-access/http/instagramApi.client.js +420 -0
- package/dist/esm/data-access/http/ir.client.js +234 -0
- package/dist/esm/data-access/http/linkedInApi.client.js +481 -0
- package/dist/esm/data-access/http/masf.client.js +93 -0
- package/dist/esm/data-access/http/tiktok.native.js +146 -0
- package/dist/esm/data-access/http/tiktokApi.client.js +433 -0
- package/dist/esm/data-access/index.js +30 -0
- package/dist/esm/errors/engage-error.js +9 -0
- package/dist/esm/errors/http-error.js +16 -0
- package/dist/esm/lib/applicationTags.helpers.js +22 -0
- package/dist/esm/lib/configuration.js +8 -0
- package/dist/esm/lib/document-action-events.js +6 -0
- package/dist/esm/lib/externalId.helpers.js +12 -0
- package/dist/esm/lib/hidden.helpers.js +6 -0
- package/dist/esm/lib/hiddenComment.helper.js +112 -0
- package/dist/esm/lib/logger.helpers.js +60 -0
- package/dist/esm/lib/logger.js +16 -0
- package/dist/esm/lib/message.helpers.js +52 -0
- package/dist/esm/lib/metrics.helper.js +90 -0
- package/package.json +14 -4
- package/src/data-access/http/facebook.native.js +542 -0
- package/src/data-access/http/tiktok.native.js +248 -0
- package/src/data-access/index.js +4 -0
- package/src/errors/engage-error.js +11 -0
- package/src/errors/http-error.js +19 -0
- package/src/lib/logger.helpers.js +15 -0
- package/src/lib/message.helpers.js +7 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.comment = comment;
|
|
7
|
+
exports.deleteComment = deleteComment;
|
|
8
|
+
exports.getPostData = getPostData;
|
|
9
|
+
exports.getProfile = getProfile;
|
|
10
|
+
exports.getStats = getStats;
|
|
11
|
+
exports.hide = hide;
|
|
12
|
+
exports.like = like;
|
|
13
|
+
exports.reply = reply;
|
|
14
|
+
exports.unhide = unhide;
|
|
15
|
+
exports.unlike = unlike;
|
|
16
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
17
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
18
|
+
var _externalIdHelpers = require("../../lib/externalId.helpers.js");
|
|
19
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
|
+
const TIKTOK_API_URL = "https://business-api.tiktok.com/open_api/v1.3/business/";
|
|
21
|
+
async function comment(token, business_id, video_id, text, logger) {
|
|
22
|
+
const {
|
|
23
|
+
body: publishedMessage
|
|
24
|
+
} = (await sendPost(token, 'comment/create/', {
|
|
25
|
+
business_id: business_id,
|
|
26
|
+
video_id: video_id.startsWith('tt_') ? video_id.split('_')[2] : video_id,
|
|
27
|
+
text
|
|
28
|
+
}, logger)) || {};
|
|
29
|
+
return publishedMessage;
|
|
30
|
+
}
|
|
31
|
+
async function reply(token, videoId, sourceId, inReplyToId, text, logger) {
|
|
32
|
+
const {
|
|
33
|
+
body: publishedMessage
|
|
34
|
+
} = (await sendPost(token, 'comment/reply/create/', {
|
|
35
|
+
business_id: sourceId,
|
|
36
|
+
comment_id: inReplyToId,
|
|
37
|
+
video_id: (0, _externalIdHelpers.removePrefix)(videoId),
|
|
38
|
+
text
|
|
39
|
+
}, logger)) || {};
|
|
40
|
+
return publishedMessage;
|
|
41
|
+
}
|
|
42
|
+
async function like(token, externalId, sourceId, logger) {
|
|
43
|
+
const {
|
|
44
|
+
body: publishedMessage
|
|
45
|
+
} = (await sendPost(token, 'comment/like/', {
|
|
46
|
+
business_id: (0, _externalIdHelpers.removePrefix)(sourceId),
|
|
47
|
+
comment_id: (0, _externalIdHelpers.removePrefix)(externalId),
|
|
48
|
+
action: 'LIKE'
|
|
49
|
+
}, logger)) || {};
|
|
50
|
+
return publishedMessage;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Conversations says this is only allowed on Native...
|
|
54
|
+
async function unlike(token, inReplyToId, sourceId, logger) {
|
|
55
|
+
const {
|
|
56
|
+
body: publishedMessage
|
|
57
|
+
} = (await sendPost(token, 'comment/like/', {
|
|
58
|
+
business_id: (0, _externalIdHelpers.removePrefix)(sourceId),
|
|
59
|
+
comment_id: (0, _externalIdHelpers.removePrefix)(inReplyToId),
|
|
60
|
+
action: 'unlike'
|
|
61
|
+
}, logger)) || {};
|
|
62
|
+
return publishedMessage;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Conversations says this is only allowed on Native...
|
|
66
|
+
async function hide(token, externalId, sourceId, video_id, logger) {
|
|
67
|
+
const {
|
|
68
|
+
body: publishedMessage
|
|
69
|
+
} = (await sendPost(token, 'comment/hide/', {
|
|
70
|
+
business_id: (0, _externalIdHelpers.removePrefix)(sourceId),
|
|
71
|
+
comment_id: (0, _externalIdHelpers.removePrefix)(externalId),
|
|
72
|
+
video_id: (0, _externalIdHelpers.removePrefix)(video_id),
|
|
73
|
+
action: 'HIDE'
|
|
74
|
+
}, logger)) || {};
|
|
75
|
+
return publishedMessage;
|
|
76
|
+
}
|
|
77
|
+
async function unhide(token, externalId, sourceId, video_id, logger) {
|
|
78
|
+
const {
|
|
79
|
+
body: publishedMessage
|
|
80
|
+
} = (await sendPost(token, 'comment/hide/', {
|
|
81
|
+
business_id: (0, _externalIdHelpers.removePrefix)(sourceId),
|
|
82
|
+
comment_id: (0, _externalIdHelpers.removePrefix)(externalId),
|
|
83
|
+
video_id: (0, _externalIdHelpers.removePrefix)(video_id),
|
|
84
|
+
action: 'UNHIDE'
|
|
85
|
+
}, logger)) || {};
|
|
86
|
+
return publishedMessage;
|
|
87
|
+
}
|
|
88
|
+
async function deleteComment(token, inReplyToId, profileId, logger) {
|
|
89
|
+
const {
|
|
90
|
+
body: publishedMessage
|
|
91
|
+
} = (await sendPost(token, 'comment/delete/', {
|
|
92
|
+
business_id: profileId,
|
|
93
|
+
comment_id: inReplyToId
|
|
94
|
+
}, logger)) || {};
|
|
95
|
+
return publishedMessage;
|
|
96
|
+
}
|
|
97
|
+
async function getProfile(token, business_id) {
|
|
98
|
+
let fields = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '["username", "display_name", "profile_image"]';
|
|
99
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
100
|
+
const profile = (await sendRequest(token, `get/?business_id=${business_id}&fields=${fields}`, logger)) || {};
|
|
101
|
+
return profile;
|
|
102
|
+
}
|
|
103
|
+
async function getStats(token, business_id, externalIds) {
|
|
104
|
+
let paramString = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'video/list/';
|
|
105
|
+
let logger = arguments.length > 4 ? arguments[4] : undefined;
|
|
106
|
+
const profile = (await sendRequest(token, `${paramString}?business_id=${business_id}&fields=["item_id","create_time","thumbnail_url","share_url","embed_url","caption","video_views","likes","comments","shares"]&filters=${JSON.stringify({
|
|
107
|
+
video_ids: externalIds
|
|
108
|
+
})}`, logger)) || {};
|
|
109
|
+
return profile;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// This doesn't appear to be used in Conversations either
|
|
113
|
+
async function getPostData(token, business_id, video_id) {
|
|
114
|
+
let fields = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '["item_id", "thumbnail_url", "create_time", "username", "display_name", "profile_image"]';
|
|
115
|
+
let logger = arguments.length > 4 ? arguments[4] : undefined;
|
|
116
|
+
const video_ids = `["${video_id}"]`;
|
|
117
|
+
const profile = (await sendRequest(token, `video/list?business_id=${business_id}&fields=${fields}&filters={"video_ids":${video_ids}}`, logger)) || {};
|
|
118
|
+
return profile;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// assumes batch calls are using the same credential
|
|
122
|
+
async function sendRequest(token) {
|
|
123
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
124
|
+
let logger = arguments.length > 2 ? arguments[2] : undefined;
|
|
125
|
+
let response = {};
|
|
126
|
+
try {
|
|
127
|
+
response = await _superagent.default.get(TIKTOK_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Access-Token', token).send();
|
|
128
|
+
} catch (err) {
|
|
129
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
130
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call tiktok api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
131
|
+
} else {
|
|
132
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call tiktok api for paramString ${paramString}`, err);
|
|
133
|
+
}
|
|
134
|
+
throw err;
|
|
135
|
+
}
|
|
136
|
+
if (response.status !== 200) {
|
|
137
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call tiktok api`, {
|
|
138
|
+
responseBody: JSON.stringify(response.body)
|
|
139
|
+
});
|
|
140
|
+
let error = new Error(`Failed to call tiktok api`);
|
|
141
|
+
error.code = response.status;
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
return response.body;
|
|
145
|
+
}
|
|
146
|
+
async function sendPost(token) {
|
|
147
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
148
|
+
let postData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
149
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
150
|
+
let response = {};
|
|
151
|
+
try {
|
|
152
|
+
response = await _superagent.default.post(TIKTOK_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Access-Token', token).send(postData);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
155
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call tiktok api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
156
|
+
} else {
|
|
157
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call tiktok api for paramString ${paramString}`, err);
|
|
158
|
+
}
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
161
|
+
return response;
|
|
162
|
+
}
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TikTokApiClient = void 0;
|
|
7
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
8
|
+
var _configuration = _interopRequireDefault(require("../../lib/configuration.js"));
|
|
9
|
+
var _logger = _interopRequireDefault(require("../../lib/logger.js"));
|
|
10
|
+
var _externalIdHelpers = require("../../lib/externalId.helpers.js");
|
|
11
|
+
var _credentialsApiClient = require("../http/credentialsApi.client.js");
|
|
12
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
class TikTokApiClient {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.tiktokURL = _configuration.default.get('TIKTOK_API_URL');
|
|
17
|
+
this.credentialsAPI = new _credentialsApiClient.CredentialsApiClient();
|
|
18
|
+
}
|
|
19
|
+
async getAuthorization(document) {
|
|
20
|
+
const {
|
|
21
|
+
documentId,
|
|
22
|
+
systemData: {
|
|
23
|
+
connectionsCredential: credentialId,
|
|
24
|
+
policies: {
|
|
25
|
+
storage: {
|
|
26
|
+
privateTo: companyId
|
|
27
|
+
} = {}
|
|
28
|
+
} = {}
|
|
29
|
+
} = {}
|
|
30
|
+
} = document;
|
|
31
|
+
try {
|
|
32
|
+
const credential = await this.credentialsAPI.getToken(credentialId, companyId);
|
|
33
|
+
return `${credential.token}`;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
_logger.default.error(`${documentId} - error getting tiktok token - ${error.code}`, error, {
|
|
36
|
+
[_loggerHelpers.MeltwaterAttributes.DOCUMENTID]: documentId,
|
|
37
|
+
[_loggerHelpers.MeltwaterAttributes.COMPANYID]: companyId,
|
|
38
|
+
[_loggerHelpers.MeltwaterAttributes.CREDENTIALID]: credentialId
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async sendPost(_ref) {
|
|
43
|
+
let {
|
|
44
|
+
paramString = '',
|
|
45
|
+
headers = {},
|
|
46
|
+
document,
|
|
47
|
+
postData = undefined
|
|
48
|
+
} = _ref;
|
|
49
|
+
let response = {};
|
|
50
|
+
try {
|
|
51
|
+
response = await _superagent.default.post(this.tiktokURL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Access-Token', await this.getAuthorization(document)).send(postData);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
let errorText = '';
|
|
54
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
55
|
+
errorText = `Failed to call tiktok api for paramString ${paramString}: ${err.response.body.error.message}`;
|
|
56
|
+
_logger.default.error(errorText);
|
|
57
|
+
} else {
|
|
58
|
+
errorText = `Failed to call tiktok api for paramString ${paramString}`;
|
|
59
|
+
_logger.default.error(errorText, err);
|
|
60
|
+
}
|
|
61
|
+
throw new Error(errorText);
|
|
62
|
+
}
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// assumes batch calls are using the same credential
|
|
67
|
+
async sendRequest(_ref2) {
|
|
68
|
+
let {
|
|
69
|
+
paramString = '',
|
|
70
|
+
headers = {},
|
|
71
|
+
document
|
|
72
|
+
} = _ref2;
|
|
73
|
+
let response = {};
|
|
74
|
+
try {
|
|
75
|
+
response = await _superagent.default.get(this.tiktokURL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Access-Token', await this.getAuthorization(document)).send();
|
|
76
|
+
} catch (err) {
|
|
77
|
+
let errorText = '';
|
|
78
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
79
|
+
errorText = `Failed to call tiktok api for paramString ${paramString}: ${err.response.body.error.message}`;
|
|
80
|
+
_logger.default.error(errorText);
|
|
81
|
+
} else {
|
|
82
|
+
errorText = `Failed to call tiktok api for paramString ${paramString}`;
|
|
83
|
+
_logger.default.error(errorText, err);
|
|
84
|
+
}
|
|
85
|
+
throw new Error(errorText);
|
|
86
|
+
}
|
|
87
|
+
if (response.status !== 200) {
|
|
88
|
+
_logger.default.error(`Failed to call tiktok api for documentId ${document.documentId}`, response.body, {
|
|
89
|
+
[_loggerHelpers.MeltwaterAttributes.DOCUMENTID]: document.documentId
|
|
90
|
+
});
|
|
91
|
+
let error = new Error(`Failed to call tiktok api for documentId ${document.documentId}`);
|
|
92
|
+
error.code = response.status;
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
return response.body;
|
|
96
|
+
}
|
|
97
|
+
async getChannelInfoForDocuments(documents) {
|
|
98
|
+
const channelInfo = await this.getStatsForDocuments(documents, 'metaData.authors.0.authorInfo.externalId', {
|
|
99
|
+
og: ['video/list/']
|
|
100
|
+
});
|
|
101
|
+
return channelInfo;
|
|
102
|
+
}
|
|
103
|
+
async getStatsForDocuments(documents) {
|
|
104
|
+
let externalIdFrom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'metaData.externalId';
|
|
105
|
+
let paramsByType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
106
|
+
og: ['video/list/']
|
|
107
|
+
};
|
|
108
|
+
// for batching separate og and comment/reply requests per credential
|
|
109
|
+
const documentsByTypeAndCredentials = documents.reduce((retObj, document, index) => {
|
|
110
|
+
const paramArray = paramsByType[document.metaData.discussionType];
|
|
111
|
+
if (paramArray) {
|
|
112
|
+
paramArray.forEach(paramString => {
|
|
113
|
+
let discussionTypeBucket = retObj[`${paramString}${document.systemData.connectionsCredential}`];
|
|
114
|
+
if (!discussionTypeBucket) {
|
|
115
|
+
discussionTypeBucket = {
|
|
116
|
+
paramString,
|
|
117
|
+
document,
|
|
118
|
+
externalIds: [],
|
|
119
|
+
externalIdToDocumentIndex: {}
|
|
120
|
+
};
|
|
121
|
+
retObj[`${paramString}${document.systemData.connectionsCredential}`] = discussionTypeBucket;
|
|
122
|
+
}
|
|
123
|
+
const externalIdTrimmed = (0, _externalIdHelpers.removePrefix)(
|
|
124
|
+
// javascript weirdness to get around '.' notation
|
|
125
|
+
externalIdFrom.split('.').reduce((a, b) => a[b], document));
|
|
126
|
+
discussionTypeBucket.externalIds.push(externalIdTrimmed);
|
|
127
|
+
discussionTypeBucket.externalIdToDocumentIndex[externalIdTrimmed] = index;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return retObj;
|
|
131
|
+
}, {});
|
|
132
|
+
const sortedResults = Array(documents.length).fill();
|
|
133
|
+
await Promise.all(Object.values(documentsByTypeAndCredentials).map(async documentsByTypeAndCredential => {
|
|
134
|
+
if (documentsByTypeAndCredential.externalIds.length) {
|
|
135
|
+
const {
|
|
136
|
+
metaData: {
|
|
137
|
+
inReplyTo: {
|
|
138
|
+
profileId: business_id
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} = documentsByTypeAndCredential.document;
|
|
142
|
+
const trimmedBusinessId = (0, _externalIdHelpers.removePrefix)(business_id);
|
|
143
|
+
const requestResult = await this.sendRequest({
|
|
144
|
+
paramString: `${documentsByTypeAndCredential.paramString}?business_id=${trimmedBusinessId}&fields=["item_id","create_time","thumbnail_url","share_url","embed_url","caption","video_views","likes","comments","shares"]&filters=${JSON.stringify({
|
|
145
|
+
video_ids: documentsByTypeAndCredential.externalIds
|
|
146
|
+
})}`,
|
|
147
|
+
document: documentsByTypeAndCredential.document
|
|
148
|
+
});
|
|
149
|
+
requestResult.data.videos.forEach(_ref3 => {
|
|
150
|
+
let {
|
|
151
|
+
item_id,
|
|
152
|
+
create_time,
|
|
153
|
+
thumbnail_url,
|
|
154
|
+
share_url,
|
|
155
|
+
embed_url,
|
|
156
|
+
caption,
|
|
157
|
+
video_views,
|
|
158
|
+
likes,
|
|
159
|
+
comments,
|
|
160
|
+
shares,
|
|
161
|
+
...args
|
|
162
|
+
} = _ref3;
|
|
163
|
+
const documentIndex = documentsByTypeAndCredential.externalIdToDocumentIndex[item_id];
|
|
164
|
+
sortedResults[documentIndex] = {
|
|
165
|
+
...sortedResults[documentIndex],
|
|
166
|
+
item_id,
|
|
167
|
+
create_time,
|
|
168
|
+
thumbnail_url,
|
|
169
|
+
externalId: documents[documentIndex].metaData.externalId,
|
|
170
|
+
share_url,
|
|
171
|
+
embed_url,
|
|
172
|
+
caption,
|
|
173
|
+
video_views,
|
|
174
|
+
likes,
|
|
175
|
+
comments,
|
|
176
|
+
shares
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}));
|
|
181
|
+
return sortedResults;
|
|
182
|
+
}
|
|
183
|
+
async publish(message, videoId, markMessageAsCompleteDocumentId) {
|
|
184
|
+
const {
|
|
185
|
+
metaData: {
|
|
186
|
+
discussionType
|
|
187
|
+
}
|
|
188
|
+
} = message;
|
|
189
|
+
let publishedMessage;
|
|
190
|
+
switch (discussionType) {
|
|
191
|
+
case 'qt':
|
|
192
|
+
publishedMessage = await this.insertComment(message);
|
|
193
|
+
break;
|
|
194
|
+
case 're':
|
|
195
|
+
publishedMessage = await this.insertReply(videoId, message, markMessageAsCompleteDocumentId);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
return publishedMessage;
|
|
199
|
+
}
|
|
200
|
+
async insertComment(document) {
|
|
201
|
+
const {
|
|
202
|
+
body: {
|
|
203
|
+
content: {
|
|
204
|
+
text: text
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
metaData: {
|
|
208
|
+
source: {
|
|
209
|
+
id: business_id
|
|
210
|
+
},
|
|
211
|
+
inReplyTo: {
|
|
212
|
+
id: video_id
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
} = document;
|
|
216
|
+
const {
|
|
217
|
+
body: publishedMessage
|
|
218
|
+
} = (await this.sendPost({
|
|
219
|
+
paramString: 'comment/create/',
|
|
220
|
+
postData: {
|
|
221
|
+
business_id,
|
|
222
|
+
video_id,
|
|
223
|
+
text
|
|
224
|
+
},
|
|
225
|
+
document
|
|
226
|
+
})) || {};
|
|
227
|
+
return publishedMessage;
|
|
228
|
+
}
|
|
229
|
+
async insertReply(videoId, document, markMessageAsCompleteDocumentId) {
|
|
230
|
+
const {
|
|
231
|
+
body: {
|
|
232
|
+
content: {
|
|
233
|
+
text: text
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
metaData: {
|
|
237
|
+
inReplyTo: {
|
|
238
|
+
id: comment_id,
|
|
239
|
+
profileId: business_id
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
} = document;
|
|
243
|
+
const {
|
|
244
|
+
body: publishedMessage
|
|
245
|
+
} = (await this.sendPost({
|
|
246
|
+
paramString: 'comment/reply/create/',
|
|
247
|
+
postData: {
|
|
248
|
+
business_id: document.metaData.source.id,
|
|
249
|
+
comment_id: markMessageAsCompleteDocumentId || comment_id,
|
|
250
|
+
video_id: (0, _externalIdHelpers.removePrefix)(videoId),
|
|
251
|
+
text
|
|
252
|
+
},
|
|
253
|
+
document
|
|
254
|
+
})) || {};
|
|
255
|
+
return publishedMessage;
|
|
256
|
+
}
|
|
257
|
+
async toggleLike(document) {
|
|
258
|
+
const {
|
|
259
|
+
enrichments: {
|
|
260
|
+
socialScores: {
|
|
261
|
+
tt_liked_by_user: likedByUser
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
} = document;
|
|
265
|
+
try {
|
|
266
|
+
let likeResponse = await (!likedByUser ? this.like(document) : this.unlike(document));
|
|
267
|
+
return likeResponse;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
_logger.default.error(`${document} - error recieved - ${error.code}`, error);
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async toggleHide(document) {
|
|
274
|
+
let parentDoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
275
|
+
const {
|
|
276
|
+
documentId,
|
|
277
|
+
appData: {
|
|
278
|
+
hidden: hiddenOnNative
|
|
279
|
+
}
|
|
280
|
+
} = document;
|
|
281
|
+
let response;
|
|
282
|
+
try {
|
|
283
|
+
if (hiddenOnNative) {
|
|
284
|
+
response = await this.hide(document, parentDoc);
|
|
285
|
+
} else {
|
|
286
|
+
response = await this.unhide(document, parentDoc);
|
|
287
|
+
}
|
|
288
|
+
_logger.default.info(`Native Tiktok API Hide Response for documentId ${documentId}`, {
|
|
289
|
+
status: response.status,
|
|
290
|
+
ok: response.ok,
|
|
291
|
+
[_loggerHelpers.MeltwaterAttributes.DOCUMENTID]: documentId
|
|
292
|
+
});
|
|
293
|
+
if (response.message === 'OK') {
|
|
294
|
+
return response;
|
|
295
|
+
}
|
|
296
|
+
} catch (error) {
|
|
297
|
+
_logger.default.error(`${documentId} - error recieved - ${error.code}`, error, {
|
|
298
|
+
[_loggerHelpers.MeltwaterAttributes.DOCUMENTID]: documentId
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async like(document) {
|
|
303
|
+
const {
|
|
304
|
+
metaData: {
|
|
305
|
+
externalId: comment_id,
|
|
306
|
+
source: {
|
|
307
|
+
id: sourceId
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
} = document;
|
|
311
|
+
const {
|
|
312
|
+
body: publishedMessage
|
|
313
|
+
} = (await this.sendPost({
|
|
314
|
+
paramString: 'comment/like/',
|
|
315
|
+
postData: {
|
|
316
|
+
business_id: (0, _externalIdHelpers.removePrefix)(sourceId),
|
|
317
|
+
comment_id: (0, _externalIdHelpers.removePrefix)(comment_id),
|
|
318
|
+
action: 'LIKE'
|
|
319
|
+
},
|
|
320
|
+
document
|
|
321
|
+
})) || {};
|
|
322
|
+
return publishedMessage;
|
|
323
|
+
}
|
|
324
|
+
async unlike(document) {
|
|
325
|
+
const {
|
|
326
|
+
metaData: {
|
|
327
|
+
inReplyTo: {
|
|
328
|
+
id: comment_id
|
|
329
|
+
},
|
|
330
|
+
source: {
|
|
331
|
+
id: sourceId
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
} = document;
|
|
335
|
+
const {
|
|
336
|
+
body: publishedMessage
|
|
337
|
+
} = (await this.sendPost({
|
|
338
|
+
paramString: 'comment/like/',
|
|
339
|
+
postData: {
|
|
340
|
+
business_id: (0, _externalIdHelpers.removePrefix)(sourceId),
|
|
341
|
+
comment_id: (0, _externalIdHelpers.removePrefix)(comment_id),
|
|
342
|
+
action: 'unlike'
|
|
343
|
+
},
|
|
344
|
+
document
|
|
345
|
+
})) || {};
|
|
346
|
+
return publishedMessage;
|
|
347
|
+
}
|
|
348
|
+
async hide(document) {
|
|
349
|
+
let parentDoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
350
|
+
const {
|
|
351
|
+
metaData: {
|
|
352
|
+
externalId: comment_id,
|
|
353
|
+
source: {
|
|
354
|
+
id: sourceId
|
|
355
|
+
},
|
|
356
|
+
discussionType
|
|
357
|
+
}
|
|
358
|
+
} = document;
|
|
359
|
+
|
|
360
|
+
//very small chance we get externalid instead of id
|
|
361
|
+
const video_id = discussionType === 're' ? parentDoc?.metaData?.inReplyTo?.id || parentDoc?.metaData?.inReplyTo?.externalId : document?.metaData?.inReplyTo?.id || document?.metaData?.inReplyTo?.externalId;
|
|
362
|
+
const {
|
|
363
|
+
body: publishedMessage
|
|
364
|
+
} = (await this.sendPost({
|
|
365
|
+
paramString: 'comment/hide/',
|
|
366
|
+
postData: {
|
|
367
|
+
business_id: (0, _externalIdHelpers.removePrefix)(sourceId),
|
|
368
|
+
comment_id: (0, _externalIdHelpers.removePrefix)(comment_id),
|
|
369
|
+
video_id: (0, _externalIdHelpers.removePrefix)(video_id),
|
|
370
|
+
action: 'HIDE'
|
|
371
|
+
},
|
|
372
|
+
document
|
|
373
|
+
})) || {};
|
|
374
|
+
return publishedMessage;
|
|
375
|
+
}
|
|
376
|
+
async unhide(document) {
|
|
377
|
+
let parentDoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
378
|
+
const {
|
|
379
|
+
metaData: {
|
|
380
|
+
externalId: comment_id,
|
|
381
|
+
source: {
|
|
382
|
+
id: sourceId
|
|
383
|
+
},
|
|
384
|
+
discussionType
|
|
385
|
+
}
|
|
386
|
+
} = document;
|
|
387
|
+
const video_id = discussionType === 're' ? parentDoc?.metaData?.inReplyTo?.id : document?.metaData?.inReplyTo?.id;
|
|
388
|
+
const {
|
|
389
|
+
body: publishedMessage
|
|
390
|
+
} = (await this.sendPost({
|
|
391
|
+
paramString: 'comment/hide/',
|
|
392
|
+
postData: {
|
|
393
|
+
business_id: (0, _externalIdHelpers.removePrefix)(sourceId),
|
|
394
|
+
comment_id: (0, _externalIdHelpers.removePrefix)(comment_id),
|
|
395
|
+
video_id: (0, _externalIdHelpers.removePrefix)(video_id),
|
|
396
|
+
action: 'UNHIDE'
|
|
397
|
+
},
|
|
398
|
+
document
|
|
399
|
+
})) || {};
|
|
400
|
+
return publishedMessage;
|
|
401
|
+
}
|
|
402
|
+
async deleteComment(document) {
|
|
403
|
+
const {
|
|
404
|
+
metaData: {
|
|
405
|
+
inReplyTo: {
|
|
406
|
+
id: comment_id,
|
|
407
|
+
profileId: business_id
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
} = document;
|
|
411
|
+
const {
|
|
412
|
+
body: publishedMessage
|
|
413
|
+
} = (await this.sendPost({
|
|
414
|
+
paramString: 'comment/delete/',
|
|
415
|
+
postData: {
|
|
416
|
+
business_id,
|
|
417
|
+
comment_id
|
|
418
|
+
},
|
|
419
|
+
document
|
|
420
|
+
})) || {};
|
|
421
|
+
return publishedMessage;
|
|
422
|
+
}
|
|
423
|
+
async getProfile(business_id, document) {
|
|
424
|
+
const fields = '["username", "display_name", "profile_image"]';
|
|
425
|
+
const profile = (await this.sendRequest({
|
|
426
|
+
paramString: `get/?business_id=${business_id}&fields=${fields}`,
|
|
427
|
+
document
|
|
428
|
+
})) || {};
|
|
429
|
+
return profile;
|
|
430
|
+
}
|
|
431
|
+
async getPostData(business_id, video_id, document) {
|
|
432
|
+
const fields = '["item_id", "thumbnail_url", "create_time", "username", "display_name", "profile_image"]';
|
|
433
|
+
const video_ids = `["${video_id}"]`;
|
|
434
|
+
const profile = (await this.sendRequest({
|
|
435
|
+
paramString: `video/list?business_id=${business_id}&fields=${fields}&filters={"video_ids":${video_ids}}`,
|
|
436
|
+
document
|
|
437
|
+
})) || {};
|
|
438
|
+
return profile;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
exports.TikTokApiClient = TikTokApiClient;
|