@memberjunction/actions-bizapps-social 2.112.0 → 2.113.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +13 -0
- package/dist/base/base-social.action.d.ts.map +1 -1
- package/dist/base/base-social.action.js +24 -18
- package/dist/base/base-social.action.js.map +1 -1
- package/dist/providers/buffer/buffer-base.action.d.ts.map +1 -1
- package/dist/providers/buffer/buffer-base.action.js +34 -35
- package/dist/providers/buffer/buffer-base.action.js.map +1 -1
- package/dist/providers/facebook/actions/boost-post.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/boost-post.action.js +33 -33
- package/dist/providers/facebook/actions/boost-post.action.js.map +1 -1
- package/dist/providers/facebook/actions/create-album.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/create-album.action.js +36 -34
- package/dist/providers/facebook/actions/create-album.action.js.map +1 -1
- package/dist/providers/facebook/actions/create-post.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/create-post.action.js +20 -20
- package/dist/providers/facebook/actions/create-post.action.js.map +1 -1
- package/dist/providers/facebook/actions/get-page-insights.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/get-page-insights.action.js +27 -25
- package/dist/providers/facebook/actions/get-page-insights.action.js.map +1 -1
- package/dist/providers/facebook/actions/get-page-posts.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/get-page-posts.action.js +23 -19
- package/dist/providers/facebook/actions/get-page-posts.action.js.map +1 -1
- package/dist/providers/facebook/actions/get-post-insights.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/get-post-insights.action.js +32 -28
- package/dist/providers/facebook/actions/get-post-insights.action.js.map +1 -1
- package/dist/providers/facebook/actions/respond-to-comments.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/respond-to-comments.action.js +44 -42
- package/dist/providers/facebook/actions/respond-to-comments.action.js.map +1 -1
- package/dist/providers/facebook/actions/schedule-post.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/schedule-post.action.js +29 -29
- package/dist/providers/facebook/actions/schedule-post.action.js.map +1 -1
- package/dist/providers/facebook/actions/search-posts.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/search-posts.action.js +39 -37
- package/dist/providers/facebook/actions/search-posts.action.js.map +1 -1
- package/dist/providers/facebook/facebook-base.action.d.ts.map +1 -1
- package/dist/providers/facebook/facebook-base.action.js +59 -44
- package/dist/providers/facebook/facebook-base.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/bulk-schedule-posts.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/bulk-schedule-posts.action.js +31 -33
- package/dist/providers/hootsuite/actions/bulk-schedule-posts.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/create-scheduled-post.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/create-scheduled-post.action.js +32 -28
- package/dist/providers/hootsuite/actions/create-scheduled-post.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/delete-scheduled-post.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/delete-scheduled-post.action.js +19 -19
- package/dist/providers/hootsuite/actions/delete-scheduled-post.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/get-analytics.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/get-analytics.action.js +26 -24
- package/dist/providers/hootsuite/actions/get-analytics.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/get-scheduled-posts.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/get-scheduled-posts.action.js +22 -22
- package/dist/providers/hootsuite/actions/get-scheduled-posts.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/get-social-profiles.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/get-social-profiles.action.js +34 -32
- package/dist/providers/hootsuite/actions/get-social-profiles.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/search-posts.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/search-posts.action.js +52 -43
- package/dist/providers/hootsuite/actions/search-posts.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/update-scheduled-post.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/update-scheduled-post.action.js +28 -30
- package/dist/providers/hootsuite/actions/update-scheduled-post.action.js.map +1 -1
- package/dist/providers/hootsuite/hootsuite-base.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/hootsuite-base.action.js +20 -18
- package/dist/providers/hootsuite/hootsuite-base.action.js.map +1 -1
- package/dist/providers/instagram/actions/create-post.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/create-post.action.js +26 -27
- package/dist/providers/instagram/actions/create-post.action.js.map +1 -1
- package/dist/providers/instagram/actions/create-story.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/create-story.action.js +35 -35
- package/dist/providers/instagram/actions/create-story.action.js.map +1 -1
- package/dist/providers/instagram/actions/get-account-insights.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/get-account-insights.action.js +59 -38
- package/dist/providers/instagram/actions/get-account-insights.action.js.map +1 -1
- package/dist/providers/instagram/actions/get-business-posts.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/get-business-posts.action.js +29 -29
- package/dist/providers/instagram/actions/get-business-posts.action.js.map +1 -1
- package/dist/providers/instagram/actions/get-comments.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/get-comments.action.js +36 -36
- package/dist/providers/instagram/actions/get-comments.action.js.map +1 -1
- package/dist/providers/instagram/actions/get-post-insights.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/get-post-insights.action.js +25 -23
- package/dist/providers/instagram/actions/get-post-insights.action.js.map +1 -1
- package/dist/providers/instagram/actions/schedule-post.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/schedule-post.action.js +25 -25
- package/dist/providers/instagram/actions/schedule-post.action.js.map +1 -1
- package/dist/providers/instagram/actions/search-posts.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/search-posts.action.js +60 -56
- package/dist/providers/instagram/actions/search-posts.action.js.map +1 -1
- package/dist/providers/instagram/instagram-base.action.d.ts.map +1 -1
- package/dist/providers/instagram/instagram-base.action.js +27 -25
- package/dist/providers/instagram/instagram-base.action.js.map +1 -1
- package/dist/providers/linkedin/actions/create-article.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/create-article.action.js +45 -55
- package/dist/providers/linkedin/actions/create-article.action.js.map +1 -1
- package/dist/providers/linkedin/actions/create-post.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/create-post.action.js +29 -31
- package/dist/providers/linkedin/actions/create-post.action.js.map +1 -1
- package/dist/providers/linkedin/actions/get-followers.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/get-followers.action.js +28 -28
- package/dist/providers/linkedin/actions/get-followers.action.js.map +1 -1
- package/dist/providers/linkedin/actions/get-organization-posts.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/get-organization-posts.action.js +20 -20
- package/dist/providers/linkedin/actions/get-organization-posts.action.js.map +1 -1
- package/dist/providers/linkedin/actions/get-personal-posts.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/get-personal-posts.action.js +19 -19
- package/dist/providers/linkedin/actions/get-personal-posts.action.js.map +1 -1
- package/dist/providers/linkedin/actions/get-post-analytics.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/get-post-analytics.action.js +23 -25
- package/dist/providers/linkedin/actions/get-post-analytics.action.js.map +1 -1
- package/dist/providers/linkedin/actions/schedule-post.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/schedule-post.action.js +30 -32
- package/dist/providers/linkedin/actions/schedule-post.action.js.map +1 -1
- package/dist/providers/linkedin/actions/search-posts.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/search-posts.action.js +30 -28
- package/dist/providers/linkedin/actions/search-posts.action.js.map +1 -1
- package/dist/providers/linkedin/linkedin-base.action.d.ts.map +1 -1
- package/dist/providers/linkedin/linkedin-base.action.js +38 -33
- package/dist/providers/linkedin/linkedin-base.action.js.map +1 -1
- package/dist/providers/tiktok/tiktok-base.action.d.ts.map +1 -1
- package/dist/providers/tiktok/tiktok-base.action.js +26 -25
- package/dist/providers/tiktok/tiktok-base.action.js.map +1 -1
- package/dist/providers/twitter/actions/create-thread.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/create-thread.action.js +29 -25
- package/dist/providers/twitter/actions/create-thread.action.js.map +1 -1
- package/dist/providers/twitter/actions/create-tweet.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/create-tweet.action.js +23 -23
- package/dist/providers/twitter/actions/create-tweet.action.js.map +1 -1
- package/dist/providers/twitter/actions/delete-tweet.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/delete-tweet.action.js +19 -19
- package/dist/providers/twitter/actions/delete-tweet.action.js.map +1 -1
- package/dist/providers/twitter/actions/get-analytics.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/get-analytics.action.js +47 -40
- package/dist/providers/twitter/actions/get-analytics.action.js.map +1 -1
- package/dist/providers/twitter/actions/get-mentions.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/get-mentions.action.js +31 -30
- package/dist/providers/twitter/actions/get-mentions.action.js.map +1 -1
- package/dist/providers/twitter/actions/get-timeline.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/get-timeline.action.js +29 -29
- package/dist/providers/twitter/actions/get-timeline.action.js.map +1 -1
- package/dist/providers/twitter/actions/schedule-tweet.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/schedule-tweet.action.js +26 -26
- package/dist/providers/twitter/actions/schedule-tweet.action.js.map +1 -1
- package/dist/providers/twitter/actions/search-tweets.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/search-tweets.action.js +58 -56
- package/dist/providers/twitter/actions/search-tweets.action.js.map +1 -1
- package/dist/providers/twitter/twitter-base.action.d.ts.map +1 -1
- package/dist/providers/twitter/twitter-base.action.js +68 -58
- package/dist/providers/twitter/twitter-base.action.js.map +1 -1
- package/dist/providers/youtube/youtube-base.action.d.ts +1 -1
- package/dist/providers/youtube/youtube-base.action.d.ts.map +1 -1
- package/dist/providers/youtube/youtube-base.action.js +25 -22
- package/dist/providers/youtube/youtube-base.action.js.map +1 -1
- package/package.json +6 -5
- package/src/base/base-social.action.ts +224 -217
- package/src/providers/buffer/buffer-base.action.ts +441 -435
- package/src/providers/facebook/actions/boost-post.action.ts +386 -350
- package/src/providers/facebook/actions/create-album.action.ts +307 -291
- package/src/providers/facebook/actions/create-post.action.ts +227 -224
- package/src/providers/facebook/actions/get-page-insights.action.ts +403 -383
- package/src/providers/facebook/actions/get-page-posts.action.ts +225 -214
- package/src/providers/facebook/actions/get-post-insights.action.ts +316 -300
- package/src/providers/facebook/actions/respond-to-comments.action.ts +336 -319
- package/src/providers/facebook/actions/schedule-post.action.ts +292 -289
- package/src/providers/facebook/actions/search-posts.action.ts +413 -399
- package/src/providers/facebook/facebook-base.action.ts +670 -653
- package/src/providers/hootsuite/actions/bulk-schedule-posts.action.ts +257 -257
- package/src/providers/hootsuite/actions/create-scheduled-post.action.ts +189 -184
- package/src/providers/hootsuite/actions/delete-scheduled-post.action.ts +161 -160
- package/src/providers/hootsuite/actions/get-analytics.action.ts +254 -249
- package/src/providers/hootsuite/actions/get-scheduled-posts.action.ts +207 -206
- package/src/providers/hootsuite/actions/get-social-profiles.action.ts +205 -206
- package/src/providers/hootsuite/actions/search-posts.action.ts +369 -351
- package/src/providers/hootsuite/actions/update-scheduled-post.action.ts +209 -211
- package/src/providers/hootsuite/hootsuite-base.action.ts +307 -301
- package/src/providers/instagram/actions/create-post.action.ts +296 -276
- package/src/providers/instagram/actions/create-story.action.ts +394 -378
- package/src/providers/instagram/actions/get-account-insights.action.ts +420 -384
- package/src/providers/instagram/actions/get-business-posts.action.ts +242 -233
- package/src/providers/instagram/actions/get-comments.action.ts +377 -365
- package/src/providers/instagram/actions/get-post-insights.action.ts +273 -265
- package/src/providers/instagram/actions/schedule-post.action.ts +235 -233
- package/src/providers/instagram/actions/search-posts.action.ts +538 -512
- package/src/providers/instagram/instagram-base.action.ts +393 -368
- package/src/providers/linkedin/actions/create-article.action.ts +266 -275
- package/src/providers/linkedin/actions/create-post.action.ts +177 -179
- package/src/providers/linkedin/actions/get-followers.action.ts +211 -211
- package/src/providers/linkedin/actions/get-organization-posts.action.ts +147 -146
- package/src/providers/linkedin/actions/get-personal-posts.action.ts +139 -138
- package/src/providers/linkedin/actions/get-post-analytics.action.ts +189 -190
- package/src/providers/linkedin/actions/schedule-post.action.ts +189 -191
- package/src/providers/linkedin/actions/search-posts.action.ts +283 -275
- package/src/providers/linkedin/linkedin-base.action.ts +421 -407
- package/src/providers/tiktok/tiktok-base.action.ts +320 -305
- package/src/providers/twitter/actions/create-thread.action.ts +207 -203
- package/src/providers/twitter/actions/create-tweet.action.ts +188 -187
- package/src/providers/twitter/actions/delete-tweet.action.ts +129 -128
- package/src/providers/twitter/actions/get-analytics.action.ts +411 -402
- package/src/providers/twitter/actions/get-mentions.action.ts +219 -218
- package/src/providers/twitter/actions/get-timeline.action.ts +233 -232
- package/src/providers/twitter/actions/schedule-tweet.action.ts +222 -221
- package/src/providers/twitter/actions/search-tweets.action.ts +543 -540
- package/src/providers/twitter/twitter-base.action.ts +560 -541
- package/src/providers/youtube/youtube-base.action.ts +333 -320
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RegisterClass } from '@memberjunction/global';
|
|
2
2
|
import { InstagramBaseAction } from '../instagram-base.action';
|
|
3
3
|
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
|
-
import { LogError } from '@memberjunction/
|
|
4
|
+
import { LogError } from '@memberjunction/core';
|
|
5
5
|
import { SocialPost } from '../../../base/base-social.action';
|
|
6
6
|
import { BaseAction } from '@memberjunction/actions';
|
|
7
7
|
|
|
@@ -11,263 +11,272 @@ import { BaseAction } from '@memberjunction/actions';
|
|
|
11
11
|
*/
|
|
12
12
|
@RegisterClass(BaseAction, 'Instagram - Get Business Posts')
|
|
13
13
|
export class InstagramGetBusinessPostsAction extends InstagramBaseAction {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
|
|
15
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
16
|
+
try {
|
|
17
|
+
const companyIntegrationId = this.getParamValue(params.Params, 'CompanyIntegrationID');
|
|
18
|
+
const limit = this.getParamValue(params.Params, 'Limit') || 25;
|
|
19
|
+
const mediaType = this.getParamValue(params.Params, 'MediaType');
|
|
20
|
+
const includeMetrics = this.getParamValue(params.Params, 'IncludeMetrics') !== false;
|
|
21
|
+
const afterCursor = this.getParamValue(params.Params, 'AfterCursor');
|
|
22
|
+
const startDate = this.getParamValue(params.Params, 'StartDate');
|
|
23
|
+
const endDate = this.getParamValue(params.Params, 'EndDate');
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
// Initialize OAuth
|
|
26
|
+
if (!await this.initializeOAuth(companyIntegrationId)) {
|
|
27
|
+
return {
|
|
28
|
+
Success: false,
|
|
29
|
+
Message: 'Failed to initialize Instagram authentication',
|
|
30
|
+
ResultCode: 'AUTH_FAILED'
|
|
31
|
+
};
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
// Build fields parameter
|
|
35
|
+
let fields = 'id,caption,media_type,media_url,thumbnail_url,permalink,timestamp';
|
|
36
|
+
if (includeMetrics) {
|
|
37
|
+
fields += ',like_count,comments_count,impressions,reach,saved,video_views';
|
|
38
|
+
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
// Build query parameters
|
|
41
|
+
const queryParams: any = {
|
|
42
|
+
fields,
|
|
43
|
+
access_token: this.getAccessToken(),
|
|
44
|
+
limit: Math.min(limit, 100) // Instagram max is 100 per request
|
|
45
|
+
};
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
if (afterCursor) {
|
|
48
|
+
queryParams.after = afterCursor;
|
|
49
|
+
}
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
// Add date filtering if provided
|
|
52
|
+
if (startDate) {
|
|
53
|
+
queryParams.since = Math.floor(new Date(startDate).getTime() / 1000);
|
|
54
|
+
}
|
|
55
|
+
if (endDate) {
|
|
56
|
+
queryParams.until = Math.floor(new Date(endDate).getTime() / 1000);
|
|
57
|
+
}
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
59
|
+
// Fetch posts
|
|
60
|
+
const response = await this.makeInstagramRequest<{
|
|
61
|
+
data: any[];
|
|
62
|
+
paging?: {
|
|
63
|
+
cursors: {
|
|
64
|
+
before: string;
|
|
65
|
+
after: string;
|
|
66
|
+
};
|
|
67
|
+
next?: string;
|
|
68
|
+
previous?: string;
|
|
69
|
+
};
|
|
70
|
+
}>(
|
|
71
|
+
`${this.instagramBusinessAccountId}/media`,
|
|
72
|
+
'GET',
|
|
73
|
+
null,
|
|
74
|
+
queryParams
|
|
75
|
+
);
|
|
70
76
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
// Filter by media type if specified
|
|
78
|
+
let posts = response.data || [];
|
|
79
|
+
if (mediaType) {
|
|
80
|
+
posts = posts.filter(post => post.media_type === mediaType);
|
|
81
|
+
}
|
|
76
82
|
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
// Transform to common format
|
|
84
|
+
const normalizedPosts: SocialPost[] = posts.map(post => this.normalizePost(post));
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
// Get additional insights if requested and available
|
|
87
|
+
if (includeMetrics && posts.length > 0) {
|
|
88
|
+
await this.enrichPostsWithInsights(normalizedPosts);
|
|
89
|
+
}
|
|
84
90
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
// Store result in output params
|
|
92
|
+
const outputParams = [...params.Params];
|
|
93
|
+
outputParams.push({
|
|
94
|
+
Name: 'ResultData',
|
|
95
|
+
Type: 'Output',
|
|
96
|
+
Value: JSON.stringify({
|
|
97
|
+
posts: normalizedPosts,
|
|
98
|
+
paging: {
|
|
99
|
+
hasNext: !!response.paging?.next,
|
|
100
|
+
hasPrevious: !!response.paging?.previous,
|
|
101
|
+
afterCursor: response.paging?.cursors?.after,
|
|
102
|
+
beforeCursor: response.paging?.cursors?.before
|
|
103
|
+
},
|
|
104
|
+
summary: {
|
|
105
|
+
totalPosts: normalizedPosts.length,
|
|
106
|
+
mediaTypes: this.summarizeMediaTypes(posts),
|
|
107
|
+
dateRange: this.getDateRange(normalizedPosts)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
});
|
|
105
111
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
} catch (error: any) {
|
|
113
|
-
LogError('Failed to retrieve Instagram business posts', error);
|
|
112
|
+
return {
|
|
113
|
+
Success: true,
|
|
114
|
+
Message: `Retrieved ${normalizedPosts.length} Instagram posts`,
|
|
115
|
+
ResultCode: 'SUCCESS',
|
|
116
|
+
Params: outputParams
|
|
117
|
+
};
|
|
114
118
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
} catch (error: any) {
|
|
120
|
+
LogError('Failed to retrieve Instagram business posts', error);
|
|
121
|
+
|
|
122
|
+
if (error.code === 'RATE_LIMIT') {
|
|
123
|
+
return {
|
|
124
|
+
Success: false,
|
|
125
|
+
Message: 'Instagram API rate limit exceeded. Please try again later.',
|
|
126
|
+
ResultCode: 'RATE_LIMIT'
|
|
127
|
+
};
|
|
128
|
+
}
|
|
122
129
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
if (error.code === 'INSUFFICIENT_PERMISSIONS') {
|
|
131
|
+
return {
|
|
132
|
+
Success: false,
|
|
133
|
+
Message: 'Insufficient permissions to access Instagram business posts',
|
|
134
|
+
ResultCode: 'INSUFFICIENT_PERMISSIONS'
|
|
135
|
+
};
|
|
136
|
+
}
|
|
130
137
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
return {
|
|
139
|
+
Success: false,
|
|
140
|
+
Message: `Failed to retrieve Instagram posts: ${error.message}`,
|
|
141
|
+
ResultCode: 'ERROR'
|
|
142
|
+
};
|
|
143
|
+
}
|
|
136
144
|
}
|
|
137
|
-
}
|
|
138
145
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Enrich posts with additional insights data
|
|
148
|
+
*/
|
|
149
|
+
private async enrichPostsWithInsights(posts: SocialPost[]): Promise<void> {
|
|
150
|
+
// Instagram allows batch insights requests
|
|
151
|
+
const postIds = posts.map(p => p.id);
|
|
152
|
+
const batchSize = 50; // Instagram's batch limit
|
|
146
153
|
|
|
147
|
-
|
|
148
|
-
|
|
154
|
+
for (let i = 0; i < postIds.length; i += batchSize) {
|
|
155
|
+
const batch = postIds.slice(i, i + batchSize);
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
// Get insights for this batch
|
|
159
|
+
const metrics = ['impressions', 'reach', 'engagement', 'saved', 'video_views'];
|
|
160
|
+
const insightsPromises = batch.map(postId =>
|
|
161
|
+
this.getInsights(postId, metrics, 'lifetime')
|
|
162
|
+
);
|
|
149
163
|
|
|
150
|
-
|
|
151
|
-
// Get insights for this batch
|
|
152
|
-
const metrics = ['impressions', 'reach', 'engagement', 'saved', 'video_views'];
|
|
153
|
-
const insightsPromises = batch.map((postId) => this.getInsights(postId, metrics, 'lifetime'));
|
|
164
|
+
const insightsResults = await Promise.allSettled(insightsPromises);
|
|
154
165
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
// Map insights back to posts
|
|
167
|
+
insightsResults.forEach((result, index) => {
|
|
168
|
+
if (result.status === 'fulfilled' && result.value) {
|
|
169
|
+
const postIndex = i + index;
|
|
170
|
+
const post = posts[postIndex];
|
|
171
|
+
|
|
172
|
+
// Parse insights data
|
|
173
|
+
result.value.forEach((metric: any) => {
|
|
174
|
+
const value = metric.values?.[0]?.value || 0;
|
|
175
|
+
|
|
176
|
+
switch (metric.name) {
|
|
177
|
+
case 'impressions':
|
|
178
|
+
post.analytics!.impressions = value;
|
|
179
|
+
break;
|
|
180
|
+
case 'reach':
|
|
181
|
+
post.analytics!.reach = value;
|
|
182
|
+
break;
|
|
183
|
+
case 'engagement':
|
|
184
|
+
post.analytics!.engagements = value;
|
|
185
|
+
break;
|
|
186
|
+
case 'saved':
|
|
187
|
+
post.analytics!.saves = value;
|
|
188
|
+
break;
|
|
189
|
+
case 'video_views':
|
|
190
|
+
post.analytics!.videoViews = value;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
} catch (error) {
|
|
197
|
+
// Log but don't fail the whole operation
|
|
198
|
+
LogError(`Failed to get insights for batch starting at ${i}`, error);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
162
202
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Summarize media types in the response
|
|
205
|
+
*/
|
|
206
|
+
private summarizeMediaTypes(posts: any[]): Record<string, number> {
|
|
207
|
+
const summary: Record<string, number> = {
|
|
208
|
+
IMAGE: 0,
|
|
209
|
+
VIDEO: 0,
|
|
210
|
+
CAROUSEL_ALBUM: 0
|
|
211
|
+
};
|
|
166
212
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
case 'reach':
|
|
172
|
-
post.analytics!.reach = value;
|
|
173
|
-
break;
|
|
174
|
-
case 'engagement':
|
|
175
|
-
post.analytics!.engagements = value;
|
|
176
|
-
break;
|
|
177
|
-
case 'saved':
|
|
178
|
-
post.analytics!.saves = value;
|
|
179
|
-
break;
|
|
180
|
-
case 'video_views':
|
|
181
|
-
post.analytics!.videoViews = value;
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
213
|
+
posts.forEach(post => {
|
|
214
|
+
if (summary[post.media_type] !== undefined) {
|
|
215
|
+
summary[post.media_type]++;
|
|
216
|
+
}
|
|
186
217
|
});
|
|
187
|
-
} catch (error) {
|
|
188
|
-
// Log but don't fail the whole operation
|
|
189
|
-
LogError(`Failed to get insights for batch starting at ${i}`, error);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
218
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
*/
|
|
197
|
-
private summarizeMediaTypes(posts: any[]): Record<string, number> {
|
|
198
|
-
const summary: Record<string, number> = {
|
|
199
|
-
IMAGE: 0,
|
|
200
|
-
VIDEO: 0,
|
|
201
|
-
CAROUSEL_ALBUM: 0,
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
posts.forEach((post) => {
|
|
205
|
-
if (summary[post.media_type] !== undefined) {
|
|
206
|
-
summary[post.media_type]++;
|
|
207
|
-
}
|
|
208
|
-
});
|
|
219
|
+
return summary;
|
|
220
|
+
}
|
|
209
221
|
|
|
210
|
-
|
|
211
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Get date range of posts
|
|
224
|
+
*/
|
|
225
|
+
private getDateRange(posts: SocialPost[]): { earliest: Date | null; latest: Date | null } {
|
|
226
|
+
if (posts.length === 0) {
|
|
227
|
+
return { earliest: null, latest: null };
|
|
228
|
+
}
|
|
212
229
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return { earliest: null, latest: null };
|
|
230
|
+
const dates = posts.map(p => p.publishedAt.getTime());
|
|
231
|
+
return {
|
|
232
|
+
earliest: new Date(Math.min(...dates)),
|
|
233
|
+
latest: new Date(Math.max(...dates))
|
|
234
|
+
};
|
|
219
235
|
}
|
|
220
236
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
{
|
|
260
|
-
Name: 'EndDate',
|
|
261
|
-
Type: 'Input',
|
|
262
|
-
Value: null,
|
|
263
|
-
},
|
|
264
|
-
];
|
|
265
|
-
}
|
|
237
|
+
/**
|
|
238
|
+
* Define the parameters for this action
|
|
239
|
+
*/
|
|
240
|
+
public get Params(): ActionParam[] {
|
|
241
|
+
return [
|
|
242
|
+
...this.commonSocialParams,
|
|
243
|
+
{
|
|
244
|
+
Name: 'Limit',
|
|
245
|
+
Type: 'Input',
|
|
246
|
+
Value: 25
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
Name: 'MediaType',
|
|
250
|
+
Type: 'Input',
|
|
251
|
+
Value: null
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
Name: 'IncludeMetrics',
|
|
255
|
+
Type: 'Input',
|
|
256
|
+
Value: true
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
Name: 'AfterCursor',
|
|
260
|
+
Type: 'Input',
|
|
261
|
+
Value: null
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
Name: 'StartDate',
|
|
265
|
+
Type: 'Input',
|
|
266
|
+
Value: null
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
Name: 'EndDate',
|
|
270
|
+
Type: 'Input',
|
|
271
|
+
Value: null
|
|
272
|
+
}
|
|
273
|
+
];
|
|
274
|
+
}
|
|
266
275
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
276
|
+
/**
|
|
277
|
+
* Get the description for this action
|
|
278
|
+
*/
|
|
279
|
+
public get Description(): string {
|
|
280
|
+
return 'Retrieves posts from an Instagram Business account with optional metrics and filtering.';
|
|
281
|
+
}
|
|
282
|
+
}
|