@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 { BaseAction } from '@memberjunction/actions';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -10,286 +10,294 @@ import { BaseAction } from '@memberjunction/actions';
|
|
|
10
10
|
*/
|
|
11
11
|
@RegisterClass(BaseAction, 'Instagram - Get Post Insights')
|
|
12
12
|
export class InstagramGetPostInsightsAction extends InstagramBaseAction {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
13
|
+
|
|
14
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
15
|
+
try {
|
|
16
|
+
const companyIntegrationId = this.getParamValue(params.Params, 'CompanyIntegrationID');
|
|
17
|
+
const postId = this.getParamValue(params.Params, 'PostID');
|
|
18
|
+
const metricTypes = this.getParamValue(params.Params, 'MetricTypes') as string[];
|
|
19
|
+
const period = this.getParamValue(params.Params, 'Period') || 'lifetime';
|
|
20
|
+
|
|
21
|
+
// Initialize OAuth
|
|
22
|
+
if (!await this.initializeOAuth(companyIntegrationId)) {
|
|
23
|
+
return {
|
|
24
|
+
Success: false,
|
|
25
|
+
Message: 'Failed to initialize Instagram authentication',
|
|
26
|
+
ResultCode: 'AUTH_FAILED'
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Validate inputs
|
|
31
|
+
if (!postId) {
|
|
32
|
+
return {
|
|
33
|
+
Success: false,
|
|
34
|
+
Message: 'PostID is required',
|
|
35
|
+
ResultCode: 'MISSING_PARAMS'
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// First, get the post details to determine its type
|
|
40
|
+
const postDetails = await this.getPostDetails(postId);
|
|
41
|
+
if (!postDetails) {
|
|
42
|
+
return {
|
|
43
|
+
Success: false,
|
|
44
|
+
Message: 'Post not found or access denied',
|
|
45
|
+
ResultCode: 'POST_NOT_FOUND'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Determine available metrics based on post type
|
|
50
|
+
const availableMetrics = this.getAvailableMetrics(postDetails.media_type);
|
|
51
|
+
const requestedMetrics = metricTypes && metricTypes.length > 0
|
|
52
|
+
? metricTypes.filter(m => availableMetrics.includes(m))
|
|
53
|
+
: availableMetrics;
|
|
54
|
+
|
|
55
|
+
if (requestedMetrics.length === 0) {
|
|
56
|
+
return {
|
|
57
|
+
Success: false,
|
|
58
|
+
Message: 'No valid metrics specified for this post type',
|
|
59
|
+
ResultCode: 'INVALID_METRICS'
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Get insights
|
|
64
|
+
const insights = await this.getInsights(postId, requestedMetrics, period as any);
|
|
65
|
+
|
|
66
|
+
// Parse and structure the insights data
|
|
67
|
+
const parsedInsights = this.parseInsightsData(insights);
|
|
68
|
+
|
|
69
|
+
// Calculate engagement rate
|
|
70
|
+
const engagementRate = this.calculateEngagementRate(parsedInsights, postDetails);
|
|
71
|
+
|
|
72
|
+
// Store result in output params
|
|
73
|
+
const outputParams = [...params.Params];
|
|
74
|
+
outputParams.push({
|
|
75
|
+
Name: 'ResultData',
|
|
76
|
+
Type: 'Output',
|
|
77
|
+
Value: JSON.stringify({
|
|
78
|
+
postId,
|
|
79
|
+
postType: postDetails.media_type,
|
|
80
|
+
permalink: postDetails.permalink,
|
|
81
|
+
publishedAt: postDetails.timestamp,
|
|
82
|
+
metrics: parsedInsights,
|
|
83
|
+
summary: {
|
|
84
|
+
engagementRate,
|
|
85
|
+
totalEngagements: this.calculateTotalEngagements(parsedInsights),
|
|
86
|
+
performanceScore: this.calculatePerformanceScore(parsedInsights)
|
|
87
|
+
},
|
|
88
|
+
period,
|
|
89
|
+
dataCollectedAt: new Date().toISOString()
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
Success: true,
|
|
95
|
+
Message: 'Successfully retrieved post insights',
|
|
96
|
+
ResultCode: 'SUCCESS',
|
|
97
|
+
Params: outputParams
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
} catch (error: any) {
|
|
101
|
+
LogError('Failed to retrieve Instagram post insights', error);
|
|
102
|
+
|
|
103
|
+
if (error.code === 'RATE_LIMIT') {
|
|
104
|
+
return {
|
|
105
|
+
Success: false,
|
|
106
|
+
Message: 'Instagram API rate limit exceeded. Please try again later.',
|
|
107
|
+
ResultCode: 'RATE_LIMIT'
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (error.code === 'POST_NOT_FOUND') {
|
|
112
|
+
return {
|
|
113
|
+
Success: false,
|
|
114
|
+
Message: 'Instagram post not found or access denied',
|
|
115
|
+
ResultCode: 'POST_NOT_FOUND'
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
Success: false,
|
|
121
|
+
Message: `Failed to retrieve post insights: ${error.message}`,
|
|
122
|
+
ResultCode: 'ERROR'
|
|
123
|
+
};
|
|
124
|
+
}
|
|
121
125
|
}
|
|
122
|
-
}
|
|
123
126
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Get post details including media type
|
|
129
|
+
*/
|
|
130
|
+
private async getPostDetails(postId: string): Promise<any> {
|
|
131
|
+
try {
|
|
132
|
+
const response = await this.makeInstagramRequest(
|
|
133
|
+
postId,
|
|
134
|
+
'GET',
|
|
135
|
+
null,
|
|
136
|
+
{
|
|
137
|
+
fields: 'id,media_type,permalink,timestamp,caption,like_count,comments_count',
|
|
138
|
+
access_token: this.getAccessToken()
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
return response;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
136
145
|
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Get available metrics based on post type
|
|
141
|
-
*/
|
|
142
|
-
private getAvailableMetrics(mediaType: string): string[] {
|
|
143
|
-
const baseMetrics = ['impressions', 'reach', 'engagement'];
|
|
144
|
-
|
|
145
|
-
switch (mediaType) {
|
|
146
|
-
case 'IMAGE':
|
|
147
|
-
case 'CAROUSEL_ALBUM':
|
|
148
|
-
return [...baseMetrics, 'saved', 'shares'];
|
|
149
|
-
|
|
150
|
-
case 'VIDEO':
|
|
151
|
-
case 'REELS':
|
|
152
|
-
return [...baseMetrics, 'saved', 'shares', 'video_views', 'avg_watch_time', 'completion_rate'];
|
|
153
|
-
|
|
154
|
-
case 'STORY':
|
|
155
|
-
return ['impressions', 'reach', 'exits', 'replies', 'taps_forward', 'taps_back'];
|
|
156
146
|
|
|
157
|
-
|
|
158
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Get available metrics based on post type
|
|
149
|
+
*/
|
|
150
|
+
private getAvailableMetrics(mediaType: string): string[] {
|
|
151
|
+
const baseMetrics = ['impressions', 'reach', 'engagement'];
|
|
152
|
+
|
|
153
|
+
switch (mediaType) {
|
|
154
|
+
case 'IMAGE':
|
|
155
|
+
case 'CAROUSEL_ALBUM':
|
|
156
|
+
return [...baseMetrics, 'saved', 'shares'];
|
|
157
|
+
|
|
158
|
+
case 'VIDEO':
|
|
159
|
+
case 'REELS':
|
|
160
|
+
return [...baseMetrics, 'saved', 'shares', 'video_views', 'avg_watch_time', 'completion_rate'];
|
|
161
|
+
|
|
162
|
+
case 'STORY':
|
|
163
|
+
return ['impressions', 'reach', 'exits', 'replies', 'taps_forward', 'taps_back'];
|
|
164
|
+
|
|
165
|
+
default:
|
|
166
|
+
return baseMetrics;
|
|
167
|
+
}
|
|
159
168
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Parse insights data into a structured format
|
|
164
|
-
*/
|
|
165
|
-
private parseInsightsData(insights: any[]): Record<string, any> {
|
|
166
|
-
const parsed: Record<string, any> = {};
|
|
167
169
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Parse insights data into a structured format
|
|
172
|
+
*/
|
|
173
|
+
private parseInsightsData(insights: any[]): Record<string, any> {
|
|
174
|
+
const parsed: Record<string, any> = {};
|
|
175
|
+
|
|
176
|
+
insights.forEach(metric => {
|
|
177
|
+
const name = metric.name;
|
|
178
|
+
const values = metric.values || [];
|
|
179
|
+
|
|
180
|
+
if (values.length > 0) {
|
|
181
|
+
// For lifetime metrics, there's usually only one value
|
|
182
|
+
const primaryValue = values[0];
|
|
183
|
+
|
|
184
|
+
parsed[name] = {
|
|
185
|
+
value: primaryValue.value || 0,
|
|
186
|
+
title: metric.title,
|
|
187
|
+
description: metric.description,
|
|
188
|
+
period: metric.period
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// For time series data (like daily metrics)
|
|
192
|
+
if (values.length > 1) {
|
|
193
|
+
parsed[name].timeSeries = values.map((v: any) => ({
|
|
194
|
+
value: v.value,
|
|
195
|
+
endTime: v.end_time
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
return parsed;
|
|
202
|
+
}
|
|
171
203
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Calculate engagement rate
|
|
206
|
+
*/
|
|
207
|
+
private calculateEngagementRate(insights: Record<string, any>, postDetails: any): number {
|
|
208
|
+
const reach = insights.reach?.value || postDetails.reach || 0;
|
|
209
|
+
const engagement = insights.engagement?.value || 0;
|
|
210
|
+
|
|
211
|
+
if (reach === 0) return 0;
|
|
212
|
+
|
|
213
|
+
return Number(((engagement / reach) * 100).toFixed(2));
|
|
214
|
+
}
|
|
175
215
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Calculate total engagements
|
|
218
|
+
*/
|
|
219
|
+
private calculateTotalEngagements(insights: Record<string, any>): number {
|
|
220
|
+
const engagement = insights.engagement?.value || 0;
|
|
221
|
+
const saves = insights.saved?.value || 0;
|
|
222
|
+
const shares = insights.shares?.value || 0;
|
|
223
|
+
|
|
224
|
+
return engagement + saves + shares;
|
|
225
|
+
}
|
|
182
226
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Calculate a performance score (0-100)
|
|
229
|
+
*/
|
|
230
|
+
private calculatePerformanceScore(insights: Record<string, any>): number {
|
|
231
|
+
// Simple scoring algorithm based on key metrics
|
|
232
|
+
let score = 0;
|
|
233
|
+
let factors = 0;
|
|
234
|
+
|
|
235
|
+
// Engagement rate factor
|
|
236
|
+
const reach = insights.reach?.value || 0;
|
|
237
|
+
const engagement = insights.engagement?.value || 0;
|
|
238
|
+
if (reach > 0) {
|
|
239
|
+
const engagementRate = (engagement / reach) * 100;
|
|
240
|
+
score += Math.min(engagementRate * 10, 30); // Max 30 points
|
|
241
|
+
factors++;
|
|
189
242
|
}
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
return parsed;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Calculate engagement rate
|
|
198
|
-
*/
|
|
199
|
-
private calculateEngagementRate(insights: Record<string, any>, postDetails: any): number {
|
|
200
|
-
const reach = insights.reach?.value || postDetails.reach || 0;
|
|
201
|
-
const engagement = insights.engagement?.value || 0;
|
|
202
|
-
|
|
203
|
-
if (reach === 0) return 0;
|
|
204
|
-
|
|
205
|
-
return Number(((engagement / reach) * 100).toFixed(2));
|
|
206
|
-
}
|
|
207
243
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return engagement + saves + shares;
|
|
217
|
-
}
|
|
244
|
+
// Reach factor (compared to impressions)
|
|
245
|
+
const impressions = insights.impressions?.value || 0;
|
|
246
|
+
if (impressions > 0) {
|
|
247
|
+
const reachRate = (reach / impressions) * 100;
|
|
248
|
+
score += Math.min(reachRate, 20); // Max 20 points
|
|
249
|
+
factors++;
|
|
250
|
+
}
|
|
218
251
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
252
|
+
// Saves factor
|
|
253
|
+
const saves = insights.saved?.value || 0;
|
|
254
|
+
if (reach > 0) {
|
|
255
|
+
const saveRate = (saves / reach) * 100;
|
|
256
|
+
score += Math.min(saveRate * 20, 25); // Max 25 points
|
|
257
|
+
factors++;
|
|
258
|
+
}
|
|
226
259
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
factors++;
|
|
234
|
-
}
|
|
260
|
+
// Video completion rate (for videos)
|
|
261
|
+
const completionRate = insights.completion_rate?.value || 0;
|
|
262
|
+
if (completionRate > 0) {
|
|
263
|
+
score += Math.min(completionRate, 25); // Max 25 points
|
|
264
|
+
factors++;
|
|
265
|
+
}
|
|
235
266
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
score += Math.min(reachRate, 20); // Max 20 points
|
|
241
|
-
factors++;
|
|
267
|
+
// Normalize score
|
|
268
|
+
if (factors === 0) return 0;
|
|
269
|
+
|
|
270
|
+
return Math.round(Math.min(score, 100));
|
|
242
271
|
}
|
|
243
272
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
273
|
+
/**
|
|
274
|
+
* Define the parameters for this action
|
|
275
|
+
*/
|
|
276
|
+
public get Params(): ActionParam[] {
|
|
277
|
+
return [
|
|
278
|
+
...this.commonSocialParams,
|
|
279
|
+
{
|
|
280
|
+
Name: 'PostID',
|
|
281
|
+
Type: 'Input',
|
|
282
|
+
Value: null
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
Name: 'MetricTypes',
|
|
286
|
+
Type: 'Input',
|
|
287
|
+
Value: null
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
Name: 'Period',
|
|
291
|
+
Type: 'Input',
|
|
292
|
+
Value: 'lifetime'
|
|
293
|
+
}
|
|
294
|
+
];
|
|
250
295
|
}
|
|
251
296
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
297
|
+
/**
|
|
298
|
+
* Get the description for this action
|
|
299
|
+
*/
|
|
300
|
+
public get Description(): string {
|
|
301
|
+
return 'Retrieves detailed analytics and insights for a specific Instagram post including impressions, reach, engagement, and more.';
|
|
257
302
|
}
|
|
258
|
-
|
|
259
|
-
// Normalize score
|
|
260
|
-
if (factors === 0) return 0;
|
|
261
|
-
|
|
262
|
-
return Math.round(Math.min(score, 100));
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Define the parameters for this action
|
|
267
|
-
*/
|
|
268
|
-
public get Params(): ActionParam[] {
|
|
269
|
-
return [
|
|
270
|
-
...this.commonSocialParams,
|
|
271
|
-
{
|
|
272
|
-
Name: 'PostID',
|
|
273
|
-
Type: 'Input',
|
|
274
|
-
Value: null,
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
Name: 'MetricTypes',
|
|
278
|
-
Type: 'Input',
|
|
279
|
-
Value: null,
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
Name: 'Period',
|
|
283
|
-
Type: 'Input',
|
|
284
|
-
Value: 'lifetime',
|
|
285
|
-
},
|
|
286
|
-
];
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Get the description for this action
|
|
291
|
-
*/
|
|
292
|
-
public get Description(): string {
|
|
293
|
-
return 'Retrieves detailed analytics and insights for a specific Instagram post including impressions, reach, engagement, and more.';
|
|
294
|
-
}
|
|
295
|
-
}
|
|
303
|
+
}
|