From 7a15b80ab6da682cbd701a58da948526c0f8105f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 05:06:33 +0000 Subject: [PATCH 1/5] Initial plan for issue From 50062cf345a4a1594a14ff59859b75aaa091f44e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 05:10:09 +0000 Subject: [PATCH 2/5] Initial analysis of copilot instructions update needs Co-authored-by: kawax <1502086+kawax@users.noreply.github.com> --- build/logs/clover.xml | 273 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 build/logs/clover.xml diff --git a/build/logs/clover.xml b/build/logs/clover.xml new file mode 100644 index 0000000..2ed48a0 --- /dev/null +++ b/build/logs/clover.xml @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 61159718701097976d71929d3141df2bf54973c8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 05:13:31 +0000 Subject: [PATCH 3/5] Update copilot instructions with missing methods, features, and improved accuracy Co-authored-by: kawax <1502086+kawax@users.noreply.github.com> --- .github/copilot-instructions.md | 67 +++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 8836ac0..7aed0ad 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -5,15 +5,29 @@ The `revolution/laravel-threads` package is a Laravel library that provides comprehensive integration with Meta's Threads platform. It serves Laravel developers who need to: - **Authenticate users via Threads OAuth** using Laravel Socialite -- **Publish content to Threads** (text posts, images, videos, carousels) -- **Manage Threads content** (delete, repost, search) +- **Publish content to Threads** (text posts, images, videos, carousels, polls) +- **Manage Threads content** (delete, repost, search, status checking) - **Send notifications through Threads** via Laravel's notification system - **Retrieve user profiles and posts** from the Threads API +- **Monitor publishing quotas** and API limits -The package abstracts the complexity of the Threads API behind familiar Laravel patterns (facades, service providers, notifications), enabling developers to integrate Threads functionality without dealing with raw HTTP requests or OAuth flows. It supports both direct API usage and Laravel's notification system for automated posting. +The package abstracts the complexity of the Threads API behind familiar Laravel patterns (facades, service providers, notifications), enabling developers to integrate Threads functionality without dealing with raw HTTP requests or OAuth flows. It supports both direct API usage and Laravel's notification system for automated posting, with extensibility through Laravel's macro system. **Target Users**: Laravel application developers building social media integrations, content management systems, or marketing automation tools that need to interact with Threads. +## Token Management + +The package handles two types of Threads API tokens: + +- **Short-lived tokens**: Obtained through Socialite OAuth flow, valid for limited time +- **Long-lived tokens**: Valid for 60-90 days, required for API operations + +Key token management features: +- Automatic conversion from short-lived to long-lived tokens via `exchangeToken()` +- Token refresh capability via `refreshToken()` for continuous access +- Support for Threads tester tokens (pre-generated as long-lived) +- Database storage recommended (tokens cannot be stored in `.env` permanently) + ## Project Organization ### Core Systems @@ -23,7 +37,8 @@ The package is organized into four main subsystems: 1. **Core API Client System** (`src/ThreadsClient.php`, `src/Contracts/Factory.php`) - Handles direct HTTP communication with Threads API - Implements two-phase content creation (create → publish) - - Manages token authentication and refresh + - Manages token authentication, refresh, and quota monitoring + - Supports extensibility through Laravel's macro system 2. **Laravel Integration Layer** (`src/ThreadsServiceProvider.php`, `src/Facades/Threads.php`, `src/Traits/WithThreads.php`) - Registers services with Laravel's container @@ -37,7 +52,7 @@ The package is organized into four main subsystems: 4. **Notification System** (`src/Notifications/ThreadsChannel.php`, `src/Notifications/ThreadsMessage.php`) - Custom Laravel notification channel for Threads - - Supports text, image, and video content + - Supports text, image, video, and poll content - Integrates with Laravel's notification infrastructure ### Main Files and Directories @@ -76,19 +91,20 @@ docs/ ### Main Classes and Functions **Core API Client:** -- `ThreadsClient`: Main HTTP client with methods like `createText()`, `createImage()`, `publish()`, `delete()` +- `ThreadsClient`: Main HTTP client with methods like `createText()`, `createImage()`, `createVideo()`, `createCarousel()`, `publish()`, `delete()`, `repost()`, `search()`, `profiles()`, `posts()`, `single()`, `replies()`, `status()`, `quota()` - `Factory`: Interface defining the client contract for dependency injection **Laravel Integration:** -- `ThreadsServiceProvider::register()`: Binds Factory to ThreadsClient in service container -- `ThreadsServiceProvider::boot()`: Extends Socialite with Threads driver -- `Threads` (Facade): Provides static access like `Threads::createText()` +- `ThreadsServiceProvider::register()`: Binds Factory to ThreadsClient as scoped service in container +- `ThreadsServiceProvider::boot()`: Extends Socialite with Threads driver using service configuration +- `Threads` (Facade): Provides static access like `Threads::createText()` with macro and conditional support - `WithThreads::threads()`: Trait method returning configured client instance **OAuth System:** -- `ThreadsProvider::redirect()`: Initiates OAuth authorization flow +- `ThreadsProvider::redirect()`: Initiates OAuth authorization flow with default scopes - `ThreadsProvider::user()`: Handles callback and retrieves user data - `ThreadsProvider::exchangeToken()`: Converts short-lived to long-lived tokens +- Default scopes: `['threads_basic', 'threads_content_publish', 'threads_delete', 'threads_keyword_search']` **Notification System:** - `ThreadsChannel::send()`: Processes notifications and dispatches to Threads @@ -97,9 +113,10 @@ docs/ ### CI/CD Pipeline -- **`.github/workflows/test.yml`**: Runs PHPUnit tests across PHP 8.2-8.4, generates coverage -- **`.github/workflows/lint.yml`**: Enforces code style using Laravel Pint -- **`phpunit.xml`**: Configures test discovery and coverage reporting +- **`.github/workflows/test.yml`**: Runs PHPUnit tests across PHP 8.2-8.4, generates coverage with Qlty integration +- **`.github/workflows/lint.yml`**: Enforces code style using Laravel Pint (PHP 8.4) +- **`.github/workflows/copilot-setup-steps.yml`**: Automated setup workflow for GitHub Copilot integration +- **`phpunit.xml`**: Configures test discovery and coverage reporting to `build/logs/clover.xml` - **`pint.json`**: Laravel coding standards with disabled unused imports rule ## Glossary of Codebase-Specific Terms @@ -124,7 +141,7 @@ docs/ **MediaType** - Enum defining content types: TEXT, IMAGE, VIDEO, CAROUSEL. Located: `src/Enums/MediaType.php` -**ReplyControl** - Enum for reply permissions: EVERYONE, FOLLOW, MENTIONED. Located: `src/Enums/ReplyControl.php` +**ReplyControl** - Enum for reply permissions: EVERYONE, FOLLOW (accounts_you_follow), MENTIONED (mentioned_only). Located: `src/Enums/ReplyControl.php` **SearchType** - Enum for search ordering: TOP, RECENT. Located: `src/Enums/SearchType.php` @@ -138,13 +155,29 @@ docs/ **createCarousel** - Method creating multi-media carousel posts. Found in: `ThreadsClient::createCarousel()` +**profiles** - Method retrieving user profile information. Found in: `ThreadsClient::profiles()` + +**posts** - Method retrieving user's posts with pagination. Found in: `ThreadsClient::posts()` + +**single** - Method retrieving a single post by ID. Found in: `ThreadsClient::single()` + +**replies** - Method retrieving replies to posts. Found in: `ThreadsClient::replies()` + +**repost** - Method for reposting existing content. Found in: `ThreadsClient::repost()` + +**status** - Method checking publishing status of containers. Found in: `ThreadsClient::status()` + +**quota** - Method checking API usage limits and quotas. Found in: `ThreadsClient::quota()` + +**search** - Method for keyword search across public Threads content. Found in: `ThreadsClient::search()` + **toThreads** - Notification method returning ThreadsMessage instance. Found in: custom notification classes **routeNotificationForThreads** - Model method providing Threads token for notifications. Found in: Notifiable models **threads** - Trait method returning configured ThreadsClient instance. Found in: `WithThreads::threads()` -**tokenForThreads** - Abstract method models must implement for token retrieval. Found in: `WithThreads` trait +**tokenForThreads** - Abstract method models must implement for token retrieval. Found in: `WithThreads` trait (must be implemented by classes using the trait) **POST_DEFAULT_FIELDS** - Constant array of default API response fields. Found in: `ThreadsClient::POST_DEFAULT_FIELDS` @@ -157,3 +190,7 @@ docs/ **is_carousel** - Boolean flag marking media for carousel inclusion. Found in: media creation methods **sleep** - Parameter controlling publish timing/delays. Found in: `publish()` and `ThreadsMessage` + +**poll_attachment** - Option for adding polls to text posts. Found in: `createText()` options + +**Macroable** - Trait enabling custom method addition to ThreadsClient and ThreadsMessage. Found in: `ThreadsClient` and `ThreadsMessage` classes From e0ca1bf7d9b7dcc5b43915bd071225ef1874c01a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 05:14:56 +0000 Subject: [PATCH 4/5] Final polish: improve notification system description clarity Co-authored-by: kawax <1502086+kawax@users.noreply.github.com> --- .github/copilot-instructions.md | 2 +- build/logs/clover.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 7aed0ad..5bab18e 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -109,7 +109,7 @@ docs/ **Notification System:** - `ThreadsChannel::send()`: Processes notifications and dispatches to Threads - `ThreadsMessage::create()`: Factory method for message construction -- `ThreadsMessage::withImage()`, `ThreadsMessage::withVideo()`: Fluent media attachment +- `ThreadsMessage::withImage()`, `ThreadsMessage::withVideo()`: Fluent media attachment methods ### CI/CD Pipeline diff --git a/build/logs/clover.xml b/build/logs/clover.xml index 2ed48a0..8fbeae1 100644 --- a/build/logs/clover.xml +++ b/build/logs/clover.xml @@ -1,6 +1,6 @@ - - + + From 74b986c111665c1fa7538e94a5e43d5605f95787 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Jun 2025 05:24:27 +0000 Subject: [PATCH 5/5] Add build directory to .gitignore to exclude build artifacts Co-authored-by: kawax <1502086+kawax@users.noreply.github.com> --- .gitignore | 1 + build/logs/clover.xml | 273 ------------------------------------------ 2 files changed, 1 insertion(+), 273 deletions(-) delete mode 100644 build/logs/clover.xml diff --git a/.gitignore b/.gitignore index 83713b9..a38c653 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor .phpunit.result.cache composer.lock +build diff --git a/build/logs/clover.xml b/build/logs/clover.xml deleted file mode 100644 index 8fbeae1..0000000 --- a/build/logs/clover.xml +++ /dev/null @@ -1,273 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -