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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ const privacyLevel = [
},
];

const contentPostingMethod = [
{
value: 'DIRECT_POST',
label: 'Post content directly to TikTok',
},
{
value: 'UPLOAD',
label: 'Upload content to TikTok without posting it',
},
];

const yesNo = [
{
value: 'true',
Expand Down Expand Up @@ -109,12 +120,16 @@ const TikTokSettings: FC<{ values?: any }> = (props) => {
const disclose = watch('disclose');
const brand_organic_toggle = watch('brand_organic_toggle');
const brand_content_toggle = watch('brand_content_toggle');
const content_posting_method = watch('content_posting_method');

const isUploadMode = content_posting_method === 'UPLOAD';

return (
<div className="flex flex-col">
<CheckTikTokValidity picture={props?.values?.[0]?.image?.[0]?.path} />
<Select
label="Who can see this video?"
disabled={isUploadMode}
{...register('privacy_level', {
value: 'PUBLIC_TO_EVERYONE',
})}
Expand All @@ -126,26 +141,47 @@ const TikTokSettings: FC<{ values?: any }> = (props) => {
</option>
))}
</Select>
<div className="text-[14px] mb-[10px] text-balance">
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.
</div>
<Select
keiwanmosaddegh marked this conversation as resolved.
Show resolved Hide resolved
label="Content posting method"
disabled={isUploadMode}
{...register('content_posting_method', {
value: 'DIRECT_POST',
})}
>
<option value="">Select</option>
{contentPostingMethod.map((item) => (
<option key={item.value} value={item.value}>
{item.label}
</option>
))}
</Select>
<hr className="mb-[15px] border-tableBorder" />
<div className="text-[14px] mb-[10px]">Allow User To:</div>
<div className="flex gap-[40px]">
<Checkbox
variant="hollow"
label="Duet"
disabled={isUploadMode}
{...register('duet', {
value: false,
})}
/>
<Checkbox
label="Stitch"
variant="hollow"
disabled={isUploadMode}
{...register('stitch', {
value: false,
})}
/>
<Checkbox
label="Comments"
variant="hollow"
disabled={isUploadMode}
{...register('comment', {
value: false,
})}
Expand All @@ -156,6 +192,7 @@ const TikTokSettings: FC<{ values?: any }> = (props) => {
<Checkbox
variant="hollow"
label="Disclose Video Content"
disabled={isUploadMode}
{...register('disclose', {
value: false,
})}
Expand Down Expand Up @@ -183,7 +220,7 @@ const TikTokSettings: FC<{ values?: any }> = (props) => {
</div>
)}
<div className="text-[14px] my-[10px] text-balance">
Turn on to disclose that this video promotes good or services in
Turn on to disclose that this video promotes goods or services in
exchange for something of value. You video could promote yourself, a
third party, or both.
</div>
Expand All @@ -193,6 +230,7 @@ const TikTokSettings: FC<{ values?: any }> = (props) => {
<Checkbox
variant="hollow"
label="Your brand"
disabled={isUploadMode}
{...register('brand_organic_toggle', {
value: false,
})}
Expand All @@ -205,6 +243,7 @@ const TikTokSettings: FC<{ values?: any }> = (props) => {
<Checkbox
variant="hollow"
label="Branded content"
disabled={isUploadMode}
{...register('brand_content_toggle', {
value: false,
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ export class TikTokDto {
@IsIn(['true'])
@IsDefined()
isValidVideo: boolean;

@IsIn(['DIRECT_POST', 'UPLOAD'])
@IsString()
content_posting_method: 'DIRECT_POST' | 'UPLOAD';
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,35 +218,46 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
}
}

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

async post(
id: string,
accessToken: string,
postDetails: PostDetails<TikTokDto>[],
integration: Integration
): Promise<PostResponse[]> {
const [firstPost, ...comments] = postDetails;

const {
data: { publish_id },
} = await (
await this.fetch(
'https://open.tiktokapis.com/v2/post/publish/video/init/',
`https://open.tiktokapis.com/v2/post/publish${this.postingMethod(firstPost.settings.content_posting_method)}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({
post_info: {
title: firstPost.message,
privacy_level: firstPost.settings.privacy_level,
disable_duet: !firstPost.settings.duet,
disable_comment: !firstPost.settings.comment,
disable_stitch: !firstPost.settings.stitch,
brand_content_toggle: firstPost.settings.brand_content_toggle,
brand_organic_toggle: firstPost.settings.brand_organic_toggle,
},
...(firstPost.settings.content_posting_method === 'DIRECT_POST' ? {
post_info: {
title: firstPost.message,
privacy_level: firstPost.settings.privacy_level,
disable_duet: !firstPost.settings.duet,
disable_comment: !firstPost.settings.comment,
disable_stitch: !firstPost.settings.stitch,
brand_content_toggle: firstPost.settings.brand_content_toggle,
brand_organic_toggle: firstPost.settings.brand_organic_toggle,
}
} : {}),
keiwanmosaddegh marked this conversation as resolved.
Show resolved Hide resolved
source_info: {
source: 'PULL_FROM_URL',
video_url: firstPost?.media?.[0]?.url!,
Expand Down