polidog/php-chatwork-api
A lightweight PHP client for the ChatWork API. Send messages, manage rooms, tasks, files, and contacts through a simple, fluent interface. Install with Composer, authenticate with your API token, and start calling ChatWork endpoints in minutes.
composer require polidog/php-chatwork-apisrc/Api/, which lists every endpoint wrapper (Rooms, Messages, Tasks, Members, Files, IncomingRequests, Me, Contacts). Read those classes before reading the README; the README lags behind the code.// config/services.php
'chatwork' => ['token' => env('CHATWORK_API_TOKEN')],
// app/Providers/ChatworkServiceProvider.php
public function register(): void
{
$this->app->singleton(\Polidog\Chatwork\Client::class, fn () =>
new \Polidog\Chatwork\Client(config('services.chatwork.token'))
);
}
app(\Polidog\Chatwork\Client::class)
->rooms()
->messages($roomId)
->create("Deploy finished on " . config('app.env'));
Confirm the room ID by calling ->rooms()->show($id) in php artisan tinker before writing any real code — 404s from wrong room IDs are the most common first-day failure.
Polidog\Chatwork\Client across your codebase. Create App\Services\ChatworkMessenger with send(int $roomId, string $body): void (and notify() / task() as needed). This is your seam for tests, for swapping the client later, and for centralising error handling. One file, not twenty.App\Jobs\SendChatworkMessage with public int $tries = 5; public array $backoff = [10, 30, 60, 120];. Never call the ChatWork API inline from a controller — the latency is invisible in dev and the rate limit will bite in production.App\Notifications\Channels\ChatworkChannel so ChatWork is a first-class channel: via() returns ['chatwork'], and toChatwork($notifiable) returns the message payload. Route rooms through the notifiable ($user->chatwork_room_id) or through a config map.DeploySucceeded, BackupFailed, InvoicePaid → listeners that dispatch(new SendChatworkMessage(...))->onQueue('notifications'). Keeps controllers thin and lets you rate-limit at the queue level (Laravel's RateLimited job middleware works nicely here).chatwork:poll that pulls recent messages per room since the last processed message_id, persists them, and stores the cursor per room in cache or a chatwork_cursors table. Make it idempotent — the API will re-deliver on retry.ChatworkMessenger in the container and assert send() was called. Keep that one class small so the fake stays trivial.Retry-After on 429 responses — Laravel's backoff array is in whole seconds and is too coarse to honour what the API actually returns.publishes(), no facade, no test helpers. Budget an hour for the service provider + wrapper, and expect to write every convenience yourself.X-ChatworkToken header. Guzzle's request logging middleware will happily dump it. Redact that header in any logging middleware, and never dd() a request object in a shared debug session.room_id. Keep a config map (config/chatwork.php → ['rooms' => ['deploy' => 123, 'alerts' => 456]]) so nobody hardcodes magic numbers.[To:123], [info], [title], [hr], [piconname:…] specially. If user-supplied content flows into a message, escape brackets or you will get formatting injection."polidog/php-chatwork-api": "~x.y" in composer.json. Because you wrapped it in ChatworkMessenger, replacing it with a hand-rolled Guzzle client for the six endpoints you actually use is a one-file change — worth considering if you only need messages and tasks.Retry-After and logs redacted requests is more reliable than any retry logic you bolt on at the Laravel layer.How can I help you explore Laravel packages today?