From cfd1fc3d752c1d32cd820719070b9601e60bd8e2 Mon Sep 17 00:00:00 2001 From: Ali Hesari Date: Sun, 18 Oct 2026 20:48:14 +0200 Subject: [PATCH 1/4] feat(inbox): repost and bookmark X items, X post lookup and recent search --- src/Model/InboxItem.php | 8 +++++ src/Model/XPost.php | 56 ++++++++++++++++++++++++++++++++++ src/Model/XSearchPage.php | 30 ++++++++++++++++++ src/Resource/InboxResource.php | 44 ++++++++++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 src/Model/XPost.php create mode 100644 src/Model/XSearchPage.php diff --git a/src/Model/InboxItem.php b/src/Model/InboxItem.php index 1f4768c..2d12f78 100644 --- a/src/Model/InboxItem.php +++ b/src/Model/InboxItem.php @@ -43,11 +43,15 @@ private function __construct( public readonly ?bool $canHide, public readonly ?bool $canDelete, public readonly ?bool $liked, + public readonly ?bool $reposted, + public readonly ?bool $bookmarked, public readonly ?string $vote, public readonly ?bool $pinned, public readonly ?string $reaction, public readonly ?DateTimeImmutable $editedAt, public readonly ?bool $canLike, + public readonly ?bool $canRepost, + public readonly ?bool $canBookmark, public readonly ?bool $canVote, public readonly ?bool $canPin, public readonly ?bool $canEdit, @@ -95,11 +99,15 @@ public static function fromArray(mixed $data): static self::bool($data, 'can_hide'), self::bool($data, 'can_delete'), self::bool($data, 'liked'), + self::bool($data, 'reposted'), + self::bool($data, 'bookmarked'), self::str($data, 'vote'), self::bool($data, 'pinned'), self::str($data, 'reaction'), self::date($data, 'edited_at'), self::bool($data, 'can_like'), + self::bool($data, 'can_repost'), + self::bool($data, 'can_bookmark'), self::bool($data, 'can_vote'), self::bool($data, 'can_pin'), self::bool($data, 'can_edit'), diff --git a/src/Model/XPost.php b/src/Model/XPost.php new file mode 100644 index 0000000..1714a07 --- /dev/null +++ b/src/Model/XPost.php @@ -0,0 +1,56 @@ + $posts */ + private function __construct( + array $raw, + public readonly array $posts, + public readonly ?string $nextToken, + ) { + parent::__construct($raw); + } + + public static function fromArray(mixed $data): static + { + $data = is_array($data) ? $data : []; + $meta = self::nested($data, 'meta') ?? []; + + return new self( + $data, + XPost::listFrom(self::seq($data, 'data')), + self::str($meta, 'next_token'), + ); + } +} diff --git a/src/Resource/InboxResource.php b/src/Resource/InboxResource.php index 7e8dd5d..a15f734 100644 --- a/src/Resource/InboxResource.php +++ b/src/Resource/InboxResource.php @@ -17,6 +17,8 @@ use Fopost\Sdk\Model\InboxStartConversationResult; use Fopost\Sdk\Model\InboxThread; use Fopost\Sdk\Model\Page; +use Fopost\Sdk\Model\XPost; +use Fopost\Sdk\Model\XSearchPage; /** * $client->inbox(): comments, mentions, reviews and direct messages on connected accounts. @@ -248,6 +250,28 @@ public function unlike(string $itemId): InboxItem return InboxItem::fromArray(self::unwrap($this->http->post("/inbox/{$itemId}/unlike"))); } + /** Repost the item on X, where canRepost is true. Needs the `publish` scope. */ + public function repost(string $itemId): InboxItem + { + return InboxItem::fromArray(self::unwrap($this->http->post("/inbox/{$itemId}/repost"))); + } + + public function unrepost(string $itemId): InboxItem + { + return InboxItem::fromArray(self::unwrap($this->http->post("/inbox/{$itemId}/unrepost"))); + } + + /** Bookmark the item on X, where canBookmark is true. Needs the `publish` scope. */ + public function bookmark(string $itemId): InboxItem + { + return InboxItem::fromArray(self::unwrap($this->http->post("/inbox/{$itemId}/bookmark"))); + } + + public function unbookmark(string $itemId): InboxItem + { + return InboxItem::fromArray(self::unwrap($this->http->post("/inbox/{$itemId}/unbookmark"))); + } + /** * Vote up or down where the network ranks by votes (Reddit), where canVote is true. * @@ -365,4 +389,24 @@ public function rejectReply(int $approvalId): InboxApprovalDecision self::unwrap($this->http->post("/inbox/approvals/{$approvalId}/reject")), ); } + + /** One X post by id, read with the given X account's token; 404 when X has no such post. */ + public function getXPost(string $postId, string $accountId): XPost + { + return XPost::fromArray(self::unwrap($this->http->get("/x/posts/{$postId}", ['account_id' => $accountId]))); + } + + /** + * Recent X posts matching $q (1..512 characters), read with the given X account's token. + * + * $options: `max_results` (10..100) and `next_token` from the previous page. + * + * @param array $options + */ + public function searchXPosts(string $q, string $accountId, array $options = []): XSearchPage + { + return XSearchPage::fromArray( + $this->http->get('/x/search', ['q' => $q, 'account_id' => $accountId] + $options), + ); + } } From f05a7debbc819c29f10315a562b725c7396a7c0d Mon Sep 17 00:00:00 2001 From: Ali Hesari Date: Sun, 18 Oct 2026 20:48:14 +0200 Subject: [PATCH 2/4] feat(accounts): follow and unfollow an X user --- src/Model/XFollowResult.php | 30 ++++++++++++++++++++++++++++++ src/Resource/AccountsResource.php | 16 ++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/Model/XFollowResult.php diff --git a/src/Model/XFollowResult.php b/src/Model/XFollowResult.php new file mode 100644 index 0000000..f328e4f --- /dev/null +++ b/src/Model/XFollowResult.php @@ -0,0 +1,30 @@ +http->post("/accounts/{$accountId}/x/follow", ['user_id' => $userId]), + )); + } + + public function unfollowXUser(string $accountId, string $userId): XFollowResult + { + return XFollowResult::fromArray(self::unwrap( + $this->http->post("/accounts/{$accountId}/x/unfollow", ['user_id' => $userId]), + )); + } + /** * Channels the Slack app can post to in the connected workspace. * From 3ca99bf690af3f9d2961a869642e93fd2ed63ff6 Mon Sep 17 00:00:00 2001 From: Ali Hesari Date: Sun, 18 Oct 2026 20:48:14 +0200 Subject: [PATCH 3/4] test: X repost, bookmark, follow, lookup and search --- tests/AccountsTest.php | 21 ++++++++++++ tests/InboxTest.php | 73 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/tests/AccountsTest.php b/tests/AccountsTest.php index 0e00d24..aab30ea 100644 --- a/tests/AccountsTest.php +++ b/tests/AccountsTest.php @@ -459,4 +459,25 @@ public function testInstagramAndLinkedInReads(): void $mentions = $this->client()->accounts()->searchLinkedInMentions('a_1', 'devtestco'); $this->assertStringEndsWith('(urn:li:organization:2414183)', $mentions[0]->annotation); } + + public function testXFollowAndUnfollowSendTheUserId(): void + { + $followed = ['account_id' => 'a_1', 'user_id' => '2244994945']; + $this->transport->push(200, ['data' => $followed + ['following' => true]]); + $result = $this->client()->accounts()->followXUser('a_1', '2244994945'); + + $this->assertSame('POST', $this->transport->last()['method']); + $this->assertSame('https://api.fopost.com/v1/accounts/a_1/x/follow', $this->transport->last()['url']); + $this->assertSame(['user_id' => '2244994945'], $this->transport->lastJson()); + $this->assertSame('a_1', $result->accountId); + $this->assertSame('2244994945', $result->userId); + $this->assertTrue($result->following); + + $this->transport->push(200, ['data' => $followed + ['following' => false]]); + $result = $this->client()->accounts()->unfollowXUser('a_1', '2244994945'); + + $this->assertSame('https://api.fopost.com/v1/accounts/a_1/x/unfollow', $this->transport->last()['url']); + $this->assertSame(['user_id' => '2244994945'], $this->transport->lastJson()); + $this->assertFalse($result->following); + } } diff --git a/tests/InboxTest.php b/tests/InboxTest.php index 6a00f6e..f36bf46 100644 --- a/tests/InboxTest.php +++ b/tests/InboxTest.php @@ -341,4 +341,77 @@ public function testApprovalsUseIntegerIdsAndAnOptionalText(): void $this->assertSame('https://api.fopost.com/v1/inbox/approvals/42/reject', $this->transport->last()['url']); $this->assertSame('rejected', $decision->outcome); } + + public function testRepostAndBookmarkReturnTheItem(): void + { + $acted = self::item([ + 'reposted' => true, + 'bookmarked' => true, + 'canRepost' => true, + 'canBookmark' => true, + ]); + + foreach (['repost', 'unrepost', 'bookmark', 'unbookmark'] as $action) { + $this->transport->push(200, ['data' => $acted]); + $item = $this->client()->inbox()->{$action}('i_1'); + $this->assertSame('POST', $this->transport->last()['method']); + $this->assertSame("https://api.fopost.com/v1/inbox/i_1/{$action}", $this->transport->last()['url']); + $this->assertNull($this->transport->last()['body']); + $this->assertTrue($item->reposted); + $this->assertTrue($item->bookmarked); + $this->assertTrue($item->canRepost); + $this->assertTrue($item->canBookmark); + } + } + + public function testXPostLookupAndSearch(): void + { + $this->transport->push(200, ['data' => [ + 'id' => '1790000000000000001', + 'text' => 'Launch day', + 'permalink' => 'https://x.com/yourbrand/status/1790000000000000001', + 'author_name' => 'Your Brand', + 'author_handle' => 'yourbrand', + 'author_followers' => 1200, + 'conversation_id' => '1790000000000000001', + 'likes' => 4, + 'replies' => 1, + 'reposts' => 2, + 'quotes' => 0, + 'platform_created_at' => '2026-10-18T09:00:00Z', + ]]); + $post = $this->client()->inbox()->getXPost('1790000000000000001', 'a_1'); + + $this->assertSame('GET', $this->transport->last()['method']); + $this->assertSame( + 'https://api.fopost.com/v1/x/posts/1790000000000000001?account_id=a_1', + $this->transport->last()['url'], + ); + $this->assertSame('yourbrand', $post->authorHandle); + $this->assertSame(2, $post->reposts); + $this->assertSame('2026-10-18', $post->platformCreatedAt?->format('Y-m-d')); + + $this->transport->push(200, [ + 'data' => [['id' => '1790000000000000002', 'text' => 'Nice launch']], + 'meta' => ['next_token' => 'b26v89c19zqg8o3fpe'], + ]); + $page = $this->client()->inbox()->searchXPosts('launch day', 'a_1', ['max_results' => 20]); + + $this->assertSame( + 'https://api.fopost.com/v1/x/search?q=launch+day&account_id=a_1&max_results=20', + $this->transport->last()['url'], + ); + $this->assertCount(1, $page->posts); + $this->assertSame('1790000000000000002', $page->posts[0]->id); + $this->assertSame('b26v89c19zqg8o3fpe', $page->nextToken); + + $this->transport->push(200, ['data' => [], 'meta' => ['next_token' => null]]); + $page = $this->client()->inbox()->searchXPosts('launch day', 'a_1', ['next_token' => $page->nextToken]); + $this->assertSame( + 'https://api.fopost.com/v1/x/search?q=launch+day&account_id=a_1&next_token=b26v89c19zqg8o3fpe', + $this->transport->last()['url'], + ); + $this->assertSame([], $page->posts); + $this->assertNull($page->nextToken); + } } From eed1d0af6a553f58a9a49dd7f2df5c44606a42db Mon Sep 17 00:00:00 2001 From: Ali Hesari Date: Sun, 18 Oct 2026 20:48:15 +0200 Subject: [PATCH 4/4] docs: X engagement actions in README, CHANGELOG and CLAUDE.md --- CHANGELOG.md | 16 ++++++++++++++++ CLAUDE.md | 5 ++++- README.md | 13 +++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b198668..750bcf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ All notable changes to `fopost/sdk` are documented here. +## Unreleased + +### Added + +- `$client->inbox()->repost()`, `unrepost()`, `bookmark()` and `unbookmark()` for X items, + mirroring `like()`/`unlike()` (`inbox` + `publish` scopes). `InboxItem` carries `reposted`, + `bookmarked`, `canRepost` and `canBookmark`. +- `$client->accounts()->followXUser($accountId, $userId)` and `unfollowXUser()` (numeric X user + id, `inbox` + `publish` scopes), returning an `XFollowResult`. +- `$client->inbox()->getXPost($postId, $accountId)` and `searchXPosts($q, $accountId, $options)` + (`inbox` scope): live X reads through the account's token, as `XPost` and `XSearchPage` + (`posts` plus `nextToken` to pass back as `next_token`). +- Every one of these is an X API call metered to the workspace; a spent X balance is a 402 + `platform_balance_spent`. An X account connected before this release must be reconnected for + repost, bookmark and follow, and answers 409 `reconnect_required` until then. + ## 0.3.0 - 2026-10-18 ### Removed diff --git a/CLAUDE.md b/CLAUDE.md index 5a3056a..543f923 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -64,6 +64,7 @@ src/ TelegramConnectCode.php TelegramConnectStatus.php TelegramBotCommand.php TelegramBotCommands.php SlackChannel.php SlackMember.php SlackIdentity.php Inbox*.php (item, thread, conversation, account, platform, approval, reply, refresh and start-conversation results) + XPost.php XSearchPage.php XFollowResult.php Ad.php AdInsights.php ExternalAd.php AdConnection.php AdSource.php BoostablePost.php Audience.php AudiencesResult.php CreatedAudience.php TargetingOption.php LeadForm.php LeadFormSource.php Lead.php LeadsPage.php LeadFormDetail.php FeedLead.php LeadsFeedPage.php LeadPage.php @@ -97,7 +98,9 @@ is added. - `inbox` (scope `inbox`) covers `/inbox`, `/inbox/posts`, `/inbox/conversations`, `unread-count`, `accounts`, `platforms`, `read`, `refresh`, `approvals` (+ `approve`/`reject`, integer ids), and - per-item `PATCH`, `reply`, `hide`, `unhide`, `DELETE`. Not wrapped: `/inbox/chat/*` (browser + per-item `PATCH`, `reply`, `hide`, `unhide`, `DELETE`, `like`/`unlike`, `repost`/`unrepost`, + `bookmark`/`unbookmark`, plus the X pass-through reads `/x/posts/{id}` and `/x/search` + (`getXPost`, `searchXPosts`, `account_id` required). Not wrapped: `/inbox/chat/*` (browser encrypted X Chat) and `/inbox/{id}/attachments/{index}` (a binary stream; the SDK has no binary download path). The read and refresh bodies are snake_case, the item `PATCH` is camelCase (`snoozedUntil`), and list `meta` is `{page, perPage, total}` — `PageMeta` reads `page` as diff --git a/README.md b/README.md index 6a2ad3c..308e749 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,11 @@ $subreddits = $client->accounts()->listRedditSubreddits('acc_1'); $rules = $client->accounts()->listRedditSubredditRules('acc_1', 'webdev'); $flairs = $client->accounts()->listRedditFlairs('acc_1', 'webdev'); $client->accounts()->setRedditDefaultSubreddit('acc_1', 'webdev'); + +// X: follow and unfollow by numeric X user id. Needs the `publish` scope too. An X account +// connected before this shipped answers 409 `reconnect_required` until it is reconnected. +$client->accounts()->followXUser('acc_1', '2244994945'); +$client->accounts()->unfollowXUser('acc_1', '2244994945'); ``` ## Google Business Profile @@ -302,6 +307,8 @@ $client->inbox()->delete($item->id); // also deletes our own reply // These also need the `publish` scope; the item's can* flags say where each works. $client->inbox()->like($item->id); // unlike() +$client->inbox()->repost($item->id); // unrepost(); X, where canRepost is true +$client->inbox()->bookmark($item->id); // unbookmark(); X, where canBookmark is true $client->inbox()->vote($item->id, 'down'); // 'up', 'down', or 'none' to take it back $client->inbox()->pin($item->id); // unpin() $client->inbox()->react($item->id, '❤️'); // null removes ours @@ -320,6 +327,12 @@ foreach ($client->inbox()->listApprovals($workspaceId) as $approval) { $client->inbox()->approveReply($approval->id); // or approveReply($id, 'edited text') } $client->inbox()->rejectReply($approval->id); + +// X pass-through reads, with the X account whose token does the read. Each one is an X API +// call metered to the workspace; an empty X balance is a 402 `platform_balance_spent`. +$post = $client->inbox()->getXPost('1790000000000000001', $accountId); +$results = $client->inbox()->searchXPosts('launch day', $accountId, ['max_results' => 20]); +$more = $client->inbox()->searchXPosts('launch day', $accountId, ['next_token' => $results->nextToken]); ``` ## Contacts