@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.
Files changed (204) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +13 -0
  3. package/dist/base/base-social.action.d.ts.map +1 -1
  4. package/dist/base/base-social.action.js +24 -18
  5. package/dist/base/base-social.action.js.map +1 -1
  6. package/dist/providers/buffer/buffer-base.action.d.ts.map +1 -1
  7. package/dist/providers/buffer/buffer-base.action.js +34 -35
  8. package/dist/providers/buffer/buffer-base.action.js.map +1 -1
  9. package/dist/providers/facebook/actions/boost-post.action.d.ts.map +1 -1
  10. package/dist/providers/facebook/actions/boost-post.action.js +33 -33
  11. package/dist/providers/facebook/actions/boost-post.action.js.map +1 -1
  12. package/dist/providers/facebook/actions/create-album.action.d.ts.map +1 -1
  13. package/dist/providers/facebook/actions/create-album.action.js +36 -34
  14. package/dist/providers/facebook/actions/create-album.action.js.map +1 -1
  15. package/dist/providers/facebook/actions/create-post.action.d.ts.map +1 -1
  16. package/dist/providers/facebook/actions/create-post.action.js +20 -20
  17. package/dist/providers/facebook/actions/create-post.action.js.map +1 -1
  18. package/dist/providers/facebook/actions/get-page-insights.action.d.ts.map +1 -1
  19. package/dist/providers/facebook/actions/get-page-insights.action.js +27 -25
  20. package/dist/providers/facebook/actions/get-page-insights.action.js.map +1 -1
  21. package/dist/providers/facebook/actions/get-page-posts.action.d.ts.map +1 -1
  22. package/dist/providers/facebook/actions/get-page-posts.action.js +23 -19
  23. package/dist/providers/facebook/actions/get-page-posts.action.js.map +1 -1
  24. package/dist/providers/facebook/actions/get-post-insights.action.d.ts.map +1 -1
  25. package/dist/providers/facebook/actions/get-post-insights.action.js +32 -28
  26. package/dist/providers/facebook/actions/get-post-insights.action.js.map +1 -1
  27. package/dist/providers/facebook/actions/respond-to-comments.action.d.ts.map +1 -1
  28. package/dist/providers/facebook/actions/respond-to-comments.action.js +44 -42
  29. package/dist/providers/facebook/actions/respond-to-comments.action.js.map +1 -1
  30. package/dist/providers/facebook/actions/schedule-post.action.d.ts.map +1 -1
  31. package/dist/providers/facebook/actions/schedule-post.action.js +29 -29
  32. package/dist/providers/facebook/actions/schedule-post.action.js.map +1 -1
  33. package/dist/providers/facebook/actions/search-posts.action.d.ts.map +1 -1
  34. package/dist/providers/facebook/actions/search-posts.action.js +39 -37
  35. package/dist/providers/facebook/actions/search-posts.action.js.map +1 -1
  36. package/dist/providers/facebook/facebook-base.action.d.ts.map +1 -1
  37. package/dist/providers/facebook/facebook-base.action.js +59 -44
  38. package/dist/providers/facebook/facebook-base.action.js.map +1 -1
  39. package/dist/providers/hootsuite/actions/bulk-schedule-posts.action.d.ts.map +1 -1
  40. package/dist/providers/hootsuite/actions/bulk-schedule-posts.action.js +31 -33
  41. package/dist/providers/hootsuite/actions/bulk-schedule-posts.action.js.map +1 -1
  42. package/dist/providers/hootsuite/actions/create-scheduled-post.action.d.ts.map +1 -1
  43. package/dist/providers/hootsuite/actions/create-scheduled-post.action.js +32 -28
  44. package/dist/providers/hootsuite/actions/create-scheduled-post.action.js.map +1 -1
  45. package/dist/providers/hootsuite/actions/delete-scheduled-post.action.d.ts.map +1 -1
  46. package/dist/providers/hootsuite/actions/delete-scheduled-post.action.js +19 -19
  47. package/dist/providers/hootsuite/actions/delete-scheduled-post.action.js.map +1 -1
  48. package/dist/providers/hootsuite/actions/get-analytics.action.d.ts.map +1 -1
  49. package/dist/providers/hootsuite/actions/get-analytics.action.js +26 -24
  50. package/dist/providers/hootsuite/actions/get-analytics.action.js.map +1 -1
  51. package/dist/providers/hootsuite/actions/get-scheduled-posts.action.d.ts.map +1 -1
  52. package/dist/providers/hootsuite/actions/get-scheduled-posts.action.js +22 -22
  53. package/dist/providers/hootsuite/actions/get-scheduled-posts.action.js.map +1 -1
  54. package/dist/providers/hootsuite/actions/get-social-profiles.action.d.ts.map +1 -1
  55. package/dist/providers/hootsuite/actions/get-social-profiles.action.js +34 -32
  56. package/dist/providers/hootsuite/actions/get-social-profiles.action.js.map +1 -1
  57. package/dist/providers/hootsuite/actions/search-posts.action.d.ts.map +1 -1
  58. package/dist/providers/hootsuite/actions/search-posts.action.js +52 -43
  59. package/dist/providers/hootsuite/actions/search-posts.action.js.map +1 -1
  60. package/dist/providers/hootsuite/actions/update-scheduled-post.action.d.ts.map +1 -1
  61. package/dist/providers/hootsuite/actions/update-scheduled-post.action.js +28 -30
  62. package/dist/providers/hootsuite/actions/update-scheduled-post.action.js.map +1 -1
  63. package/dist/providers/hootsuite/hootsuite-base.action.d.ts.map +1 -1
  64. package/dist/providers/hootsuite/hootsuite-base.action.js +20 -18
  65. package/dist/providers/hootsuite/hootsuite-base.action.js.map +1 -1
  66. package/dist/providers/instagram/actions/create-post.action.d.ts.map +1 -1
  67. package/dist/providers/instagram/actions/create-post.action.js +26 -27
  68. package/dist/providers/instagram/actions/create-post.action.js.map +1 -1
  69. package/dist/providers/instagram/actions/create-story.action.d.ts.map +1 -1
  70. package/dist/providers/instagram/actions/create-story.action.js +35 -35
  71. package/dist/providers/instagram/actions/create-story.action.js.map +1 -1
  72. package/dist/providers/instagram/actions/get-account-insights.action.d.ts.map +1 -1
  73. package/dist/providers/instagram/actions/get-account-insights.action.js +59 -38
  74. package/dist/providers/instagram/actions/get-account-insights.action.js.map +1 -1
  75. package/dist/providers/instagram/actions/get-business-posts.action.d.ts.map +1 -1
  76. package/dist/providers/instagram/actions/get-business-posts.action.js +29 -29
  77. package/dist/providers/instagram/actions/get-business-posts.action.js.map +1 -1
  78. package/dist/providers/instagram/actions/get-comments.action.d.ts.map +1 -1
  79. package/dist/providers/instagram/actions/get-comments.action.js +36 -36
  80. package/dist/providers/instagram/actions/get-comments.action.js.map +1 -1
  81. package/dist/providers/instagram/actions/get-post-insights.action.d.ts.map +1 -1
  82. package/dist/providers/instagram/actions/get-post-insights.action.js +25 -23
  83. package/dist/providers/instagram/actions/get-post-insights.action.js.map +1 -1
  84. package/dist/providers/instagram/actions/schedule-post.action.d.ts.map +1 -1
  85. package/dist/providers/instagram/actions/schedule-post.action.js +25 -25
  86. package/dist/providers/instagram/actions/schedule-post.action.js.map +1 -1
  87. package/dist/providers/instagram/actions/search-posts.action.d.ts.map +1 -1
  88. package/dist/providers/instagram/actions/search-posts.action.js +60 -56
  89. package/dist/providers/instagram/actions/search-posts.action.js.map +1 -1
  90. package/dist/providers/instagram/instagram-base.action.d.ts.map +1 -1
  91. package/dist/providers/instagram/instagram-base.action.js +27 -25
  92. package/dist/providers/instagram/instagram-base.action.js.map +1 -1
  93. package/dist/providers/linkedin/actions/create-article.action.d.ts.map +1 -1
  94. package/dist/providers/linkedin/actions/create-article.action.js +45 -55
  95. package/dist/providers/linkedin/actions/create-article.action.js.map +1 -1
  96. package/dist/providers/linkedin/actions/create-post.action.d.ts.map +1 -1
  97. package/dist/providers/linkedin/actions/create-post.action.js +29 -31
  98. package/dist/providers/linkedin/actions/create-post.action.js.map +1 -1
  99. package/dist/providers/linkedin/actions/get-followers.action.d.ts.map +1 -1
  100. package/dist/providers/linkedin/actions/get-followers.action.js +28 -28
  101. package/dist/providers/linkedin/actions/get-followers.action.js.map +1 -1
  102. package/dist/providers/linkedin/actions/get-organization-posts.action.d.ts.map +1 -1
  103. package/dist/providers/linkedin/actions/get-organization-posts.action.js +20 -20
  104. package/dist/providers/linkedin/actions/get-organization-posts.action.js.map +1 -1
  105. package/dist/providers/linkedin/actions/get-personal-posts.action.d.ts.map +1 -1
  106. package/dist/providers/linkedin/actions/get-personal-posts.action.js +19 -19
  107. package/dist/providers/linkedin/actions/get-personal-posts.action.js.map +1 -1
  108. package/dist/providers/linkedin/actions/get-post-analytics.action.d.ts.map +1 -1
  109. package/dist/providers/linkedin/actions/get-post-analytics.action.js +23 -25
  110. package/dist/providers/linkedin/actions/get-post-analytics.action.js.map +1 -1
  111. package/dist/providers/linkedin/actions/schedule-post.action.d.ts.map +1 -1
  112. package/dist/providers/linkedin/actions/schedule-post.action.js +30 -32
  113. package/dist/providers/linkedin/actions/schedule-post.action.js.map +1 -1
  114. package/dist/providers/linkedin/actions/search-posts.action.d.ts.map +1 -1
  115. package/dist/providers/linkedin/actions/search-posts.action.js +30 -28
  116. package/dist/providers/linkedin/actions/search-posts.action.js.map +1 -1
  117. package/dist/providers/linkedin/linkedin-base.action.d.ts.map +1 -1
  118. package/dist/providers/linkedin/linkedin-base.action.js +38 -33
  119. package/dist/providers/linkedin/linkedin-base.action.js.map +1 -1
  120. package/dist/providers/tiktok/tiktok-base.action.d.ts.map +1 -1
  121. package/dist/providers/tiktok/tiktok-base.action.js +26 -25
  122. package/dist/providers/tiktok/tiktok-base.action.js.map +1 -1
  123. package/dist/providers/twitter/actions/create-thread.action.d.ts.map +1 -1
  124. package/dist/providers/twitter/actions/create-thread.action.js +29 -25
  125. package/dist/providers/twitter/actions/create-thread.action.js.map +1 -1
  126. package/dist/providers/twitter/actions/create-tweet.action.d.ts.map +1 -1
  127. package/dist/providers/twitter/actions/create-tweet.action.js +23 -23
  128. package/dist/providers/twitter/actions/create-tweet.action.js.map +1 -1
  129. package/dist/providers/twitter/actions/delete-tweet.action.d.ts.map +1 -1
  130. package/dist/providers/twitter/actions/delete-tweet.action.js +19 -19
  131. package/dist/providers/twitter/actions/delete-tweet.action.js.map +1 -1
  132. package/dist/providers/twitter/actions/get-analytics.action.d.ts.map +1 -1
  133. package/dist/providers/twitter/actions/get-analytics.action.js +47 -40
  134. package/dist/providers/twitter/actions/get-analytics.action.js.map +1 -1
  135. package/dist/providers/twitter/actions/get-mentions.action.d.ts.map +1 -1
  136. package/dist/providers/twitter/actions/get-mentions.action.js +31 -30
  137. package/dist/providers/twitter/actions/get-mentions.action.js.map +1 -1
  138. package/dist/providers/twitter/actions/get-timeline.action.d.ts.map +1 -1
  139. package/dist/providers/twitter/actions/get-timeline.action.js +29 -29
  140. package/dist/providers/twitter/actions/get-timeline.action.js.map +1 -1
  141. package/dist/providers/twitter/actions/schedule-tweet.action.d.ts.map +1 -1
  142. package/dist/providers/twitter/actions/schedule-tweet.action.js +26 -26
  143. package/dist/providers/twitter/actions/schedule-tweet.action.js.map +1 -1
  144. package/dist/providers/twitter/actions/search-tweets.action.d.ts.map +1 -1
  145. package/dist/providers/twitter/actions/search-tweets.action.js +58 -56
  146. package/dist/providers/twitter/actions/search-tweets.action.js.map +1 -1
  147. package/dist/providers/twitter/twitter-base.action.d.ts.map +1 -1
  148. package/dist/providers/twitter/twitter-base.action.js +68 -58
  149. package/dist/providers/twitter/twitter-base.action.js.map +1 -1
  150. package/dist/providers/youtube/youtube-base.action.d.ts +1 -1
  151. package/dist/providers/youtube/youtube-base.action.d.ts.map +1 -1
  152. package/dist/providers/youtube/youtube-base.action.js +25 -22
  153. package/dist/providers/youtube/youtube-base.action.js.map +1 -1
  154. package/package.json +6 -5
  155. package/src/base/base-social.action.ts +224 -217
  156. package/src/providers/buffer/buffer-base.action.ts +441 -435
  157. package/src/providers/facebook/actions/boost-post.action.ts +386 -350
  158. package/src/providers/facebook/actions/create-album.action.ts +307 -291
  159. package/src/providers/facebook/actions/create-post.action.ts +227 -224
  160. package/src/providers/facebook/actions/get-page-insights.action.ts +403 -383
  161. package/src/providers/facebook/actions/get-page-posts.action.ts +225 -214
  162. package/src/providers/facebook/actions/get-post-insights.action.ts +316 -300
  163. package/src/providers/facebook/actions/respond-to-comments.action.ts +336 -319
  164. package/src/providers/facebook/actions/schedule-post.action.ts +292 -289
  165. package/src/providers/facebook/actions/search-posts.action.ts +413 -399
  166. package/src/providers/facebook/facebook-base.action.ts +670 -653
  167. package/src/providers/hootsuite/actions/bulk-schedule-posts.action.ts +257 -257
  168. package/src/providers/hootsuite/actions/create-scheduled-post.action.ts +189 -184
  169. package/src/providers/hootsuite/actions/delete-scheduled-post.action.ts +161 -160
  170. package/src/providers/hootsuite/actions/get-analytics.action.ts +254 -249
  171. package/src/providers/hootsuite/actions/get-scheduled-posts.action.ts +207 -206
  172. package/src/providers/hootsuite/actions/get-social-profiles.action.ts +205 -206
  173. package/src/providers/hootsuite/actions/search-posts.action.ts +369 -351
  174. package/src/providers/hootsuite/actions/update-scheduled-post.action.ts +209 -211
  175. package/src/providers/hootsuite/hootsuite-base.action.ts +307 -301
  176. package/src/providers/instagram/actions/create-post.action.ts +296 -276
  177. package/src/providers/instagram/actions/create-story.action.ts +394 -378
  178. package/src/providers/instagram/actions/get-account-insights.action.ts +420 -384
  179. package/src/providers/instagram/actions/get-business-posts.action.ts +242 -233
  180. package/src/providers/instagram/actions/get-comments.action.ts +377 -365
  181. package/src/providers/instagram/actions/get-post-insights.action.ts +273 -265
  182. package/src/providers/instagram/actions/schedule-post.action.ts +235 -233
  183. package/src/providers/instagram/actions/search-posts.action.ts +538 -512
  184. package/src/providers/instagram/instagram-base.action.ts +393 -368
  185. package/src/providers/linkedin/actions/create-article.action.ts +266 -275
  186. package/src/providers/linkedin/actions/create-post.action.ts +177 -179
  187. package/src/providers/linkedin/actions/get-followers.action.ts +211 -211
  188. package/src/providers/linkedin/actions/get-organization-posts.action.ts +147 -146
  189. package/src/providers/linkedin/actions/get-personal-posts.action.ts +139 -138
  190. package/src/providers/linkedin/actions/get-post-analytics.action.ts +189 -190
  191. package/src/providers/linkedin/actions/schedule-post.action.ts +189 -191
  192. package/src/providers/linkedin/actions/search-posts.action.ts +283 -275
  193. package/src/providers/linkedin/linkedin-base.action.ts +421 -407
  194. package/src/providers/tiktok/tiktok-base.action.ts +320 -305
  195. package/src/providers/twitter/actions/create-thread.action.ts +207 -203
  196. package/src/providers/twitter/actions/create-tweet.action.ts +188 -187
  197. package/src/providers/twitter/actions/delete-tweet.action.ts +129 -128
  198. package/src/providers/twitter/actions/get-analytics.action.ts +411 -402
  199. package/src/providers/twitter/actions/get-mentions.action.ts +219 -218
  200. package/src/providers/twitter/actions/get-timeline.action.ts +233 -232
  201. package/src/providers/twitter/actions/schedule-tweet.action.ts +222 -221
  202. package/src/providers/twitter/actions/search-tweets.action.ts +543 -540
  203. package/src/providers/twitter/twitter-base.action.ts +560 -541
  204. 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/global';
4
+ import { LogError } from '@memberjunction/core';
5
5
  import { BaseAction } from '@memberjunction/actions';
6
6
 
7
7
  /**
@@ -12,236 +12,238 @@ import { BaseAction } from '@memberjunction/actions';
12
12
  */
13
13
  @RegisterClass(BaseAction, 'Instagram - Schedule Post')
14
14
  export class InstagramSchedulePostAction extends InstagramBaseAction {
15
- protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
16
- try {
17
- const companyIntegrationId = this.getParamValue(params.Params, 'CompanyIntegrationID');
18
- const content = this.getParamValue(params.Params, 'Content');
19
- const mediaUrls = this.getParamValue(params.Params, 'MediaUrls') as string[];
20
- const scheduledTime = this.getParamValue(params.Params, 'ScheduledTime');
21
- const postType = this.getParamValue(params.Params, 'PostType') || 'FEED';
22
- const locationId = this.getParamValue(params.Params, 'LocationID');
23
- const taggedUsers = this.getParamValue(params.Params, 'TaggedUsers') as string[];
24
- const firstComment = this.getParamValue(params.Params, 'FirstComment');
25
-
26
- // Initialize OAuth
27
- if (!(await this.initializeOAuth(companyIntegrationId))) {
28
- return {
29
- Success: false,
30
- Message: 'Failed to initialize Instagram authentication',
31
- ResultCode: 'AUTH_FAILED',
32
- };
33
- }
34
-
35
- // Validate inputs
36
- if (!scheduledTime) {
37
- return {
38
- Success: false,
39
- Message: 'ScheduledTime is required',
40
- ResultCode: 'MISSING_PARAMS',
41
- };
42
- }
43
-
44
- if (!mediaUrls || mediaUrls.length === 0) {
45
- return {
46
- Success: false,
47
- Message: 'At least one media URL is required',
48
- ResultCode: 'MISSING_MEDIA',
49
- };
50
- }
51
-
52
- // Validate scheduled time
53
- const scheduleDate = new Date(scheduledTime);
54
- const now = new Date();
55
-
56
- if (scheduleDate <= now) {
57
- return {
58
- Success: false,
59
- Message: 'Scheduled time must be in the future',
60
- ResultCode: 'INVALID_SCHEDULE_TIME',
61
- };
62
- }
63
-
64
- // Instagram requires scheduling at least 10 minutes in the future
65
- const minScheduleTime = new Date(now.getTime() + 10 * 60 * 1000);
66
- if (scheduleDate < minScheduleTime) {
67
- return {
68
- Success: false,
69
- Message: 'Posts must be scheduled at least 10 minutes in the future',
70
- ResultCode: 'SCHEDULE_TOO_SOON',
71
- };
72
- }
73
-
74
- // Instagram limits scheduling to 75 days in the future
75
- const maxScheduleTime = new Date(now.getTime() + 75 * 24 * 60 * 60 * 1000);
76
- if (scheduleDate > maxScheduleTime) {
77
- return {
78
- Success: false,
79
- Message: 'Posts cannot be scheduled more than 75 days in the future',
80
- ResultCode: 'SCHEDULE_TOO_FAR',
81
- };
82
- }
83
-
84
- // Create scheduling payload
85
- const schedulingData = {
86
- content,
87
- mediaUrls,
88
- scheduledTime: scheduleDate.toISOString(),
89
- postType,
90
- locationId,
91
- taggedUsers,
92
- firstComment,
93
- accountId: this.instagramBusinessAccountId,
94
- pageId: this.facebookPageId,
95
- };
96
-
97
- // Instagram doesn't have a direct scheduling API endpoint
98
- // Instead, we need to use Facebook's Content Publishing API
99
- // or integrate with Creator Studio
100
-
101
- // For now, we'll store the scheduling data and return instructions
102
- const schedulingId = this.generateSchedulingId();
103
-
104
- // In a production environment, you would:
105
- // 1. Store this in a database
106
- // 2. Set up a cron job or scheduler to publish at the scheduled time
107
- // 3. Or integrate with Facebook Creator Studio API
108
-
109
- // Store scheduling data (this is a placeholder - implement your storage solution)
110
- await this.storeSchedulingData(schedulingId, schedulingData);
111
-
112
- // Store result in output params
113
- const outputParams = [...params.Params];
114
- outputParams.push({
115
- Name: 'ResultData',
116
- Type: 'Output',
117
- Value: JSON.stringify({
118
- schedulingId,
119
- scheduledTime: scheduleDate.toISOString(),
120
- postType,
121
- mediaCount: mediaUrls.length,
122
- instructions: {
123
- creatorStudio: 'This post can be managed in Facebook Creator Studio',
124
- api: 'Use the scheduling ID to retrieve and publish this post at the scheduled time',
125
- webhook: "Set up a webhook to be notified when it's time to publish",
126
- },
127
- schedulingData,
128
- }),
129
- });
130
-
131
- return {
132
- Success: true,
133
- Message: 'Instagram post scheduled successfully',
134
- ResultCode: 'SUCCESS',
135
- Params: outputParams,
136
- };
137
- } catch (error: any) {
138
- LogError('Failed to schedule Instagram post', error);
139
-
140
- if (error.code === 'RATE_LIMIT') {
141
- return {
142
- Success: false,
143
- Message: 'Instagram API rate limit exceeded. Please try again later.',
144
- ResultCode: 'RATE_LIMIT',
145
- };
146
- }
147
-
148
- return {
149
- Success: false,
150
- Message: `Failed to schedule post: ${error.message}`,
151
- ResultCode: 'ERROR',
152
- };
15
+
16
+ protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
17
+ try {
18
+ const companyIntegrationId = this.getParamValue(params.Params, 'CompanyIntegrationID');
19
+ const content = this.getParamValue(params.Params, 'Content');
20
+ const mediaUrls = this.getParamValue(params.Params, 'MediaUrls') as string[];
21
+ const scheduledTime = this.getParamValue(params.Params, 'ScheduledTime');
22
+ const postType = this.getParamValue(params.Params, 'PostType') || 'FEED';
23
+ const locationId = this.getParamValue(params.Params, 'LocationID');
24
+ const taggedUsers = this.getParamValue(params.Params, 'TaggedUsers') as string[];
25
+ const firstComment = this.getParamValue(params.Params, 'FirstComment');
26
+
27
+ // Initialize OAuth
28
+ if (!await this.initializeOAuth(companyIntegrationId)) {
29
+ return {
30
+ Success: false,
31
+ Message: 'Failed to initialize Instagram authentication',
32
+ ResultCode: 'AUTH_FAILED'
33
+ };
34
+ }
35
+
36
+ // Validate inputs
37
+ if (!scheduledTime) {
38
+ return {
39
+ Success: false,
40
+ Message: 'ScheduledTime is required',
41
+ ResultCode: 'MISSING_PARAMS'
42
+ };
43
+ }
44
+
45
+ if (!mediaUrls || mediaUrls.length === 0) {
46
+ return {
47
+ Success: false,
48
+ Message: 'At least one media URL is required',
49
+ ResultCode: 'MISSING_MEDIA'
50
+ };
51
+ }
52
+
53
+ // Validate scheduled time
54
+ const scheduleDate = new Date(scheduledTime);
55
+ const now = new Date();
56
+
57
+ if (scheduleDate <= now) {
58
+ return {
59
+ Success: false,
60
+ Message: 'Scheduled time must be in the future',
61
+ ResultCode: 'INVALID_SCHEDULE_TIME'
62
+ };
63
+ }
64
+
65
+ // Instagram requires scheduling at least 10 minutes in the future
66
+ const minScheduleTime = new Date(now.getTime() + 10 * 60 * 1000);
67
+ if (scheduleDate < minScheduleTime) {
68
+ return {
69
+ Success: false,
70
+ Message: 'Posts must be scheduled at least 10 minutes in the future',
71
+ ResultCode: 'SCHEDULE_TOO_SOON'
72
+ };
73
+ }
74
+
75
+ // Instagram limits scheduling to 75 days in the future
76
+ const maxScheduleTime = new Date(now.getTime() + 75 * 24 * 60 * 60 * 1000);
77
+ if (scheduleDate > maxScheduleTime) {
78
+ return {
79
+ Success: false,
80
+ Message: 'Posts cannot be scheduled more than 75 days in the future',
81
+ ResultCode: 'SCHEDULE_TOO_FAR'
82
+ };
83
+ }
84
+
85
+ // Create scheduling payload
86
+ const schedulingData = {
87
+ content,
88
+ mediaUrls,
89
+ scheduledTime: scheduleDate.toISOString(),
90
+ postType,
91
+ locationId,
92
+ taggedUsers,
93
+ firstComment,
94
+ accountId: this.instagramBusinessAccountId,
95
+ pageId: this.facebookPageId
96
+ };
97
+
98
+ // Instagram doesn't have a direct scheduling API endpoint
99
+ // Instead, we need to use Facebook's Content Publishing API
100
+ // or integrate with Creator Studio
101
+
102
+ // For now, we'll store the scheduling data and return instructions
103
+ const schedulingId = this.generateSchedulingId();
104
+
105
+ // In a production environment, you would:
106
+ // 1. Store this in a database
107
+ // 2. Set up a cron job or scheduler to publish at the scheduled time
108
+ // 3. Or integrate with Facebook Creator Studio API
109
+
110
+ // Store scheduling data (this is a placeholder - implement your storage solution)
111
+ await this.storeSchedulingData(schedulingId, schedulingData);
112
+
113
+ // Store result in output params
114
+ const outputParams = [...params.Params];
115
+ outputParams.push({
116
+ Name: 'ResultData',
117
+ Type: 'Output',
118
+ Value: JSON.stringify({
119
+ schedulingId,
120
+ scheduledTime: scheduleDate.toISOString(),
121
+ postType,
122
+ mediaCount: mediaUrls.length,
123
+ instructions: {
124
+ creatorStudio: 'This post can be managed in Facebook Creator Studio',
125
+ api: 'Use the scheduling ID to retrieve and publish this post at the scheduled time',
126
+ webhook: 'Set up a webhook to be notified when it\'s time to publish'
127
+ },
128
+ schedulingData
129
+ })
130
+ });
131
+
132
+ return {
133
+ Success: true,
134
+ Message: 'Instagram post scheduled successfully',
135
+ ResultCode: 'SUCCESS',
136
+ Params: outputParams
137
+ };
138
+
139
+ } catch (error: any) {
140
+ LogError('Failed to schedule Instagram post', error);
141
+
142
+ if (error.code === 'RATE_LIMIT') {
143
+ return {
144
+ Success: false,
145
+ Message: 'Instagram API rate limit exceeded. Please try again later.',
146
+ ResultCode: 'RATE_LIMIT'
147
+ };
148
+ }
149
+
150
+ return {
151
+ Success: false,
152
+ Message: `Failed to schedule post: ${error.message}`,
153
+ ResultCode: 'ERROR'
154
+ };
155
+ }
153
156
  }
154
- }
155
-
156
- /**
157
- * Generate a unique scheduling ID
158
- */
159
- private generateSchedulingId(): string {
160
- const timestamp = Date.now();
161
- const random = Math.random().toString(36).substring(2, 9);
162
- return `ig_schedule_${timestamp}_${random}`;
163
- }
164
-
165
- /**
166
- * Store scheduling data (placeholder - implement based on your storage solution)
167
- */
168
- private async storeSchedulingData(schedulingId: string, data: any): Promise<void> {
169
- // In a real implementation, this would:
170
- // 1. Store in a database (e.g., in a ScheduledPosts table)
171
- // 2. Set up a scheduled job in your job queue
172
- // 3. Or send to a scheduling service
173
-
174
- // For demonstration, we'll just log it
175
- LogError('Scheduling data would be stored:', schedulingId, data);
176
-
177
- // You could also use MemberJunction entities to store this
178
- // For example, create a "Social Media Scheduled Posts" entity
179
- // and save the scheduling data there
180
- }
181
-
182
- /**
183
- * Create a scheduled post using Facebook Creator Studio API
184
- * Note: This is a conceptual implementation as Creator Studio API
185
- * has specific requirements and approval process
186
- */
187
- private async createCreatorStudioScheduledPost(data: any): Promise<string> {
188
- // This would require:
189
- // 1. Creator Studio API access
190
- // 2. Additional permissions
191
- // 3. Different API endpoints
192
-
193
- // For now, we return a placeholder
194
- throw new Error('Creator Studio integration not implemented. Use the scheduling data to create your own scheduling solution.');
195
- }
196
-
197
- /**
198
- * Define the parameters for this action
199
- */
200
- public get Params(): ActionParam[] {
201
- return [
202
- ...this.commonSocialParams,
203
- {
204
- Name: 'Content',
205
- Type: 'Input',
206
- Value: null,
207
- },
208
- {
209
- Name: 'MediaUrls',
210
- Type: 'Input',
211
- Value: null,
212
- },
213
- {
214
- Name: 'ScheduledTime',
215
- Type: 'Input',
216
- Value: null,
217
- },
218
- {
219
- Name: 'PostType',
220
- Type: 'Input',
221
- Value: 'FEED',
222
- },
223
- {
224
- Name: 'LocationID',
225
- Type: 'Input',
226
- Value: null,
227
- },
228
- {
229
- Name: 'TaggedUsers',
230
- Type: 'Input',
231
- Value: null,
232
- },
233
- {
234
- Name: 'FirstComment',
235
- Type: 'Input',
236
- Value: null,
237
- },
238
- ];
239
- }
240
-
241
- /**
242
- * Get the description for this action
243
- */
244
- public get Description(): string {
245
- return 'Schedules an Instagram post for future publication. Returns scheduling data that can be used with Creator Studio or custom scheduling solutions.';
246
- }
247
- }
157
+
158
+ /**
159
+ * Generate a unique scheduling ID
160
+ */
161
+ private generateSchedulingId(): string {
162
+ const timestamp = Date.now();
163
+ const random = Math.random().toString(36).substring(2, 9);
164
+ return `ig_schedule_${timestamp}_${random}`;
165
+ }
166
+
167
+ /**
168
+ * Store scheduling data (placeholder - implement based on your storage solution)
169
+ */
170
+ private async storeSchedulingData(schedulingId: string, data: any): Promise<void> {
171
+ // In a real implementation, this would:
172
+ // 1. Store in a database (e.g., in a ScheduledPosts table)
173
+ // 2. Set up a scheduled job in your job queue
174
+ // 3. Or send to a scheduling service
175
+
176
+ // For demonstration, we'll just log it
177
+ LogError('Scheduling data would be stored:', schedulingId, data);
178
+
179
+ // You could also use MemberJunction entities to store this
180
+ // For example, create a "Social Media Scheduled Posts" entity
181
+ // and save the scheduling data there
182
+ }
183
+
184
+ /**
185
+ * Create a scheduled post using Facebook Creator Studio API
186
+ * Note: This is a conceptual implementation as Creator Studio API
187
+ * has specific requirements and approval process
188
+ */
189
+ private async createCreatorStudioScheduledPost(data: any): Promise<string> {
190
+ // This would require:
191
+ // 1. Creator Studio API access
192
+ // 2. Additional permissions
193
+ // 3. Different API endpoints
194
+
195
+ // For now, we return a placeholder
196
+ throw new Error('Creator Studio integration not implemented. Use the scheduling data to create your own scheduling solution.');
197
+ }
198
+
199
+ /**
200
+ * Define the parameters for this action
201
+ */
202
+ public get Params(): ActionParam[] {
203
+ return [
204
+ ...this.commonSocialParams,
205
+ {
206
+ Name: 'Content',
207
+ Type: 'Input',
208
+ Value: null
209
+ },
210
+ {
211
+ Name: 'MediaUrls',
212
+ Type: 'Input',
213
+ Value: null
214
+ },
215
+ {
216
+ Name: 'ScheduledTime',
217
+ Type: 'Input',
218
+ Value: null
219
+ },
220
+ {
221
+ Name: 'PostType',
222
+ Type: 'Input',
223
+ Value: 'FEED'
224
+ },
225
+ {
226
+ Name: 'LocationID',
227
+ Type: 'Input',
228
+ Value: null
229
+ },
230
+ {
231
+ Name: 'TaggedUsers',
232
+ Type: 'Input',
233
+ Value: null
234
+ },
235
+ {
236
+ Name: 'FirstComment',
237
+ Type: 'Input',
238
+ Value: null
239
+ }
240
+ ];
241
+ }
242
+
243
+ /**
244
+ * Get the description for this action
245
+ */
246
+ public get Description(): string {
247
+ return 'Schedules an Instagram post for future publication. Returns scheduling data that can be used with Creator Studio or custom scheduling solutions.';
248
+ }
249
+ }