UNPKG

@memberjunction/actions-bizapps-social

Version:

Social Media Actions for MemberJunction - Twitter, LinkedIn, Facebook, Instagram, TikTok, YouTube, HootSuite, Buffer

227 lines 9.67 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateVideoPostAction = void 0; const global_1 = require("@memberjunction/global"); const tiktok_base_action_1 = require("../tiktok-base.action"); const actions_1 = require("@memberjunction/actions"); /** * Action to create a video post on TikTok * Note: This requires special API approval from TikTok */ let CreateVideoPostAction = class CreateVideoPostAction extends tiktok_base_action_1.TikTokBaseAction { /** * Create a video post on TikTok */ async InternalRunAction(params) { const { Params } = params; try { // Initialize OAuth const companyIntegrationId = this.getParamValue(Params, 'CompanyIntegrationID'); if (!companyIntegrationId) { throw new Error('CompanyIntegrationID is required'); } await this.initializeOAuth(companyIntegrationId); // Extract parameters const videoUrl = this.getParamValue(Params, 'VideoURL'); const title = this.getParamValue(Params, 'Title'); const description = this.getParamValue(Params, 'Description'); const hashtags = this.getParamValue(Params, 'Hashtags') || []; const privacyLevel = this.getParamValue(Params, 'PrivacyLevel') || 'PUBLIC'; const allowComments = this.getParamValue(Params, 'AllowComments') !== false; const allowDuet = this.getParamValue(Params, 'AllowDuet') !== false; const allowStitch = this.getParamValue(Params, 'AllowStitch') !== false; const scheduleTime = this.getParamValue(Params, 'ScheduleTime'); // Validate required parameters if (!videoUrl && !this.getParamValue(Params, 'VideoFile')) { throw new Error('Either VideoURL or VideoFile is required'); } // Build description with hashtags const hashtagString = hashtags.map((tag) => tag.startsWith('#') ? tag : `#${tag}`).join(' '); const fullDescription = description ? `${description} ${hashtagString}`.trim() : hashtagString; // Check if we have video upload approval const hasUploadApproval = this.getCustomAttribute(3) === 'approved'; if (!hasUploadApproval) { // Return informative message about TikTok limitations const alternativeSteps = { manualProcess: [ '1. Download the TikTok mobile app', '2. Log in to your TikTok account', '3. Tap the + button to create a new video', '4. Upload your video or record a new one', `5. Add title: "${title || 'Your video title'}"`, `6. Add description: "${fullDescription}"`, '7. Set privacy and interaction settings', '8. Post immediately or save as draft' ], businessSolution: 'For automated posting, apply for TikTok Marketing API access at https://ads.tiktok.com/marketing_api/', thirdPartyTools: [ 'TikTok Creator Studio (web interface)', 'Buffer (with TikTok integration)', 'Hootsuite (business plans)' ] }; // Update output parameters with alternative instructions const outputParams = [...Params]; const postIdParam = outputParams.find(p => p.Name === 'PostID'); if (postIdParam) postIdParam.Value = null; const postUrlParam = outputParams.find(p => p.Name === 'PostURL'); if (postUrlParam) postUrlParam.Value = null; const alternativesParam = outputParams.find(p => p.Name === 'Alternatives'); if (alternativesParam) alternativesParam.Value = alternativeSteps; return { Success: false, ResultCode: 'API_LIMITATION', Message: 'TikTok video upload requires special API approval. See Alternatives output for manual posting instructions.', Params: outputParams }; } // If we have approval, attempt to create the post // This is the theoretical implementation if approval is granted const createPostData = { video_url: videoUrl, title: title, description: fullDescription, privacy_level: privacyLevel, allow_comments: allowComments, allow_duet: allowDuet, allow_stitch: allowStitch, scheduled_publish_time: scheduleTime ? new Date(scheduleTime).toISOString() : undefined }; const response = await this.makeTikTokRequest('/v2/video/upload/', 'POST', createPostData); const postData = response.data; // Update output parameters const outputParams = [...Params]; const postIdParam = outputParams.find(p => p.Name === 'PostID'); if (postIdParam) postIdParam.Value = postData.video_id; const postUrlParam = outputParams.find(p => p.Name === 'PostURL'); if (postUrlParam) postUrlParam.Value = postData.share_url; const statusParam = outputParams.find(p => p.Name === 'Status'); if (statusParam) statusParam.Value = postData.status; return { Success: true, ResultCode: 'SUCCESS', Message: `Successfully created TikTok video post: ${postData.video_id}`, Params: outputParams }; } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; // Check for specific TikTok error codes if (errorMessage.includes('insufficient_permissions')) { return { Success: false, ResultCode: 'INSUFFICIENT_PERMISSIONS', Message: 'This action requires TikTok Marketing API approval. Contact TikTok for Business.', Params }; } return { Success: false, ResultCode: this.isAuthError(error) ? 'INVALID_TOKEN' : 'ERROR', Message: `Failed to create TikTok video post: ${errorMessage}`, Params }; } } /** * Define the parameters this action expects */ get Params() { return [ ...this.commonSocialParams, { Name: 'VideoURL', Type: 'Input', Value: null }, { Name: 'VideoFile', Type: 'Input', Value: null }, { Name: 'Title', Type: 'Input', Value: null }, { Name: 'Description', Type: 'Input', Value: null }, { Name: 'Hashtags', Type: 'Input', Value: [] }, { Name: 'PrivacyLevel', Type: 'Input', Value: 'PUBLIC' }, { Name: 'AllowComments', Type: 'Input', Value: true }, { Name: 'AllowDuet', Type: 'Input', Value: true }, { Name: 'AllowStitch', Type: 'Input', Value: true }, { Name: 'ScheduleTime', Type: 'Input', Value: null }, { Name: 'PostID', Type: 'Output', Value: null }, { Name: 'PostURL', Type: 'Output', Value: null }, { Name: 'Status', Type: 'Output', Value: null }, { Name: 'Alternatives', Type: 'Output', Value: null } ]; } /** * Metadata about this action */ get Description() { return 'Creates a video post on TikTok (requires special API approval from TikTok)'; } }; exports.CreateVideoPostAction = CreateVideoPostAction; exports.CreateVideoPostAction = CreateVideoPostAction = __decorate([ (0, global_1.RegisterClass)(actions_1.BaseAction, 'CreateVideoPostAction') ], CreateVideoPostAction); //# sourceMappingURL=create-video-post.action.js.map