Skip to content

Commit 956357e

Browse files
committed
Create copilot-instructions.md
1 parent 411b57e commit 956357e

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

.github/copilot-instructions.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Laravel Threads Package Onboarding Guide
2+
3+
## Overview
4+
5+
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:
6+
7+
- **Authenticate users via Threads OAuth** using Laravel Socialite
8+
- **Publish content to Threads** (text posts, images, videos, carousels)
9+
- **Manage Threads content** (delete, repost, search)
10+
- **Send notifications through Threads** via Laravel's notification system
11+
- **Retrieve user profiles and posts** from the Threads API
12+
13+
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.
14+
15+
**Target Users**: Laravel application developers building social media integrations, content management systems, or marketing automation tools that need to interact with Threads.
16+
17+
## Project Organization
18+
19+
### Core Systems
20+
21+
The package is organized into four main subsystems:
22+
23+
1. **Core API Client System** (`src/ThreadsClient.php`, `src/Contracts/Factory.php`)
24+
- Handles direct HTTP communication with Threads API
25+
- Implements two-phase content creation (create → publish)
26+
- Manages token authentication and refresh
27+
28+
2. **Laravel Integration Layer** (`src/ThreadsServiceProvider.php`, `src/Facades/Threads.php`, `src/Traits/WithThreads.php`)
29+
- Registers services with Laravel's container
30+
- Provides static facade interface
31+
- Enables Eloquent model integration via traits
32+
33+
3. **OAuth Authentication System** (`src/Socialite/ThreadsProvider.php`)
34+
- Extends Laravel Socialite for Threads OAuth
35+
- Handles authorization flow and token exchange
36+
- Maps Threads user data to Laravel user objects
37+
38+
4. **Notification System** (`src/Notifications/ThreadsChannel.php`, `src/Notifications/ThreadsMessage.php`)
39+
- Custom Laravel notification channel for Threads
40+
- Supports text, image, and video content
41+
- Integrates with Laravel's notification infrastructure
42+
43+
### Main Files and Directories
44+
45+
```
46+
src/
47+
├── Contracts/
48+
│ └── Factory.php # Interface defining API client contract
49+
├── Enums/
50+
│ ├── MediaType.php # TEXT, IMAGE, VIDEO, CAROUSEL types
51+
│ ├── ReplyControl.php # EVERYONE, FOLLOW, MENTIONED permissions
52+
│ └── SearchType.php # TOP, RECENT search ordering
53+
├── Facades/
54+
│ └── Threads.php # Static facade for ThreadsClient
55+
├── Notifications/
56+
│ ├── ThreadsChannel.php # Custom notification channel
57+
│ └── ThreadsMessage.php # Message structure for notifications
58+
├── Socialite/
59+
│ └── ThreadsProvider.php # OAuth provider for Laravel Socialite
60+
├── Traits/
61+
│ └── WithThreads.php # Trait for Eloquent model integration
62+
├── ThreadsClient.php # Core API client implementation
63+
└── ThreadsServiceProvider.php # Laravel service provider
64+
65+
tests/Feature/
66+
├── Client/ClientTest.php # Core client functionality tests
67+
├── Notifications/NotificationTest.php # Notification system tests
68+
└── Socialite/SocialiteTest.php # OAuth integration tests
69+
70+
docs/
71+
├── basic-client.md # Facade usage examples
72+
├── socialite.md # OAuth setup and usage
73+
└── notification.md # Notification system guide
74+
```
75+
76+
### Main Classes and Functions
77+
78+
**Core API Client:**
79+
- `ThreadsClient`: Main HTTP client with methods like `createText()`, `createImage()`, `publish()`, `delete()`
80+
- `Factory`: Interface defining the client contract for dependency injection
81+
82+
**Laravel Integration:**
83+
- `ThreadsServiceProvider::register()`: Binds Factory to ThreadsClient in service container
84+
- `ThreadsServiceProvider::boot()`: Extends Socialite with Threads driver
85+
- `Threads` (Facade): Provides static access like `Threads::createText()`
86+
- `WithThreads::threads()`: Trait method returning configured client instance
87+
88+
**OAuth System:**
89+
- `ThreadsProvider::redirect()`: Initiates OAuth authorization flow
90+
- `ThreadsProvider::user()`: Handles callback and retrieves user data
91+
- `ThreadsProvider::exchangeToken()`: Converts short-lived to long-lived tokens
92+
93+
**Notification System:**
94+
- `ThreadsChannel::send()`: Processes notifications and dispatches to Threads
95+
- `ThreadsMessage::create()`: Factory method for message construction
96+
- `ThreadsMessage::withImage()`, `ThreadsMessage::withVideo()`: Fluent media attachment
97+
98+
### CI/CD Pipeline
99+
100+
- **`.github/workflows/test.yml`**: Runs PHPUnit tests across PHP 8.2-8.4, generates coverage
101+
- **`.github/workflows/lint.yml`**: Enforces code style using Laravel Pint
102+
- **`phpunit.xml`**: Configures test discovery and coverage reporting
103+
- **`pint.json`**: Laravel coding standards with disabled unused imports rule
104+
105+
## Glossary of Codebase-Specific Terms
106+
107+
**ThreadsClient** - Core HTTP client class implementing Factory contract. Located: `src/ThreadsClient.php`
108+
109+
**Factory** - Interface defining API client methods like `createText()`, `publish()`. Located: `src/Contracts/Factory.php`
110+
111+
**ThreadsProvider** - Socialite driver for Threads OAuth authentication. Located: `src/Socialite/ThreadsProvider.php`
112+
113+
**ThreadsChannel** - Custom Laravel notification channel for sending to Threads. Located: `src/Notifications/ThreadsChannel.php`
114+
115+
**ThreadsMessage** - Data structure for notification content with text/image/video. Located: `src/Notifications/ThreadsMessage.php`
116+
117+
**WithThreads** - Trait providing `threads()` method for Eloquent models. Located: `src/Traits/WithThreads.php`
118+
119+
**ThreadsServiceProvider** - Laravel service provider registering package services. Located: `src/ThreadsServiceProvider.php`
120+
121+
**exchangeToken** - Method converting short-lived OAuth tokens to long-lived ones. Found in: `ThreadsClient::exchangeToken()`
122+
123+
**refreshToken** - Method renewing expired long-lived access tokens. Found in: `ThreadsClient::refreshToken()`
124+
125+
**MediaType** - Enum defining content types: TEXT, IMAGE, VIDEO, CAROUSEL. Located: `src/Enums/MediaType.php`
126+
127+
**ReplyControl** - Enum for reply permissions: EVERYONE, FOLLOW, MENTIONED. Located: `src/Enums/ReplyControl.php`
128+
129+
**SearchType** - Enum for search ordering: TOP, RECENT. Located: `src/Enums/SearchType.php`
130+
131+
**publish** - Two-phase API method completing content creation. Found in: `ThreadsClient::publish()`
132+
133+
**createText** - Method creating text-only posts on Threads. Found in: `ThreadsClient::createText()`
134+
135+
**createImage** - Method creating image posts with optional text. Found in: `ThreadsClient::createImage()`
136+
137+
**createVideo** - Method creating video posts with optional text. Found in: `ThreadsClient::createVideo()`
138+
139+
**createCarousel** - Method creating multi-media carousel posts. Found in: `ThreadsClient::createCarousel()`
140+
141+
**toThreads** - Notification method returning ThreadsMessage instance. Found in: custom notification classes
142+
143+
**routeNotificationForThreads** - Model method providing Threads token for notifications. Found in: Notifiable models
144+
145+
**threads** - Trait method returning configured ThreadsClient instance. Found in: `WithThreads::threads()`
146+
147+
**tokenForThreads** - Abstract method models must implement for token retrieval. Found in: `WithThreads` trait
148+
149+
**POST_DEFAULT_FIELDS** - Constant array of default API response fields. Found in: `ThreadsClient::POST_DEFAULT_FIELDS`
150+
151+
**withImage** - Fluent method adding image URL to ThreadsMessage. Found in: `ThreadsMessage::withImage()`
152+
153+
**withVideo** - Fluent method adding video URL to ThreadsMessage. Found in: `ThreadsMessage::withVideo()`
154+
155+
**auto_publish_text** - Option for immediate text post publishing. Found in: `createText()` options
156+
157+
**is_carousel** - Boolean flag marking media for carousel inclusion. Found in: media creation methods
158+
159+
**sleep** - Parameter controlling publish timing/delays. Found in: `publish()` and `ThreadsMessage`

0 commit comments

Comments
 (0)