|
| 1 | +import { TikTokIcon } from '@/components/icons' |
| 2 | +import type { BlockConfig } from '@/blocks/types' |
| 3 | +import { AuthMode } from '@/blocks/types' |
| 4 | +import type { TikTokResponse } from '@/tools/tiktok/types' |
| 5 | + |
| 6 | +export const TikTokBlock: BlockConfig<TikTokResponse> = { |
| 7 | + type: 'tiktok', |
| 8 | + name: 'TikTok', |
| 9 | + description: 'Access TikTok user profiles and videos', |
| 10 | + authMode: AuthMode.OAuth, |
| 11 | + longDescription: |
| 12 | + 'Integrate TikTok into your workflow. Get user profile information including follower counts and video statistics. List and query videos with cover images, embed links, and metadata.', |
| 13 | + docsLink: 'https://docs.sim.ai/tools/tiktok', |
| 14 | + category: 'tools', |
| 15 | + bgColor: '#000000', |
| 16 | + icon: TikTokIcon, |
| 17 | + subBlocks: [ |
| 18 | + // Operation selection |
| 19 | + { |
| 20 | + id: 'operation', |
| 21 | + title: 'Operation', |
| 22 | + type: 'dropdown', |
| 23 | + options: [ |
| 24 | + { label: 'Get User Info', id: 'get_user' }, |
| 25 | + { label: 'List Videos', id: 'list_videos' }, |
| 26 | + { label: 'Query Videos', id: 'query_videos' }, |
| 27 | + ], |
| 28 | + value: () => 'get_user', |
| 29 | + }, |
| 30 | + |
| 31 | + // TikTok OAuth Authentication |
| 32 | + { |
| 33 | + id: 'credential', |
| 34 | + title: 'TikTok Account', |
| 35 | + type: 'oauth-input', |
| 36 | + serviceId: 'tiktok', |
| 37 | + placeholder: 'Select TikTok account', |
| 38 | + required: true, |
| 39 | + }, |
| 40 | + |
| 41 | + // Get User Info specific fields |
| 42 | + { |
| 43 | + id: 'fields', |
| 44 | + title: 'Fields', |
| 45 | + type: 'short-input', |
| 46 | + placeholder: 'open_id,display_name,avatar_url,follower_count,video_count', |
| 47 | + condition: { |
| 48 | + field: 'operation', |
| 49 | + value: 'get_user', |
| 50 | + }, |
| 51 | + }, |
| 52 | + |
| 53 | + // List Videos specific fields |
| 54 | + { |
| 55 | + id: 'maxCount', |
| 56 | + title: 'Max Count', |
| 57 | + type: 'short-input', |
| 58 | + placeholder: '20', |
| 59 | + condition: { |
| 60 | + field: 'operation', |
| 61 | + value: 'list_videos', |
| 62 | + }, |
| 63 | + }, |
| 64 | + { |
| 65 | + id: 'cursor', |
| 66 | + title: 'Cursor', |
| 67 | + type: 'short-input', |
| 68 | + placeholder: 'Pagination cursor from previous response', |
| 69 | + condition: { |
| 70 | + field: 'operation', |
| 71 | + value: 'list_videos', |
| 72 | + }, |
| 73 | + }, |
| 74 | + |
| 75 | + // Query Videos specific fields |
| 76 | + { |
| 77 | + id: 'videoIds', |
| 78 | + title: 'Video IDs', |
| 79 | + type: 'long-input', |
| 80 | + placeholder: 'Comma-separated video IDs (e.g., 7077642457847994444,7080217258529732386)', |
| 81 | + condition: { |
| 82 | + field: 'operation', |
| 83 | + value: 'query_videos', |
| 84 | + }, |
| 85 | + required: { |
| 86 | + field: 'operation', |
| 87 | + value: 'query_videos', |
| 88 | + }, |
| 89 | + }, |
| 90 | + ], |
| 91 | + tools: { |
| 92 | + access: ['tiktok_get_user', 'tiktok_list_videos', 'tiktok_query_videos'], |
| 93 | + config: { |
| 94 | + tool: (inputs) => { |
| 95 | + const operation = inputs.operation || 'get_user' |
| 96 | + |
| 97 | + switch (operation) { |
| 98 | + case 'list_videos': |
| 99 | + return 'tiktok_list_videos' |
| 100 | + case 'query_videos': |
| 101 | + return 'tiktok_query_videos' |
| 102 | + default: |
| 103 | + return 'tiktok_get_user' |
| 104 | + } |
| 105 | + }, |
| 106 | + params: (inputs) => { |
| 107 | + const operation = inputs.operation || 'get_user' |
| 108 | + const { credential } = inputs |
| 109 | + |
| 110 | + switch (operation) { |
| 111 | + case 'get_user': |
| 112 | + return { |
| 113 | + accessToken: credential, |
| 114 | + ...(inputs.fields && { fields: inputs.fields }), |
| 115 | + } |
| 116 | + case 'list_videos': |
| 117 | + return { |
| 118 | + accessToken: credential, |
| 119 | + ...(inputs.maxCount && { maxCount: Number(inputs.maxCount) }), |
| 120 | + ...(inputs.cursor && { cursor: Number(inputs.cursor) }), |
| 121 | + } |
| 122 | + case 'query_videos': |
| 123 | + return { |
| 124 | + accessToken: credential, |
| 125 | + videoIds: inputs.videoIds |
| 126 | + ? inputs.videoIds.split(',').map((id: string) => id.trim()) |
| 127 | + : [], |
| 128 | + } |
| 129 | + default: |
| 130 | + return { |
| 131 | + accessToken: credential, |
| 132 | + } |
| 133 | + } |
| 134 | + }, |
| 135 | + }, |
| 136 | + }, |
| 137 | + inputs: { |
| 138 | + operation: { type: 'string', description: 'Operation to perform' }, |
| 139 | + credential: { type: 'string', description: 'TikTok access token' }, |
| 140 | + fields: { type: 'string', description: 'Comma-separated list of user fields to return' }, |
| 141 | + maxCount: { type: 'number', description: 'Maximum number of videos to return (1-20)' }, |
| 142 | + cursor: { type: 'number', description: 'Pagination cursor from previous response' }, |
| 143 | + videoIds: { type: 'string', description: 'Comma-separated list of video IDs to query' }, |
| 144 | + }, |
| 145 | + outputs: { |
| 146 | + // Get User outputs |
| 147 | + openId: { type: 'string', description: 'TikTok user ID' }, |
| 148 | + displayName: { type: 'string', description: 'User display name' }, |
| 149 | + avatarUrl: { type: 'string', description: 'Profile image URL' }, |
| 150 | + bioDescription: { type: 'string', description: 'User bio' }, |
| 151 | + followerCount: { type: 'number', description: 'Number of followers' }, |
| 152 | + followingCount: { type: 'number', description: 'Number of accounts followed' }, |
| 153 | + likesCount: { type: 'number', description: 'Total likes received' }, |
| 154 | + videoCount: { type: 'number', description: 'Total public videos' }, |
| 155 | + isVerified: { type: 'boolean', description: 'Whether account is verified' }, |
| 156 | + // List/Query Videos outputs |
| 157 | + videos: { type: 'json', description: 'Array of video objects' }, |
| 158 | + cursor: { type: 'number', description: 'Cursor for next page' }, |
| 159 | + hasMore: { type: 'boolean', description: 'Whether more videos are available' }, |
| 160 | + }, |
| 161 | +} |
0 commit comments