@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.
Files changed (70) hide show
  1. package/.github/workflows/release.yml +2 -0
  2. package/babel.config.js +18 -0
  3. package/dist/cjs/data-access/http/InstagramVideoClient.js +42 -0
  4. package/dist/cjs/data-access/http/WarpZoneApi.client.js +32 -0
  5. package/dist/cjs/data-access/http/amazonS3.js +44 -0
  6. package/dist/cjs/data-access/http/asset-manager-tvm.client.js +35 -0
  7. package/dist/cjs/data-access/http/companiesApi.client.js +38 -0
  8. package/dist/cjs/data-access/http/credentialsApi.client.js +102 -0
  9. package/dist/cjs/data-access/http/entitlementsApi.client.js +40 -0
  10. package/dist/cjs/data-access/http/facebook.native.js +344 -0
  11. package/dist/cjs/data-access/http/facebookApi.client.js +631 -0
  12. package/dist/cjs/data-access/http/featureToggleApi.client.js +31 -0
  13. package/dist/cjs/data-access/http/identityServices.client.js +97 -0
  14. package/dist/cjs/data-access/http/instagramApi.client.js +428 -0
  15. package/dist/cjs/data-access/http/ir.client.js +242 -0
  16. package/dist/cjs/data-access/http/linkedInApi.client.js +491 -0
  17. package/dist/cjs/data-access/http/masf.client.js +101 -0
  18. package/dist/cjs/data-access/http/tiktok.native.js +162 -0
  19. package/dist/cjs/data-access/http/tiktokApi.client.js +441 -0
  20. package/dist/cjs/data-access/index.js +132 -0
  21. package/dist/cjs/errors/engage-error.js +16 -0
  22. package/dist/cjs/errors/http-error.js +23 -0
  23. package/dist/cjs/lib/applicationTags.helpers.js +30 -0
  24. package/dist/cjs/lib/configuration.js +14 -0
  25. package/dist/cjs/lib/document-action-events.js +12 -0
  26. package/dist/cjs/lib/externalId.helpers.js +19 -0
  27. package/dist/cjs/lib/hidden.helpers.js +13 -0
  28. package/dist/cjs/lib/hiddenComment.helper.js +119 -0
  29. package/dist/cjs/lib/logger.helpers.js +68 -0
  30. package/dist/cjs/lib/logger.js +23 -0
  31. package/dist/cjs/lib/message.helpers.js +58 -0
  32. package/dist/cjs/lib/metrics.helper.js +97 -0
  33. package/dist/esm/data-access/http/InstagramVideoClient.js +34 -0
  34. package/dist/esm/data-access/http/WarpZoneApi.client.js +24 -0
  35. package/dist/esm/data-access/http/amazonS3.js +37 -0
  36. package/dist/esm/data-access/http/asset-manager-tvm.client.js +28 -0
  37. package/dist/esm/data-access/http/companiesApi.client.js +30 -0
  38. package/dist/esm/data-access/http/credentialsApi.client.js +92 -0
  39. package/dist/esm/data-access/http/entitlementsApi.client.js +32 -0
  40. package/dist/esm/data-access/http/facebook.native.js +325 -0
  41. package/dist/esm/data-access/http/facebookApi.client.js +621 -0
  42. package/dist/esm/data-access/http/featureToggleApi.client.js +23 -0
  43. package/dist/esm/data-access/http/identityServices.client.js +89 -0
  44. package/dist/esm/data-access/http/instagramApi.client.js +420 -0
  45. package/dist/esm/data-access/http/ir.client.js +234 -0
  46. package/dist/esm/data-access/http/linkedInApi.client.js +481 -0
  47. package/dist/esm/data-access/http/masf.client.js +93 -0
  48. package/dist/esm/data-access/http/tiktok.native.js +146 -0
  49. package/dist/esm/data-access/http/tiktokApi.client.js +433 -0
  50. package/dist/esm/data-access/index.js +30 -0
  51. package/dist/esm/errors/engage-error.js +9 -0
  52. package/dist/esm/errors/http-error.js +16 -0
  53. package/dist/esm/lib/applicationTags.helpers.js +22 -0
  54. package/dist/esm/lib/configuration.js +8 -0
  55. package/dist/esm/lib/document-action-events.js +6 -0
  56. package/dist/esm/lib/externalId.helpers.js +12 -0
  57. package/dist/esm/lib/hidden.helpers.js +6 -0
  58. package/dist/esm/lib/hiddenComment.helper.js +112 -0
  59. package/dist/esm/lib/logger.helpers.js +60 -0
  60. package/dist/esm/lib/logger.js +16 -0
  61. package/dist/esm/lib/message.helpers.js +52 -0
  62. package/dist/esm/lib/metrics.helper.js +90 -0
  63. package/package.json +14 -4
  64. package/src/data-access/http/facebook.native.js +542 -0
  65. package/src/data-access/http/tiktok.native.js +248 -0
  66. package/src/data-access/index.js +4 -0
  67. package/src/errors/engage-error.js +11 -0
  68. package/src/errors/http-error.js +19 -0
  69. package/src/lib/logger.helpers.js +15 -0
  70. package/src/lib/message.helpers.js +7 -1
@@ -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
+ }
@@ -16,6 +16,8 @@ import { WarpZoneApiClient } from './http/WarpZoneApi.client.js';
16
16
  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
+ import * as FacebookNative from './http/facebook.native.js';
20
+ import * as TiktokNative from './http/tiktok.native.js';
19
21
 
20
22
  const DocumentHelperFunctions = {
21
23
  ...messageHelpers,
@@ -28,6 +30,8 @@ const LinkedInHelpers = {
28
30
  }
29
31
 
30
32
  export {
33
+ FacebookNative,
34
+ TiktokNative,
31
35
  awsS3Client,
32
36
  assetManagerTvmRepository,
33
37
  CompanyApiClient,
@@ -0,0 +1,11 @@
1
+ export class EngageError extends Error {
2
+ code;
3
+
4
+ constructor(code, message) {
5
+ super(message);
6
+ Object.setPrototypeOf(this, new.target.prototype);
7
+
8
+ this.name = this.constructor.name;
9
+ this.code = code;
10
+ }
11
+ }
@@ -0,0 +1,19 @@
1
+ import { EngageError } from "./engage-error";
2
+
3
+ export class EngageHttpError extends EngageError {
4
+ status;
5
+ statusText;
6
+ response;
7
+ headers;
8
+
9
+ constructor(status, statusText, response, headers) {
10
+ super(`HTTP ${status}: ${statusText}`, statusText);
11
+ Object.setPrototypeOf(this, new.target.prototype);
12
+
13
+ this.name = this.constructor.name;
14
+ this.status = status;
15
+ this.statusText = statusText;
16
+ this.response = response;
17
+ this.headers = headers;
18
+ }
19
+ }
@@ -24,4 +24,19 @@ const MeltwaterAttributes = {
24
24
  USERID: 'user.id', // ID of the user
25
25
  };
26
26
 
27
+ export function loggerDebug(logger, message, meta = {}) {
28
+ if(logger)
29
+ logger.debug(message, meta);
30
+ }
31
+
32
+ export function loggerInfo(logger, message, meta = {}) {
33
+ if(logger)
34
+ logger.info(message, meta);
35
+ }
36
+
37
+ export function loggerError(logger, message, meta = {}) {
38
+ if(logger)
39
+ logger.error(message, meta);
40
+ }
41
+
27
42
  export { MeltwaterAttributes };
@@ -45,7 +45,13 @@ export function isMention({
45
45
  if(authorExternalId && credential.social_account_id &&
46
46
  (
47
47
  authorExternalId === credential.social_account_id) ||
48
- authorHandle === credential.username
48
+ (
49
+ authorHandle?.length &&
50
+ (
51
+ authorHandle.toLowerCase() === credential.username?.toLowerCase ||
52
+ authorHandle.toLowerCase() === credential.handle?.toLowerCase()
53
+ )
54
+ )
49
55
  ){
50
56
  return false;
51
57
  }