@memberjunction/actions-bizapps-social 2.111.0 → 2.112.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 +6 -6
- package/dist/base/base-social.action.d.ts.map +1 -1
- package/dist/base/base-social.action.js +18 -24
- 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 +35 -34
- 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 +34 -36
- 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 +25 -27
- 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 +19 -23
- 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 +28 -32
- 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 +42 -44
- 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 +37 -39
- 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 +44 -59
- 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 +33 -31
- 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 +28 -32
- 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 +24 -26
- 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 +32 -34
- 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 +43 -52
- 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 +30 -28
- 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 +18 -20
- 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 +27 -26
- 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 +38 -59
- 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 +23 -25
- 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 +56 -60
- 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 +25 -27
- 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 +55 -45
- 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 +31 -29
- 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 +25 -23
- 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 +32 -30
- 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 +28 -30
- 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 +33 -38
- 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 +25 -26
- 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 +25 -29
- 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 +40 -47
- 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 +30 -31
- 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 +56 -58
- 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 +58 -68
- 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 +22 -25
- package/dist/providers/youtube/youtube-base.action.js.map +1 -1
- package/package.json +5 -6
- package/src/base/base-social.action.ts +217 -224
- package/src/providers/buffer/buffer-base.action.ts +435 -441
- package/src/providers/facebook/actions/boost-post.action.ts +350 -386
- package/src/providers/facebook/actions/create-album.action.ts +291 -307
- package/src/providers/facebook/actions/create-post.action.ts +224 -227
- package/src/providers/facebook/actions/get-page-insights.action.ts +383 -403
- package/src/providers/facebook/actions/get-page-posts.action.ts +214 -225
- package/src/providers/facebook/actions/get-post-insights.action.ts +300 -316
- package/src/providers/facebook/actions/respond-to-comments.action.ts +319 -336
- package/src/providers/facebook/actions/schedule-post.action.ts +289 -292
- package/src/providers/facebook/actions/search-posts.action.ts +399 -413
- package/src/providers/facebook/facebook-base.action.ts +653 -670
- package/src/providers/hootsuite/actions/bulk-schedule-posts.action.ts +257 -257
- package/src/providers/hootsuite/actions/create-scheduled-post.action.ts +184 -189
- package/src/providers/hootsuite/actions/delete-scheduled-post.action.ts +160 -161
- package/src/providers/hootsuite/actions/get-analytics.action.ts +249 -254
- package/src/providers/hootsuite/actions/get-scheduled-posts.action.ts +206 -207
- package/src/providers/hootsuite/actions/get-social-profiles.action.ts +206 -205
- package/src/providers/hootsuite/actions/search-posts.action.ts +351 -369
- package/src/providers/hootsuite/actions/update-scheduled-post.action.ts +211 -209
- package/src/providers/hootsuite/hootsuite-base.action.ts +301 -307
- package/src/providers/instagram/actions/create-post.action.ts +276 -296
- package/src/providers/instagram/actions/create-story.action.ts +378 -394
- package/src/providers/instagram/actions/get-account-insights.action.ts +384 -420
- package/src/providers/instagram/actions/get-business-posts.action.ts +233 -242
- package/src/providers/instagram/actions/get-comments.action.ts +365 -377
- package/src/providers/instagram/actions/get-post-insights.action.ts +265 -273
- package/src/providers/instagram/actions/schedule-post.action.ts +233 -235
- package/src/providers/instagram/actions/search-posts.action.ts +512 -538
- package/src/providers/instagram/instagram-base.action.ts +368 -393
- package/src/providers/linkedin/actions/create-article.action.ts +275 -266
- package/src/providers/linkedin/actions/create-post.action.ts +179 -177
- package/src/providers/linkedin/actions/get-followers.action.ts +211 -211
- package/src/providers/linkedin/actions/get-organization-posts.action.ts +146 -147
- package/src/providers/linkedin/actions/get-personal-posts.action.ts +138 -139
- package/src/providers/linkedin/actions/get-post-analytics.action.ts +190 -189
- package/src/providers/linkedin/actions/schedule-post.action.ts +191 -189
- package/src/providers/linkedin/actions/search-posts.action.ts +275 -283
- package/src/providers/linkedin/linkedin-base.action.ts +407 -421
- package/src/providers/tiktok/tiktok-base.action.ts +305 -320
- package/src/providers/twitter/actions/create-thread.action.ts +203 -207
- package/src/providers/twitter/actions/create-tweet.action.ts +187 -188
- package/src/providers/twitter/actions/delete-tweet.action.ts +128 -129
- package/src/providers/twitter/actions/get-analytics.action.ts +402 -411
- package/src/providers/twitter/actions/get-mentions.action.ts +218 -219
- package/src/providers/twitter/actions/get-timeline.action.ts +232 -233
- package/src/providers/twitter/actions/schedule-tweet.action.ts +221 -222
- package/src/providers/twitter/actions/search-tweets.action.ts +540 -543
- package/src/providers/twitter/twitter-base.action.ts +541 -560
- package/src/providers/youtube/youtube-base.action.ts +320 -333
|
@@ -2,7 +2,7 @@ import { RegisterClass } from '@memberjunction/global';
|
|
|
2
2
|
import { FacebookBaseAction, GetPagePostsParams } from '../facebook-base.action';
|
|
3
3
|
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
4
|
import { SocialMediaErrorCode } from '../../../base/base-social.action';
|
|
5
|
-
import { LogStatus, LogError } from '@memberjunction/
|
|
5
|
+
import { LogStatus, LogError } from '@memberjunction/global';
|
|
6
6
|
import { BaseAction } from '@memberjunction/actions';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -11,232 +11,221 @@ import { BaseAction } from '@memberjunction/actions';
|
|
|
11
11
|
*/
|
|
12
12
|
@RegisterClass(BaseAction, 'FacebookGetPagePostsAction')
|
|
13
13
|
export class FacebookGetPagePostsAction extends FacebookBaseAction {
|
|
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
|
-
if (!pageId) {
|
|
85
|
-
return {
|
|
86
|
-
Success: false,
|
|
87
|
-
Message: 'PageID is required',
|
|
88
|
-
ResultCode: 'MISSING_REQUIRED_PARAM'
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Initialize OAuth
|
|
93
|
-
if (!await this.initializeOAuth(companyIntegrationId)) {
|
|
94
|
-
return {
|
|
95
|
-
Success: false,
|
|
96
|
-
Message: 'Failed to initialize Facebook OAuth connection',
|
|
97
|
-
ResultCode: 'INVALID_TOKEN'
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Get parameters
|
|
102
|
-
const startDate = this.getParamValue(Params, 'StartDate') as string;
|
|
103
|
-
const endDate = this.getParamValue(Params, 'EndDate') as string;
|
|
104
|
-
const limit = this.getParamValue(Params, 'Limit') as number || 100;
|
|
105
|
-
const maxResults = this.getParamValue(Params, 'MaxResults') as number;
|
|
106
|
-
const includeUnpublished = this.getParamValue(Params, 'IncludeUnpublished') as boolean;
|
|
107
|
-
const includeInsights = this.getParamValue(Params, 'IncludeInsights') as boolean;
|
|
108
|
-
|
|
109
|
-
// Build query parameters
|
|
110
|
-
const queryParams: GetPagePostsParams = {
|
|
111
|
-
limit: Math.min(limit, 100), // Facebook max is 100 per request
|
|
112
|
-
published: includeUnpublished ? undefined : true
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
if (startDate) {
|
|
116
|
-
queryParams.since = new Date(startDate);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (endDate) {
|
|
120
|
-
queryParams.until = new Date(endDate);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
LogStatus(`Retrieving posts from Facebook page ${pageId}...`);
|
|
124
|
-
|
|
125
|
-
// Get posts with pagination support
|
|
126
|
-
let allPosts = await this.getPagePosts(pageId, queryParams);
|
|
127
|
-
|
|
128
|
-
// If we need more posts and have a maxResults, use pagination
|
|
129
|
-
if (maxResults && allPosts.length < maxResults && allPosts.length === queryParams.limit) {
|
|
130
|
-
LogStatus(`Fetching additional pages of posts...`);
|
|
131
|
-
|
|
132
|
-
const pageToken = await this.getPageAccessToken(pageId);
|
|
133
|
-
const fields = includeInsights ? this.getPostFields() : this.getPostFieldsWithoutInsights();
|
|
134
|
-
|
|
135
|
-
allPosts = await this.getPaginatedResults(
|
|
136
|
-
`${this.apiBaseUrl}/${pageId}/posts`,
|
|
137
|
-
{
|
|
138
|
-
access_token: pageToken,
|
|
139
|
-
fields,
|
|
140
|
-
...queryParams,
|
|
141
|
-
since: queryParams.since ? Math.floor(queryParams.since.getTime() / 1000) : undefined,
|
|
142
|
-
until: queryParams.until ? Math.floor(queryParams.until.getTime() / 1000) : undefined
|
|
143
|
-
},
|
|
144
|
-
maxResults
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Limit results if maxResults specified
|
|
149
|
-
if (maxResults && allPosts.length > maxResults) {
|
|
150
|
-
allPosts = allPosts.slice(0, maxResults);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
LogStatus(`Retrieved ${allPosts.length} posts from Facebook page`);
|
|
154
|
-
|
|
155
|
-
// Normalize posts to common format
|
|
156
|
-
const normalizedPosts = allPosts.map(post => this.normalizePost(post));
|
|
157
|
-
|
|
158
|
-
// Calculate summary statistics
|
|
159
|
-
const summary = {
|
|
160
|
-
totalPosts: normalizedPosts.length,
|
|
161
|
-
dateRange: {
|
|
162
|
-
earliest: normalizedPosts.length > 0
|
|
163
|
-
? normalizedPosts[normalizedPosts.length - 1].publishedAt
|
|
164
|
-
: null,
|
|
165
|
-
latest: normalizedPosts.length > 0
|
|
166
|
-
? normalizedPosts[0].publishedAt
|
|
167
|
-
: null
|
|
168
|
-
},
|
|
169
|
-
postTypes: this.categorizePostTypes(allPosts),
|
|
170
|
-
totalEngagements: normalizedPosts.reduce((sum, post) =>
|
|
171
|
-
sum + (post.analytics?.engagements || 0), 0
|
|
172
|
-
),
|
|
173
|
-
totalImpressions: normalizedPosts.reduce((sum, post) =>
|
|
174
|
-
sum + (post.analytics?.impressions || 0), 0
|
|
175
|
-
)
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// Update output parameters
|
|
179
|
-
const outputParams = [...Params];
|
|
180
|
-
// TODO: Set output parameters based on result
|
|
181
|
-
|
|
182
|
-
return {
|
|
183
|
-
Success: true,
|
|
184
|
-
Message: `Successfully retrieved ${normalizedPosts.length} posts`,
|
|
185
|
-
ResultCode: 'SUCCESS',
|
|
186
|
-
Params: outputParams
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
} catch (error) {
|
|
190
|
-
LogError(`Failed to get Facebook page posts: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
191
|
-
|
|
192
|
-
if (this.isAuthError(error)) {
|
|
193
|
-
return this.handleOAuthError(error);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
Success: false,
|
|
198
|
-
Message: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
199
|
-
ResultCode: 'ERROR'
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Get post fields without insights (for faster queries or when insights not available)
|
|
206
|
-
*/
|
|
207
|
-
private getPostFieldsWithoutInsights(): string {
|
|
208
|
-
return 'id,message,created_time,updated_time,from,story,permalink_url,attachments,shares,reactions.summary(true),comments.summary(true)';
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Categorize posts by type based on attachments
|
|
213
|
-
*/
|
|
214
|
-
private categorizePostTypes(posts: any[]): Record<string, number> {
|
|
215
|
-
const types: Record<string, number> = {
|
|
216
|
-
status: 0,
|
|
217
|
-
photo: 0,
|
|
218
|
-
video: 0,
|
|
219
|
-
link: 0,
|
|
220
|
-
event: 0,
|
|
221
|
-
offer: 0,
|
|
222
|
-
album: 0
|
|
14
|
+
/**
|
|
15
|
+
* Get action description
|
|
16
|
+
*/
|
|
17
|
+
public get Description(): string {
|
|
18
|
+
return 'Retrieves posts from a Facebook page with optional date range filtering and pagination';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Define the parameters for this action
|
|
23
|
+
*/
|
|
24
|
+
public get Params(): ActionParam[] {
|
|
25
|
+
return [
|
|
26
|
+
...this.commonSocialParams,
|
|
27
|
+
{
|
|
28
|
+
Name: 'PageID',
|
|
29
|
+
Type: 'Input',
|
|
30
|
+
Value: null,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
Name: 'StartDate',
|
|
34
|
+
Type: 'Input',
|
|
35
|
+
Value: null,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
Name: 'EndDate',
|
|
39
|
+
Type: 'Input',
|
|
40
|
+
Value: null,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
Name: 'Limit',
|
|
44
|
+
Type: 'Input',
|
|
45
|
+
Value: 100,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
Name: 'MaxResults',
|
|
49
|
+
Type: 'Input',
|
|
50
|
+
Value: null,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
Name: 'IncludeUnpublished',
|
|
54
|
+
Type: 'Input',
|
|
55
|
+
Value: false,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
Name: 'IncludeInsights',
|
|
59
|
+
Type: 'Input',
|
|
60
|
+
Value: true,
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Execute the action
|
|
67
|
+
*/
|
|
68
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
69
|
+
const { Params, ContextUser } = params;
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
// Validate required parameters
|
|
73
|
+
const companyIntegrationId = this.getParamValue(Params, 'CompanyIntegrationID');
|
|
74
|
+
const pageId = this.getParamValue(Params, 'PageID');
|
|
75
|
+
|
|
76
|
+
if (!companyIntegrationId) {
|
|
77
|
+
return {
|
|
78
|
+
Success: false,
|
|
79
|
+
Message: 'CompanyIntegrationID is required',
|
|
80
|
+
ResultCode: 'INVALID_TOKEN',
|
|
223
81
|
};
|
|
82
|
+
}
|
|
224
83
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
84
|
+
if (!pageId) {
|
|
85
|
+
return {
|
|
86
|
+
Success: false,
|
|
87
|
+
Message: 'PageID is required',
|
|
88
|
+
ResultCode: 'MISSING_REQUIRED_PARAM',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Initialize OAuth
|
|
93
|
+
if (!(await this.initializeOAuth(companyIntegrationId))) {
|
|
94
|
+
return {
|
|
95
|
+
Success: false,
|
|
96
|
+
Message: 'Failed to initialize Facebook OAuth connection',
|
|
97
|
+
ResultCode: 'INVALID_TOKEN',
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Get parameters
|
|
102
|
+
const startDate = this.getParamValue(Params, 'StartDate') as string;
|
|
103
|
+
const endDate = this.getParamValue(Params, 'EndDate') as string;
|
|
104
|
+
const limit = (this.getParamValue(Params, 'Limit') as number) || 100;
|
|
105
|
+
const maxResults = this.getParamValue(Params, 'MaxResults') as number;
|
|
106
|
+
const includeUnpublished = this.getParamValue(Params, 'IncludeUnpublished') as boolean;
|
|
107
|
+
const includeInsights = this.getParamValue(Params, 'IncludeInsights') as boolean;
|
|
108
|
+
|
|
109
|
+
// Build query parameters
|
|
110
|
+
const queryParams: GetPagePostsParams = {
|
|
111
|
+
limit: Math.min(limit, 100), // Facebook max is 100 per request
|
|
112
|
+
published: includeUnpublished ? undefined : true,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if (startDate) {
|
|
116
|
+
queryParams.since = new Date(startDate);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (endDate) {
|
|
120
|
+
queryParams.until = new Date(endDate);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
LogStatus(`Retrieving posts from Facebook page ${pageId}...`);
|
|
124
|
+
|
|
125
|
+
// Get posts with pagination support
|
|
126
|
+
let allPosts = await this.getPagePosts(pageId, queryParams);
|
|
127
|
+
|
|
128
|
+
// If we need more posts and have a maxResults, use pagination
|
|
129
|
+
if (maxResults && allPosts.length < maxResults && allPosts.length === queryParams.limit) {
|
|
130
|
+
LogStatus(`Fetching additional pages of posts...`);
|
|
131
|
+
|
|
132
|
+
const pageToken = await this.getPageAccessToken(pageId);
|
|
133
|
+
const fields = includeInsights ? this.getPostFields() : this.getPostFieldsWithoutInsights();
|
|
134
|
+
|
|
135
|
+
allPosts = await this.getPaginatedResults(
|
|
136
|
+
`${this.apiBaseUrl}/${pageId}/posts`,
|
|
137
|
+
{
|
|
138
|
+
access_token: pageToken,
|
|
139
|
+
fields,
|
|
140
|
+
...queryParams,
|
|
141
|
+
since: queryParams.since ? Math.floor(queryParams.since.getTime() / 1000) : undefined,
|
|
142
|
+
until: queryParams.until ? Math.floor(queryParams.until.getTime() / 1000) : undefined,
|
|
143
|
+
},
|
|
144
|
+
maxResults
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Limit results if maxResults specified
|
|
149
|
+
if (maxResults && allPosts.length > maxResults) {
|
|
150
|
+
allPosts = allPosts.slice(0, maxResults);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
LogStatus(`Retrieved ${allPosts.length} posts from Facebook page`);
|
|
154
|
+
|
|
155
|
+
// Normalize posts to common format
|
|
156
|
+
const normalizedPosts = allPosts.map((post) => this.normalizePost(post));
|
|
157
|
+
|
|
158
|
+
// Calculate summary statistics
|
|
159
|
+
const summary = {
|
|
160
|
+
totalPosts: normalizedPosts.length,
|
|
161
|
+
dateRange: {
|
|
162
|
+
earliest: normalizedPosts.length > 0 ? normalizedPosts[normalizedPosts.length - 1].publishedAt : null,
|
|
163
|
+
latest: normalizedPosts.length > 0 ? normalizedPosts[0].publishedAt : null,
|
|
164
|
+
},
|
|
165
|
+
postTypes: this.categorizePostTypes(allPosts),
|
|
166
|
+
totalEngagements: normalizedPosts.reduce((sum, post) => sum + (post.analytics?.engagements || 0), 0),
|
|
167
|
+
totalImpressions: normalizedPosts.reduce((sum, post) => sum + (post.analytics?.impressions || 0), 0),
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// Update output parameters
|
|
171
|
+
const outputParams = [...Params];
|
|
172
|
+
// TODO: Set output parameters based on result
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
Success: true,
|
|
176
|
+
Message: `Successfully retrieved ${normalizedPosts.length} posts`,
|
|
177
|
+
ResultCode: 'SUCCESS',
|
|
178
|
+
Params: outputParams,
|
|
179
|
+
};
|
|
180
|
+
} catch (error) {
|
|
181
|
+
LogError(`Failed to get Facebook page posts: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
182
|
+
|
|
183
|
+
if (this.isAuthError(error)) {
|
|
184
|
+
return this.handleOAuthError(error);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
Success: false,
|
|
189
|
+
Message: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
190
|
+
ResultCode: 'ERROR',
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Get post fields without insights (for faster queries or when insights not available)
|
|
197
|
+
*/
|
|
198
|
+
private getPostFieldsWithoutInsights(): string {
|
|
199
|
+
return 'id,message,created_time,updated_time,from,story,permalink_url,attachments,shares,reactions.summary(true),comments.summary(true)';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Categorize posts by type based on attachments
|
|
204
|
+
*/
|
|
205
|
+
private categorizePostTypes(posts: any[]): Record<string, number> {
|
|
206
|
+
const types: Record<string, number> = {
|
|
207
|
+
status: 0,
|
|
208
|
+
photo: 0,
|
|
209
|
+
video: 0,
|
|
210
|
+
link: 0,
|
|
211
|
+
event: 0,
|
|
212
|
+
offer: 0,
|
|
213
|
+
album: 0,
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
for (const post of posts) {
|
|
217
|
+
if (post.attachments?.data?.[0]?.type) {
|
|
218
|
+
const type = post.attachments.data[0].type.toLowerCase();
|
|
219
|
+
if (type in types) {
|
|
220
|
+
types[type]++;
|
|
221
|
+
} else {
|
|
222
|
+
types.status++;
|
|
236
223
|
}
|
|
237
|
-
|
|
238
|
-
|
|
224
|
+
} else {
|
|
225
|
+
types.status++;
|
|
226
|
+
}
|
|
239
227
|
}
|
|
240
228
|
|
|
241
|
-
|
|
242
|
-
}
|
|
229
|
+
return types;
|
|
230
|
+
}
|
|
231
|
+
}
|