Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tiktok): add content posting method alternatives (direct post vs upload) #573

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

keiwanmosaddegh
Copy link

@keiwanmosaddegh keiwanmosaddegh commented Jan 23, 2025

What kind of change does this PR introduce?

This PR adds the option to pick between direct post and upload on the TikTok posting API.

Why was this change needed?

The current TikTok provider is based on the Direct Post API. The way to extend this and enable TikTok Draft Uploads is by introducing a new TikTok provider variant.

Checklist:

Put a "X" in the boxes below to indicate you have followed the checklist;

  • I have read the CONTRIBUTING guide.
  • I checked that there were not similar issues or PRs already open for this.
  • This PR fixes just ONE issue (do not include multiple issues or types of change in the same PR) For example, don't try and fix a UI issue and include new dependencies in the same PR.

Summary by CodeRabbit

  • New Features

    • Introduced a selection for TikTok content posting methods, allowing users to choose between direct posting and uploading without posting.
    • Added descriptive guidance above the selection to assist users in understanding their options.
  • Improvements

    • Enhanced TikTok integration by accommodating different content posting strategies based on user selection.

Copy link

vercel bot commented Jan 23, 2025

@keiwanmosaddegh is attempting to deploy a commit to the Listinai Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Jan 23, 2025

Warning

Rate limit exceeded

@keiwanmosaddegh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1df0b98 and 29dfd55.

📒 Files selected for processing (1)
  • apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (7 hunks)

Walkthrough

The changes introduce a new feature for TikTok content posting methods, allowing users to choose between directly posting content or uploading content without posting. This functionality is implemented across multiple files, including the frontend component, data transfer object (DTO), and TikTok integration provider. The modification enables more flexible content management by adding a content_posting_method option that can be set to either 'DIRECT_POST' or 'UPLOAD'.

Changes

File Change Summary
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx Added contentPostingMethod constant, new <Select> element for content posting method selection, and descriptive text above the <Select> in TikTokSettings component.
libraries/nestjs-libraries/src/dtos/posts/providers-settings/tiktok.dto.ts Introduced content_posting_method property with 'DIRECT_POST' or 'UPLOAD' values in TikTokDto class.
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts Modified post method to handle different endpoint URLs and request body based on content posting method, added postingMethod private method.

Sequence Diagram

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant TikTokAPI

    User->>Frontend: Select content posting method
    Frontend->>Backend: Send post request with method
    Backend->>Backend: Determine endpoint based on method
    alt Direct Post
        Backend->>TikTokAPI: Post with post_info
    else Upload Only
        Backend->>TikTokAPI: Upload without post_info
    end
    TikTokAPI-->>Backend: Response
    Backend-->>Frontend: Return result
Loading

Poem

🐰 A TikTok tale of posting might,
Direct or upload, now set just right!
With methods two, the choice is clear,
Rabbit's code brings flexibility near!
Hop along the social media stream,
Where content flows with coding dream! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1)

229-237: Simplify the endpoint selection logic.

The switch statement can be simplified since 'DIRECT_POST' case and default return the same value.

-    const endpoint: string = (() => {
-      switch (firstPost.settings.content_posting_method) {
-        case 'UPLOAD':
-          return '/inbox/video/init/';
-        case 'DIRECT_POST':
-        default:
-          return '/video/init/';
-      }
-    })();
+    const endpoint = firstPost.settings.content_posting_method === 'UPLOAD'
+      ? '/inbox/video/init/'
+      : '/video/init/';
🧰 Tools
🪛 Biome (1.9.4)

[error] 233-233: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc60ed4 and 81eacbe.

📒 Files selected for processing (3)
  • apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (2 hunks)
  • libraries/nestjs-libraries/src/dtos/posts/providers-settings/tiktok.dto.ts (1 hunks)
  • libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts

[error] 233-233: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

🔇 Additional comments (4)
libraries/nestjs-libraries/src/dtos/posts/providers-settings/tiktok.dto.ts (1)

36-38: LGTM! Property is well-defined and properly validated.

The new content_posting_method property is correctly implemented with appropriate validation decorators and type restrictions.

libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1)

251-261: LGTM! Clean conditional request body construction.

The post_info object is correctly included only for DIRECT_POST method, maintaining a clean separation between posting methods.

apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (2)

36-45: LGTM! Well-defined options with clear labels.

The content posting method options are clearly defined with descriptive labels that help users understand the difference between the two posting methods.


140-152: LGTM! Select component is properly integrated.

The Select component is well-implemented with:

  • Clear labeling
  • Proper form registration
  • Sensible default value ('DIRECT_POST')

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1)

221-229: Enhance type safety and simplify switch statement.

The method implementation can be improved for better type safety and readability:

- private postingMethod(method: TikTokDto["content_posting_method"]): string {
-     switch (method) {
-       case 'UPLOAD':
-         return '/inbox/video/init/';
-       case 'DIRECT_POST':
-       default:
-       return '/video/init/';
-   }
- }
+ private postingMethod(method: TikTokDto["content_posting_method"]): string {
+     return method === 'UPLOAD' 
+       ? '/inbox/video/init/' 
+       : '/video/init/';
+ }

The refactor:

  1. Simplifies the logic by using a ternary operator
  2. Removes the redundant case clause flagged by static analysis
🧰 Tools
🪛 Biome (1.9.4)

[error] 225-225: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81eacbe and aa3ffac.

📒 Files selected for processing (1)
  • libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts

[error] 225-225: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

🔇 Additional comments (1)
libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts (1)

242-242: Document posting method behaviors and add validation.

The conditional inclusion of post_info only for 'DIRECT_POST' needs clarification:

  1. Please add JSDoc comments to document the behavioral differences between posting methods:
/**
 * Posts content to TikTok using either direct post or upload method.
 * @param id - The user's ID
 * @param accessToken - The access token
 * @param postDetails - Array of post details where the first item contains posting configuration
 * @param integration - Integration details
 * 
 * @remarks
 * - DIRECT_POST: Includes post_info in the request for immediate publishing
 * - UPLOAD: Excludes post_info to support draft uploads
 */
  1. Consider adding validation to ensure required fields are present based on the posting method:
if (firstPost.settings.content_posting_method === 'DIRECT_POST' && !firstPost.message) {
  throw new Error('Title is required for direct posts');
}
  1. Run this script to verify the API behavior for both posting methods:

Also applies to: 250-260

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (1)

141-142: Fix unescaped single quotes.

Replace the single quotes with their HTML entity equivalents to resolve the ESLint warnings.

-        Choose upload without posting if you want to review and edit your content within TikTok's app before publishing.
-        This gives you access to TikTok's built-in editing tools and lets you make final adjustments before posting.
+        Choose upload without posting if you want to review and edit your content within TikTok&apos;s app before publishing.
+        This gives you access to TikTok&apos;s built-in editing tools and lets you make final adjustments before posting.
🧰 Tools
🪛 eslint

[error] 141-141: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


[error] 142-142: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa3ffac and 1df0b98.

📒 Files selected for processing (1)
  • apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (2 hunks)
🧰 Additional context used
🪛 eslint
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx

[error] 141-141: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


[error] 142-142: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)

🔇 Additional comments (4)
apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx (4)

36-45: LGTM! Well-structured options for content posting methods.

The constant follows the established pattern and provides clear, descriptive labels for each option.


140-143: Great addition of explanatory text!

The explanation effectively addresses why users might choose to upload without posting, providing clear benefits of this option.

🧰 Tools
🪛 eslint

[error] 141-141: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


[error] 142-142: ' can be escaped with &apos;, &lsquo;, &#39;, &rsquo;.

(react/no-unescaped-entities)


144-156: LGTM! Well-implemented Select component.

The component follows the established pattern, properly integrates with form state, and maintains backward compatibility with the default 'DIRECT_POST' value.


146-148: Verify backend handling of the default value.

Ensure that the backend properly handles the default 'DIRECT_POST' value for existing posts and migrations if necessary.

✅ Verification successful

Backend handling of 'DIRECT_POST' value is properly implemented

The backend codebase shows proper type definitions and handling of the 'DIRECT_POST' value:

  • Defined as a valid option in tiktok.dto.ts
  • Actively used in conditional logic in tiktok.provider.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for backend handling of content_posting_method
rg -t ts "content_posting_method.*DIRECT_POST" -g "!*test*"

Length of output: 338


Script:

#!/bin/bash
# Search for migrations or schema definitions related to content_posting_method
rg -t ts "content_posting_method" -g "*migration*" -g "*schema*" -g "*entity*"

Length of output: 78

@keiwanmosaddegh
Copy link
Author

@nevo-david ready for your 👀 when you are!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants