@meltwater/conversations-api-services 1.0.20 → 1.0.22
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 +2 -2
- package/dist/cjs/data-access/http/tiktok.native.js +162 -0
- package/dist/cjs/data-access/index.js +3 -0
- package/dist/esm/data-access/http/facebook.native.js +2 -2
- package/dist/esm/data-access/http/tiktok.native.js +146 -0
- package/dist/esm/data-access/index.js +2 -1
- package/package.json +1 -1
- package/src/data-access/http/facebook.native.js +2 -2
- package/src/data-access/http/tiktok.native.js +248 -0
- package/src/data-access/index.js +2 -0
|
@@ -101,7 +101,7 @@ async function privateMessage(token, _ref2, logger) {
|
|
|
101
101
|
},
|
|
102
102
|
tag: 'HUMAN_AGENT'
|
|
103
103
|
}, logger);
|
|
104
|
-
(0, _loggerHelpers.loggerInfo)(logger, `Native Facebook API Publish Private Message Response
|
|
104
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Native Facebook API Publish Private Message Response`, {
|
|
105
105
|
responseBody: JSON.stringify(response.body)
|
|
106
106
|
});
|
|
107
107
|
return response.body;
|
|
@@ -128,7 +128,7 @@ async function unhide(token, externalId, logger) {
|
|
|
128
128
|
}
|
|
129
129
|
async function like(token, externalId, logger) {
|
|
130
130
|
(0, _loggerHelpers.loggerDebug)(logger, `Starting to call facebook like api`);
|
|
131
|
-
response = await postApi(`${FACEBOOK_URL}/${(0, _externalIdHelpers.removePrefix)(externalId)}/likes`, token, undefined, logger);
|
|
131
|
+
const response = await postApi(`${FACEBOOK_URL}/${(0, _externalIdHelpers.removePrefix)(externalId)}/likes`, token, undefined, logger);
|
|
132
132
|
(0, _loggerHelpers.loggerInfo)(logger, `Native Facebook API Like Response`, {
|
|
133
133
|
responseBody: JSON.stringify(response.body)
|
|
134
134
|
});
|
|
@@ -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
|
+
}
|
|
@@ -78,6 +78,7 @@ Object.defineProperty(exports, "TikTokApiClient", {
|
|
|
78
78
|
return _tiktokApiClient.TikTokApiClient;
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
|
+
exports.TiktokNative = void 0;
|
|
81
82
|
Object.defineProperty(exports, "WarpZoneApiClient", {
|
|
82
83
|
enumerable: true,
|
|
83
84
|
get: function () {
|
|
@@ -116,6 +117,8 @@ var applicationTagFunctions = _interopRequireWildcard(require("../lib/applicatio
|
|
|
116
117
|
var hiddenHelpers = _interopRequireWildcard(require("../lib/hidden.helpers.js"));
|
|
117
118
|
var FacebookNative = _interopRequireWildcard(require("./http/facebook.native.js"));
|
|
118
119
|
exports.FacebookNative = FacebookNative;
|
|
120
|
+
var TiktokNative = _interopRequireWildcard(require("./http/tiktok.native.js"));
|
|
121
|
+
exports.TiktokNative = TiktokNative;
|
|
119
122
|
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); }
|
|
120
123
|
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; }
|
|
121
124
|
const DocumentHelperFunctions = exports.DocumentHelperFunctions = {
|
|
@@ -82,7 +82,7 @@ export async function privateMessage(token, _ref2, logger) {
|
|
|
82
82
|
},
|
|
83
83
|
tag: 'HUMAN_AGENT'
|
|
84
84
|
}, logger);
|
|
85
|
-
loggerInfo(logger, `Native Facebook API Publish Private Message Response
|
|
85
|
+
loggerInfo(logger, `Native Facebook API Publish Private Message Response`, {
|
|
86
86
|
responseBody: JSON.stringify(response.body)
|
|
87
87
|
});
|
|
88
88
|
return response.body;
|
|
@@ -109,7 +109,7 @@ export async function unhide(token, externalId, logger) {
|
|
|
109
109
|
}
|
|
110
110
|
export async function like(token, externalId, logger) {
|
|
111
111
|
loggerDebug(logger, `Starting to call facebook like api`);
|
|
112
|
-
response = await postApi(`${FACEBOOK_URL}/${removePrefix(externalId)}/likes`, token, undefined, logger);
|
|
112
|
+
const response = await postApi(`${FACEBOOK_URL}/${removePrefix(externalId)}/likes`, token, undefined, logger);
|
|
113
113
|
loggerInfo(logger, `Native Facebook API Like Response`, {
|
|
114
114
|
responseBody: JSON.stringify(response.body)
|
|
115
115
|
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import superagent from 'superagent';
|
|
2
|
+
import { loggerError } from '../../lib/logger.helpers.js';
|
|
3
|
+
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
4
|
+
const TIKTOK_API_URL = "https://business-api.tiktok.com/open_api/v1.3/business/";
|
|
5
|
+
export async function comment(token, business_id, video_id, text, logger) {
|
|
6
|
+
const {
|
|
7
|
+
body: publishedMessage
|
|
8
|
+
} = (await sendPost(token, 'comment/create/', {
|
|
9
|
+
business_id: business_id,
|
|
10
|
+
video_id: video_id.startsWith('tt_') ? video_id.split('_')[2] : video_id,
|
|
11
|
+
text
|
|
12
|
+
}, logger)) || {};
|
|
13
|
+
return publishedMessage;
|
|
14
|
+
}
|
|
15
|
+
export async function reply(token, videoId, sourceId, inReplyToId, text, logger) {
|
|
16
|
+
const {
|
|
17
|
+
body: publishedMessage
|
|
18
|
+
} = (await sendPost(token, 'comment/reply/create/', {
|
|
19
|
+
business_id: sourceId,
|
|
20
|
+
comment_id: inReplyToId,
|
|
21
|
+
video_id: removePrefix(videoId),
|
|
22
|
+
text
|
|
23
|
+
}, logger)) || {};
|
|
24
|
+
return publishedMessage;
|
|
25
|
+
}
|
|
26
|
+
export async function like(token, externalId, sourceId, logger) {
|
|
27
|
+
const {
|
|
28
|
+
body: publishedMessage
|
|
29
|
+
} = (await sendPost(token, 'comment/like/', {
|
|
30
|
+
business_id: removePrefix(sourceId),
|
|
31
|
+
comment_id: removePrefix(externalId),
|
|
32
|
+
action: 'LIKE'
|
|
33
|
+
}, logger)) || {};
|
|
34
|
+
return publishedMessage;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Conversations says this is only allowed on Native...
|
|
38
|
+
export async function unlike(token, inReplyToId, sourceId, logger) {
|
|
39
|
+
const {
|
|
40
|
+
body: publishedMessage
|
|
41
|
+
} = (await sendPost(token, 'comment/like/', {
|
|
42
|
+
business_id: removePrefix(sourceId),
|
|
43
|
+
comment_id: removePrefix(inReplyToId),
|
|
44
|
+
action: 'unlike'
|
|
45
|
+
}, logger)) || {};
|
|
46
|
+
return publishedMessage;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Conversations says this is only allowed on Native...
|
|
50
|
+
export async function hide(token, externalId, sourceId, video_id, logger) {
|
|
51
|
+
const {
|
|
52
|
+
body: publishedMessage
|
|
53
|
+
} = (await sendPost(token, 'comment/hide/', {
|
|
54
|
+
business_id: removePrefix(sourceId),
|
|
55
|
+
comment_id: removePrefix(externalId),
|
|
56
|
+
video_id: removePrefix(video_id),
|
|
57
|
+
action: 'HIDE'
|
|
58
|
+
}, logger)) || {};
|
|
59
|
+
return publishedMessage;
|
|
60
|
+
}
|
|
61
|
+
export async function unhide(token, externalId, sourceId, video_id, logger) {
|
|
62
|
+
const {
|
|
63
|
+
body: publishedMessage
|
|
64
|
+
} = (await sendPost(token, 'comment/hide/', {
|
|
65
|
+
business_id: removePrefix(sourceId),
|
|
66
|
+
comment_id: removePrefix(externalId),
|
|
67
|
+
video_id: removePrefix(video_id),
|
|
68
|
+
action: 'UNHIDE'
|
|
69
|
+
}, logger)) || {};
|
|
70
|
+
return publishedMessage;
|
|
71
|
+
}
|
|
72
|
+
export async function deleteComment(token, inReplyToId, profileId, logger) {
|
|
73
|
+
const {
|
|
74
|
+
body: publishedMessage
|
|
75
|
+
} = (await sendPost(token, 'comment/delete/', {
|
|
76
|
+
business_id: profileId,
|
|
77
|
+
comment_id: inReplyToId
|
|
78
|
+
}, logger)) || {};
|
|
79
|
+
return publishedMessage;
|
|
80
|
+
}
|
|
81
|
+
export async function getProfile(token, business_id) {
|
|
82
|
+
let fields = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '["username", "display_name", "profile_image"]';
|
|
83
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
84
|
+
const profile = (await sendRequest(token, `get/?business_id=${business_id}&fields=${fields}`, logger)) || {};
|
|
85
|
+
return profile;
|
|
86
|
+
}
|
|
87
|
+
export async function getStats(token, business_id, externalIds) {
|
|
88
|
+
let paramString = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'video/list/';
|
|
89
|
+
let logger = arguments.length > 4 ? arguments[4] : undefined;
|
|
90
|
+
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({
|
|
91
|
+
video_ids: externalIds
|
|
92
|
+
})}`, logger)) || {};
|
|
93
|
+
return profile;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// This doesn't appear to be used in Conversations either
|
|
97
|
+
export async function getPostData(token, business_id, video_id) {
|
|
98
|
+
let fields = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '["item_id", "thumbnail_url", "create_time", "username", "display_name", "profile_image"]';
|
|
99
|
+
let logger = arguments.length > 4 ? arguments[4] : undefined;
|
|
100
|
+
const video_ids = `["${video_id}"]`;
|
|
101
|
+
const profile = (await sendRequest(token, `video/list?business_id=${business_id}&fields=${fields}&filters={"video_ids":${video_ids}}`, logger)) || {};
|
|
102
|
+
return profile;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// assumes batch calls are using the same credential
|
|
106
|
+
async function sendRequest(token) {
|
|
107
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
108
|
+
let logger = arguments.length > 2 ? arguments[2] : undefined;
|
|
109
|
+
let response = {};
|
|
110
|
+
try {
|
|
111
|
+
response = await superagent.get(TIKTOK_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Access-Token', token).send();
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
114
|
+
loggerError(logger, `Failed to call tiktok api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
115
|
+
} else {
|
|
116
|
+
loggerError(logger, `Failed to call tiktok api for paramString ${paramString}`, err);
|
|
117
|
+
}
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
if (response.status !== 200) {
|
|
121
|
+
loggerError(logger, `Failed to call tiktok api`, {
|
|
122
|
+
responseBody: JSON.stringify(response.body)
|
|
123
|
+
});
|
|
124
|
+
let error = new Error(`Failed to call tiktok api`);
|
|
125
|
+
error.code = response.status;
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
return response.body;
|
|
129
|
+
}
|
|
130
|
+
async function sendPost(token) {
|
|
131
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
132
|
+
let postData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
133
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
134
|
+
let response = {};
|
|
135
|
+
try {
|
|
136
|
+
response = await superagent.post(TIKTOK_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Access-Token', token).send(postData);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
139
|
+
loggerError(logger, `Failed to call tiktok api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
140
|
+
} else {
|
|
141
|
+
loggerError(logger, `Failed to call tiktok api for paramString ${paramString}`, err);
|
|
142
|
+
}
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
return response;
|
|
146
|
+
}
|
|
@@ -17,6 +17,7 @@ import * as messageHelpers from '../lib/message.helpers.js';
|
|
|
17
17
|
import * as applicationTagFunctions from '../lib/applicationTags.helpers.js';
|
|
18
18
|
import * as hiddenHelpers from '../lib/hidden.helpers.js';
|
|
19
19
|
import * as FacebookNative from './http/facebook.native.js';
|
|
20
|
+
import * as TiktokNative from './http/tiktok.native.js';
|
|
20
21
|
const DocumentHelperFunctions = {
|
|
21
22
|
...messageHelpers,
|
|
22
23
|
...applicationTagFunctions,
|
|
@@ -26,4 +27,4 @@ const LinkedInHelpers = {
|
|
|
26
27
|
getOrganization,
|
|
27
28
|
getProfile
|
|
28
29
|
};
|
|
29
|
-
export { FacebookNative, awsS3Client, assetManagerTvmRepository, CompanyApiClient, CredentialsApiClient, EntitlementsApiClient, FacebookApiClient, FeatureToggleClient, IdentityServicesClient, InstagramApiClient, InstagramVideoClient, IRClient, LinkedInApiClient, TikTokApiClient, MasfClient, WarpZoneApiClient, DocumentHelperFunctions, LinkedInHelpers };
|
|
30
|
+
export { FacebookNative, TiktokNative, awsS3Client, assetManagerTvmRepository, CompanyApiClient, CredentialsApiClient, EntitlementsApiClient, FacebookApiClient, FeatureToggleClient, IdentityServicesClient, InstagramApiClient, InstagramVideoClient, IRClient, LinkedInApiClient, TikTokApiClient, MasfClient, WarpZoneApiClient, DocumentHelperFunctions, LinkedInHelpers };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meltwater/conversations-api-services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
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",
|
|
@@ -119,7 +119,7 @@ export async function privateMessage(token, {
|
|
|
119
119
|
logger
|
|
120
120
|
);
|
|
121
121
|
loggerInfo(logger,
|
|
122
|
-
`Native Facebook API Publish Private Message Response
|
|
122
|
+
`Native Facebook API Publish Private Message Response`,
|
|
123
123
|
{ responseBody: JSON.stringify(response.body) }
|
|
124
124
|
);
|
|
125
125
|
return response.body;
|
|
@@ -169,7 +169,7 @@ export async function like(token, externalId, logger) {
|
|
|
169
169
|
`Starting to call facebook like api`
|
|
170
170
|
);
|
|
171
171
|
|
|
172
|
-
response = await postApi(
|
|
172
|
+
const response = await postApi(
|
|
173
173
|
`${FACEBOOK_URL}/${removePrefix(externalId)}/likes`,
|
|
174
174
|
token,
|
|
175
175
|
undefined,
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import superagent from 'superagent';
|
|
2
|
+
import { loggerError } from '../../lib/logger.helpers.js';
|
|
3
|
+
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
4
|
+
|
|
5
|
+
const TIKTOK_API_URL = "https://business-api.tiktok.com/open_api/v1.3/business/";
|
|
6
|
+
|
|
7
|
+
export async function comment(token,business_id,video_id,text,logger) {
|
|
8
|
+
const { body: publishedMessage } =
|
|
9
|
+
(await sendPost(
|
|
10
|
+
token,
|
|
11
|
+
'comment/create/',
|
|
12
|
+
{
|
|
13
|
+
business_id: business_id,
|
|
14
|
+
video_id: video_id.startsWith('tt_')
|
|
15
|
+
? video_id.split('_')[2]
|
|
16
|
+
: video_id,
|
|
17
|
+
text,
|
|
18
|
+
},
|
|
19
|
+
logger,
|
|
20
|
+
)) || {};
|
|
21
|
+
return publishedMessage;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function reply(token,videoId,sourceId, inReplyToId, text, logger) {
|
|
25
|
+
const { body: publishedMessage } =
|
|
26
|
+
(await sendPost(
|
|
27
|
+
token,
|
|
28
|
+
'comment/reply/create/',
|
|
29
|
+
{
|
|
30
|
+
business_id: sourceId,
|
|
31
|
+
comment_id: inReplyToId,
|
|
32
|
+
video_id: removePrefix(videoId),
|
|
33
|
+
text,
|
|
34
|
+
},
|
|
35
|
+
logger,
|
|
36
|
+
)) || {};
|
|
37
|
+
|
|
38
|
+
return publishedMessage;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function like(token,externalId,sourceId,logger) {
|
|
42
|
+
const { body: publishedMessage } =
|
|
43
|
+
(await sendPost(
|
|
44
|
+
token,
|
|
45
|
+
'comment/like/',
|
|
46
|
+
{
|
|
47
|
+
business_id: removePrefix(sourceId),
|
|
48
|
+
comment_id: removePrefix(externalId),
|
|
49
|
+
action: 'LIKE',
|
|
50
|
+
},
|
|
51
|
+
logger,
|
|
52
|
+
)) || {};
|
|
53
|
+
return publishedMessage;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Conversations says this is only allowed on Native...
|
|
57
|
+
export async function unlike(token,inReplyToId,sourceId, logger) {
|
|
58
|
+
const { body: publishedMessage } =
|
|
59
|
+
(await sendPost(
|
|
60
|
+
token,
|
|
61
|
+
'comment/like/',
|
|
62
|
+
{
|
|
63
|
+
business_id: removePrefix(sourceId),
|
|
64
|
+
comment_id: removePrefix(inReplyToId),
|
|
65
|
+
action: 'unlike',
|
|
66
|
+
},
|
|
67
|
+
logger,
|
|
68
|
+
)) || {};
|
|
69
|
+
return publishedMessage;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Conversations says this is only allowed on Native...
|
|
73
|
+
export async function hide(token,externalId,sourceId, video_id, logger) {
|
|
74
|
+
const { body: publishedMessage } =
|
|
75
|
+
(await sendPost(
|
|
76
|
+
token,
|
|
77
|
+
'comment/hide/',
|
|
78
|
+
{
|
|
79
|
+
business_id: removePrefix(sourceId),
|
|
80
|
+
comment_id: removePrefix(externalId),
|
|
81
|
+
video_id: removePrefix(video_id),
|
|
82
|
+
action: 'HIDE',
|
|
83
|
+
},
|
|
84
|
+
logger,
|
|
85
|
+
)) || {};
|
|
86
|
+
return publishedMessage;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function unhide(token,externalId,sourceId,video_id, logger) {
|
|
90
|
+
|
|
91
|
+
const { body: publishedMessage } =
|
|
92
|
+
(await sendPost(
|
|
93
|
+
token,
|
|
94
|
+
'comment/hide/',
|
|
95
|
+
{
|
|
96
|
+
business_id: removePrefix(sourceId),
|
|
97
|
+
comment_id: removePrefix(externalId),
|
|
98
|
+
video_id: removePrefix(video_id),
|
|
99
|
+
action: 'UNHIDE',
|
|
100
|
+
},
|
|
101
|
+
logger,
|
|
102
|
+
)) || {};
|
|
103
|
+
return publishedMessage;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function deleteComment(token,inReplyToId, profileId, logger) {
|
|
107
|
+
const { body: publishedMessage } =
|
|
108
|
+
(await sendPost(
|
|
109
|
+
token,
|
|
110
|
+
'comment/delete/',
|
|
111
|
+
{
|
|
112
|
+
business_id: profileId,
|
|
113
|
+
comment_id: inReplyToId,
|
|
114
|
+
},
|
|
115
|
+
logger,
|
|
116
|
+
)) || {};
|
|
117
|
+
return publishedMessage;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function getProfile(
|
|
121
|
+
token,
|
|
122
|
+
business_id,
|
|
123
|
+
fields = '["username", "display_name", "profile_image"]',
|
|
124
|
+
logger
|
|
125
|
+
) {
|
|
126
|
+
const profile =
|
|
127
|
+
(await sendRequest(
|
|
128
|
+
token,
|
|
129
|
+
`get/?business_id=${business_id}&fields=${fields}`,
|
|
130
|
+
logger,
|
|
131
|
+
)) || {};
|
|
132
|
+
return profile;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function getStats(token, business_id, externalIds, paramString = 'video/list/', logger){
|
|
136
|
+
|
|
137
|
+
const profile =
|
|
138
|
+
(await sendRequest(
|
|
139
|
+
token,
|
|
140
|
+
`${
|
|
141
|
+
paramString
|
|
142
|
+
}?business_id=${business_id}&fields=["item_id","create_time","thumbnail_url","share_url","embed_url","caption","video_views","likes","comments","shares"]&filters=${JSON.stringify(
|
|
143
|
+
{
|
|
144
|
+
video_ids: externalIds,
|
|
145
|
+
}
|
|
146
|
+
)}`,
|
|
147
|
+
logger,
|
|
148
|
+
)) || {};
|
|
149
|
+
return profile;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// This doesn't appear to be used in Conversations either
|
|
153
|
+
export async function getPostData(token, business_id, video_id,
|
|
154
|
+
fields = '["item_id", "thumbnail_url", "create_time", "username", "display_name", "profile_image"]',
|
|
155
|
+
logger
|
|
156
|
+
) {
|
|
157
|
+
const video_ids = `["${video_id}"]`;
|
|
158
|
+
const profile =
|
|
159
|
+
(await sendRequest(
|
|
160
|
+
token,
|
|
161
|
+
`video/list?business_id=${business_id}&fields=${fields}&filters={"video_ids":${video_ids}}`,
|
|
162
|
+
logger,
|
|
163
|
+
)) || {};
|
|
164
|
+
return profile;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// assumes batch calls are using the same credential
|
|
168
|
+
async function sendRequest(token, paramString = '', logger) {
|
|
169
|
+
let response = {};
|
|
170
|
+
try {
|
|
171
|
+
response = await superagent
|
|
172
|
+
.get(TIKTOK_API_URL + paramString)
|
|
173
|
+
.set('Accept', 'application/json')
|
|
174
|
+
.set('Content-Type', 'application/json')
|
|
175
|
+
.set('Access-Token', token)
|
|
176
|
+
.send();
|
|
177
|
+
} catch (err) {
|
|
178
|
+
if (
|
|
179
|
+
err &&
|
|
180
|
+
err.response &&
|
|
181
|
+
err.response.body &&
|
|
182
|
+
err.response.body.error
|
|
183
|
+
) {
|
|
184
|
+
loggerError(logger,
|
|
185
|
+
`Failed to call tiktok api for paramString ${paramString}: ${err.response.body.error.message}`
|
|
186
|
+
);
|
|
187
|
+
} else {
|
|
188
|
+
loggerError(logger,
|
|
189
|
+
`Failed to call tiktok api for paramString ${paramString}`,
|
|
190
|
+
err
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
throw err;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (response.status !== 200) {
|
|
198
|
+
loggerError(logger,
|
|
199
|
+
`Failed to call tiktok api`,
|
|
200
|
+
{ responseBody: JSON.stringify(response.body) }
|
|
201
|
+
);
|
|
202
|
+
let error = new Error(
|
|
203
|
+
`Failed to call tiktok api`
|
|
204
|
+
);
|
|
205
|
+
error.code = response.status;
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return response.body;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function sendPost(
|
|
213
|
+
token,
|
|
214
|
+
paramString = '',
|
|
215
|
+
postData = undefined,
|
|
216
|
+
logger
|
|
217
|
+
) {
|
|
218
|
+
|
|
219
|
+
let response = {};
|
|
220
|
+
try {
|
|
221
|
+
response = await superagent
|
|
222
|
+
.post(TIKTOK_API_URL + paramString)
|
|
223
|
+
.set('Accept', 'application/json')
|
|
224
|
+
.set('Content-Type', 'application/json')
|
|
225
|
+
.set('Access-Token', token)
|
|
226
|
+
.send(postData);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
if (
|
|
229
|
+
err &&
|
|
230
|
+
err.response &&
|
|
231
|
+
err.response.body &&
|
|
232
|
+
err.response.body.error
|
|
233
|
+
) {
|
|
234
|
+
loggerError(logger,
|
|
235
|
+
`Failed to call tiktok api for paramString ${paramString}: ${err.response.body.error.message}`
|
|
236
|
+
);
|
|
237
|
+
} else {
|
|
238
|
+
loggerError(logger,
|
|
239
|
+
`Failed to call tiktok api for paramString ${paramString}`,
|
|
240
|
+
err
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
throw err;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return response;
|
|
248
|
+
}
|
package/src/data-access/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import * as messageHelpers from '../lib/message.helpers.js';
|
|
|
17
17
|
import * as applicationTagFunctions from '../lib/applicationTags.helpers.js';
|
|
18
18
|
import * as hiddenHelpers from '../lib/hidden.helpers.js';
|
|
19
19
|
import * as FacebookNative from './http/facebook.native.js';
|
|
20
|
+
import * as TiktokNative from './http/tiktok.native.js';
|
|
20
21
|
|
|
21
22
|
const DocumentHelperFunctions = {
|
|
22
23
|
...messageHelpers,
|
|
@@ -30,6 +31,7 @@ const LinkedInHelpers = {
|
|
|
30
31
|
|
|
31
32
|
export {
|
|
32
33
|
FacebookNative,
|
|
34
|
+
TiktokNative,
|
|
33
35
|
awsS3Client,
|
|
34
36
|
assetManagerTvmRepository,
|
|
35
37
|
CompanyApiClient,
|