Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Chatwork Api Laravel Package

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.

Deep Wiki
Context7

Getting Started

  • Install: composer require polidog/php-chatwork-api
  • Grab an API token from ChatWork → Settings → API Token. Treat it like any other secret.
  • There is no package-discovered service provider, facade, or config file — you wire it yourself. First stop is src/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.
  • Bind it once as a singleton in your own provider:
// 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'))
    );
}
  • First use case to validate the wiring: post a deploy notice to a project room. Exact method signatures vary by pinned version, but the shape is:
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.

Implementation Patterns

  • Wrap the SDK. Do not inject 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.
  • Always queue. Create 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.
  • Notification channel. Implement 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.
  • Event/listener glue. 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).
  • Inbound polling. ChatWork has no outbound webhooks for messages. Write a scheduled command 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.
  • Testing. Do not try to fake the SDK's Guzzle internals. In tests, bind a fake ChatworkMessenger in the container and assert send() was called. Keep that one class small so the fake stays trivial.

Gotchas and Tips

  • Rate limits are real and strict. ChatWork enforces per-minute quotas aggressively. Combine queue backoff with a job middleware that checks Retry-After on 429 responses — Laravel's backoff array is in whole seconds and is too coarse to honour what the API actually returns.
  • No Laravel integration out of the box. No publishes(), no facade, no test helpers. Budget an hour for the service provider + wrapper, and expect to write every convenience yourself.
  • Token leakage is easy. ChatWork authenticates via an 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 IDs, not names. Every endpoint requires the numeric room_id. Keep a config map (config/chatwork.php → ['rooms' => ['deploy' => 123, 'alerts' => 456]]) so nobody hardcodes magic numbers.
  • Message body limits. ChatWork caps bodies (roughly 1024 chars). Truncate stack traces and link to logs; do not rely on ChatWork as a log sink.
  • Bracket syntax is interpreted. ChatWork renders [To:123], [info], [title], [hr], [piconname:…] specially. If user-supplied content flows into a message, escape brackets or you will get formatting injection.
  • Distinguish failures before retrying. SDK throws on non-2xx. Retry only 5xx and 429. Treat 401 (bad token), 403 (no room access), and 404 (wrong room id) as fatal — retrying them just burns queue capacity.
  • Maintenance risk. Last release 2023-08-17, 28 stars. Pin "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.
  • Extension point. Recent versions accept a PSR-18/Guzzle HTTP client in the constructor. Injecting a Guzzle client with retry middleware that respects Retry-After and logs redacted requests is more reliable than any retry logic you bolt on at the Laravel layer.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource