Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion apps/sim/blocks/blocks/x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,23 @@ export const XBlock: BlockConfig<XResponse> = {
serviceId: 'x',
canonicalParamId: 'oauthCredential',
mode: 'basic',
requiredScopes: ['tweet.read', 'tweet.write', 'users.read', 'offline.access'],
requiredScopes: [
'tweet.read',
'tweet.write',
'tweet.moderate.write',
'users.read',
'follows.read',
'follows.write',
'bookmark.read',
'bookmark.write',
'like.read',
'like.write',
'block.read',
'block.write',
'mute.read',
'mute.write',
'offline.access',
],
Comment thread
waleedlatif1 marked this conversation as resolved.
placeholder: 'Select X account',
},
{
Expand Down
18 changes: 17 additions & 1 deletion apps/sim/lib/oauth/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,23 @@ export const OAUTH_PROVIDERS: Record<string, OAuthProviderConfig> = {
providerId: 'x',
icon: xIcon,
baseProviderIcon: xIcon,
scopes: ['tweet.read', 'tweet.write', 'users.read', 'offline.access'],
scopes: [
'tweet.read',
'tweet.write',
'tweet.moderate.write',
'users.read',
'follows.read',
'follows.write',
'bookmark.read',
'bookmark.write',
'like.read',
'like.write',
'block.read',
'block.write',
'mute.read',
'mute.write',
'offline.access',
],
},
},
defaultService: 'x',
Expand Down
63 changes: 62 additions & 1 deletion apps/sim/tools/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,40 @@ import {
wordpressUploadMediaTool,
} from '@/tools/wordpress'
import { workflowExecutorTool } from '@/tools/workflow'
import { xReadTool, xSearchTool, xUserTool, xWriteTool } from '@/tools/x'
import {
xCreateBookmarkTool,
xCreateTweetTool,
xDeleteBookmarkTool,
xDeleteTweetTool,
xGetBlockingTool,
xGetBookmarksTool,
xGetFollowersTool,
xGetFollowingTool,
xGetLikedTweetsTool,
xGetLikingUsersTool,
xGetMeTool,
xGetPersonalizedTrendsTool,
xGetQuoteTweetsTool,
xGetRetweetedByTool,
xGetTrendsByWoeidTool,
xGetTweetsByIdsTool,
xGetUsageTool,
xGetUserMentionsTool,
xGetUserTimelineTool,
xGetUserTweetsTool,
xHideReplyTool,
xManageBlockTool,
xManageFollowTool,
xManageLikeTool,
xManageMuteTool,
xManageRetweetTool,
xReadTool,
xSearchTool,
xSearchTweetsTool,
xSearchUsersTool,
xUserTool,
xWriteTool,
} from '@/tools/x'
import {
youtubeChannelInfoTool,
youtubeChannelPlaylistsTool,
Expand Down Expand Up @@ -2539,6 +2572,34 @@ export const tools: Record<string, ToolConfig> = {
x_read: xReadTool,
x_search: xSearchTool,
x_user: xUserTool,
x_search_tweets: xSearchTweetsTool,
x_get_user_tweets: xGetUserTweetsTool,
x_get_user_mentions: xGetUserMentionsTool,
x_get_user_timeline: xGetUserTimelineTool,
x_get_tweets_by_ids: xGetTweetsByIdsTool,
x_get_bookmarks: xGetBookmarksTool,
x_create_bookmark: xCreateBookmarkTool,
x_delete_bookmark: xDeleteBookmarkTool,
x_create_tweet: xCreateTweetTool,
x_delete_tweet: xDeleteTweetTool,
x_get_me: xGetMeTool,
x_search_users: xSearchUsersTool,
x_get_followers: xGetFollowersTool,
x_get_following: xGetFollowingTool,
x_manage_follow: xManageFollowTool,
x_get_blocking: xGetBlockingTool,
x_manage_block: xManageBlockTool,
x_get_liked_tweets: xGetLikedTweetsTool,
x_get_liking_users: xGetLikingUsersTool,
x_manage_like: xManageLikeTool,
x_manage_retweet: xManageRetweetTool,
x_get_retweeted_by: xGetRetweetedByTool,
x_get_quote_tweets: xGetQuoteTweetsTool,
x_get_trends_by_woeid: xGetTrendsByWoeidTool,
x_get_personalized_trends: xGetPersonalizedTrendsTool,
x_get_usage: xGetUsageTool,
x_hide_reply: xHideReplyTool,
x_manage_mute: xManageMuteTool,
pinecone_fetch: pineconeFetchTool,
pinecone_generate_embeddings: pineconeGenerateEmbeddingsTool,
pinecone_search_text: pineconeSearchTextTool,
Expand Down
64 changes: 64 additions & 0 deletions apps/sim/tools/x/create_bookmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { ToolConfig } from '@/tools/types'
import type { XCreateBookmarkParams, XCreateBookmarkResponse } from '@/tools/x/types'

export const xCreateBookmarkTool: ToolConfig<XCreateBookmarkParams, XCreateBookmarkResponse> = {
id: 'x_create_bookmark',
name: 'X Create Bookmark',
description: 'Bookmark a tweet for the authenticated user',
version: '1.0.0',

oauth: {
required: true,
provider: 'x',
},

params: {
accessToken: {
type: 'string',
required: true,
visibility: 'hidden',
description: 'X OAuth access token',
},
userId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The authenticated user ID',
},
tweetId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The tweet ID to bookmark',
},
},

request: {
url: (params) => `https://api.x.com/2/users/${params.userId.trim()}/bookmarks`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
}),
body: (params) => ({
tweet_id: params.tweetId.trim(),
}),
},

transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
bookmarked: data.data?.bookmarked ?? false,
},
}
},
Comment thread
waleedlatif1 marked this conversation as resolved.

outputs: {
bookmarked: {
type: 'boolean',
description: 'Whether the tweet was successfully bookmarked',
},
},
}
113 changes: 113 additions & 0 deletions apps/sim/tools/x/create_tweet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import type { ToolConfig } from '@/tools/types'
import type { XCreateTweetParams, XCreateTweetResponse } from '@/tools/x/types'

export const xCreateTweetTool: ToolConfig<XCreateTweetParams, XCreateTweetResponse> = {
id: 'x_create_tweet',
name: 'X Create Tweet',
description: 'Create a new tweet, reply, or quote tweet on X',
version: '1.0.0',

oauth: {
required: true,
provider: 'x',
},

params: {
accessToken: {
type: 'string',
required: true,
visibility: 'hidden',
description: 'X OAuth access token',
},
text: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The text content of the tweet (max 280 characters)',
},
replyToTweetId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Tweet ID to reply to',
},
quoteTweetId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Tweet ID to quote',
},
mediaIds: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Comma-separated media IDs to attach (up to 4)',
},
replySettings: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Who can reply: "mentionedUsers", "following", "subscribers", or "verified"',
},
},

request: {
url: 'https://api.x.com/2/tweets',
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
}),
body: (params) => {
const body: Record<string, unknown> = {
text: params.text,
}

if (params.replyToTweetId) {
body.reply = { in_reply_to_tweet_id: params.replyToTweetId.trim() }
}

if (params.quoteTweetId) {
body.quote_tweet_id = params.quoteTweetId.trim()
}

if (params.mediaIds) {
const ids = params.mediaIds
.split(',')
.map((id) => id.trim())
.filter(Boolean)
if (ids.length > 0) {
body.media = { media_ids: ids }
}
}

if (params.replySettings) {
body.reply_settings = params.replySettings
}

return body
},
},

transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
id: data.data?.id ?? '',
text: data.data?.text ?? '',
},
}
Comment thread
waleedlatif1 marked this conversation as resolved.
},

outputs: {
id: {
type: 'string',
description: 'The ID of the created tweet',
},
text: {
type: 'string',
description: 'The text of the created tweet',
},
},
}
62 changes: 62 additions & 0 deletions apps/sim/tools/x/delete_bookmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { ToolConfig } from '@/tools/types'
import type { XDeleteBookmarkParams, XDeleteBookmarkResponse } from '@/tools/x/types'

export const xDeleteBookmarkTool: ToolConfig<XDeleteBookmarkParams, XDeleteBookmarkResponse> = {
id: 'x_delete_bookmark',
name: 'X Delete Bookmark',
description: "Remove a tweet from the authenticated user's bookmarks",
version: '1.0.0',

oauth: {
required: true,
provider: 'x',
},

params: {
accessToken: {
type: 'string',
required: true,
visibility: 'hidden',
description: 'X OAuth access token',
},
userId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The authenticated user ID',
},
tweetId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The tweet ID to remove from bookmarks',
},
},

request: {
url: (params) =>
`https://api.x.com/2/users/${params.userId.trim()}/bookmarks/${params.tweetId.trim()}`,
method: 'DELETE',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
}),
},

transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
bookmarked: data.data?.bookmarked ?? false,
},
}
},

outputs: {
bookmarked: {
type: 'boolean',
description: 'Whether the tweet is still bookmarked (should be false after deletion)',
},
},
}
Loading