Communityコーディング&開発github.com

Taldres/laravel-waitlist

ニュースレターツール(Brevo、Mailchimp、Mailcoachなど)とtaldres/laravel-waitlistのウェイティングリストを同期し、確認済みの連絡先を目的ごとに追加、同意撤回や消去時に削除、さらにプロバイダー側での購読解除をWebhook経由でウェイティングリストに反映します。

laravel-waitlist とは?

このスキルは、`taldres/laravel-waitlist` パッケージを使用するLaravelアプリケーションにおいて、外部のニュースレターツール(例:Brevo、Mailchimp、Mailcoach)とのコンタクトリストの同期を実現します。主な目的は、ウェイティングリスト上の同意状態とプロバイダー側のリストを常に一致させることです。具体的には、`EntryConfirmed` や `ConsentGranted` といったイベントを購読し、確認済みの連絡先を目的ごとにプロバイダーリストに追加します。一方、`ConsentWithdrawn` や `EntryUnsubscribed` が発生した際には、他のリストに同意が残っていないかを確認した上で、該当のプロバイダーリストから削除します。また、プロバイダー側で行われた購読解除はWebhookを受け取ることでウェイティングリストに反映され、その後のキャンペーン送信で再同期されることを防ぎます。このスキルは、Laravelのイベントシステムとキュー、暗号化を活用し、処理が重複しないように注意深く設計されています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Taldres/laravel-waitlist/tree/HEAD/resources/boost/skills/laravel-waitlist-provider-sync

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Laravel Waitlist: 電子メールプロバイダーとの同期

このスキルは、taldres/laravel-waitlist を使用するアプリケーションが外部のニュースレターツールからキャンペーンを送信しており、そのコンタクトリストをウェイティングリストの同意状態に追随させる必要がある場合に使用します。

主な目標

  • プロバイダーは、同意が有効な目的の連絡先のみを保持し、どちらか一方で行われた同意撤回はもう一方にも反映されるようにします。

ワークフロー

1. 同期が必要かどうかを判断する

Laravelアプリケーション自身が(任意のメーラーを通じて)送信するメールには同期は不要です。その場合は Waitlist::recipients($purpose) を使用して送信します。同期が必要なのは、キャンペーンを外部ツールから送信する場合のみです。

2. イベントをプロバイダーの呼び出しにマッピングする

イベントプロバイダーのアクション
EntryConfirmed連絡先を追加。$event->entry->purposes の目的ごとに1つのプロバイダーリストに追加
ConsentGrantedその目的のリストに追加。ただし、$event->subscription->isConfirmed() がtrueの場合のみ
ConsentWithdrawn$event->consent->purpose のリストから削除。ただし、プロジェクトの別のリストがまだその同意を保持している場合は削除しない
EntryUnsubscribedサイクルが保持していたすべての目的のリストから削除。ただし、別のリストがまだその同意を保持している場合は削除しない
EntryForgottenそのメールアドレスのエントリが完全に存在しなくなった場合のみ連絡先を削除。それ以外の場合は、残っているエントリが保持していない目的を削除
  • リストを離れると、そのリスト上のすべての目的のサイクルが終了します。そのリストで同意されたニュースレターも終了し、ConsentWithdrawn は発火しません。
  • EntryForgotten は、消去されたすべてのエントリに対して発火します。forgetAll() や、あるリストの保持期間による削除でも発火します。その際、同じメールアドレスが別のリストに存在する場合もあります。
  • EntrySubscribed では同期しないでください。ダブルオプトインの場合、メールアドレスは未確認です。

3. キュー投入可能で暗号化されたリスナークラス(1つ)

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Taldres\Waitlist\Events\ConsentGranted;
use Taldres\Waitlist\Events\ConsentWithdrawn;
use Taldres\Waitlist\Events\EntryConfirmed;
use Taldres\Waitlist\Events\EntryForgotten;
use Taldres\Waitlist\Events\EntryUnsubscribed;
use Taldres\Waitlist\Models\WaitlistEntry;

class SyncWaitlistToProvider implements ShouldQueue, ShouldBeEncrypted
{
    public function onConfirmed(EntryConfirmed $event): void
    {
        // $event->entry->email を、$event->entry->purposes の各目的のプロバイダーリストに追加
    }

    public function onGranted(ConsentGranted $event): void
    {
        if ($event->subscription->isConfirmed()) {
            // $event->entry->email を $event->consent->purpose のリストに追加
        }
    }

    public function onWithdrawn(ConsentWithdrawn $event): void
    {
        $this->removeUnlessHeld($event->entry->project, $event->entry->email, $event->consent->purpose);
    }

    public function onUnsubscribed(EntryUnsubscribed $event): void
    {
        $event->subscription->consents()->pluck('purpose')->unique()->each(
            fn (string $purpose) => $this->removeUnlessHeld($event->entry->project, $event->entry->email, $purpose),
        );
    }

    public function onForgotten(EntryForgotten $event): void
    {
        if ($event->email === null) {   // 復号できなかった場合
            return;
        }

        if (! WaitlistEntry::query()->forEmail($event->email)->exists()) {
            // 連絡先 $event->email を削除
            return;
        }

        foreach (['waitlist', 'newsletter'] as $purpose) {   // 同期する目的
            $this->removeUnlessHeld($event->project, $event->email, $purpose);
        }
    }

    private function removeUnlessHeld(string $project, string $email, string $purpose): void
    {
        // イベントはコミット後に発火: 目的がまだ有効なのは、プロジェクトの別のリストが保持している場合のみ
        $held = WaitlistEntry::query()->inProject($project)->forEmail($email)->whereConsentedTo($purpose)->exists();

        if (! $held) {
            // $email を $purpose のプロバイダーリストから削除
        }
    }
}

メソッドは手動で登録します。これらのメソッドは意図的に handle で始まらないため、Laravelのイベント自動検出によって2回登録されることはありません:

// AppServiceProvider::boot()
Event::listen(EntryConfirmed::class, [SyncWaitlistToProvider::class, 'onConfirmed']);
Event::listen(ConsentGranted::class, [SyncWaitlistToProvider::class, 'onGranted']);
Event::listen(ConsentWithdrawn::class, [SyncWaitlistToProvider::class, 'onWithdrawn']);
Event::listen(EntryUnsubscribed::class, [SyncWaitlistToProvider::class, 'onUnsubscribed']);
Event::listen(EntryForgotten::class, [SyncWaitlistToProvider::class, 'onForgotten']);

プロバイダーAPIにはLaravelの Http クライアントを使用し、認証情報と目的ごとのリストIDは config/services.php に保持します。

4. プロバイダー側の購読解除をウェイティングリストに反映する

ツールからのキャンペーンには、そのツール独自の購読解除リンクが含まれています。そのWebhookを受信し、該当メールアドレスのすべてのリストから目的を撤回します(繰り返し受信しても変更はありません):

// routes/api.php、またはCSRF保護から除外したルートを使用する場合は routes/web.php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Taldres\Waitlist\Facades\Waitlist;
use Taldres\Waitlist\Models\WaitlistEntry;

Route::post('/webhooks/newsletter', function (Request $request) {
    // まずプロバイダーのドキュメントに従ってWebhookを検証する
    $email = (string) $request->input('email'); // フィールド名はプロバイダーによって異なる

    Waitlist::findByEmail($email)->each(
        fn (WaitlistEntry $entry) => Waitlist::for($entry->list)->withdraw($email, 'newsletter'),
    );

    return response()->noContent();
});

複数のプロジェクトがある場合: プロバイダーリストをそのプロジェクトにマッピングし、Waitlist::project($project)->findByEmail() および Waitlist::project($project)->for($entry->list)->withdraw() を使用します。

ルール、参考資料、テンプレート

  • プロジェクトと目的の組み合わせごとに1つのプロバイダーリストを使用します。オプションの目的のためにウェイティングリストごとに1つのリストを使用してはいけません。オプションの目的はプロジェクトごとに1つの同意だからです。
  • 同じ主要目的を共有するリストは、別々のウェイティングリストです。一方のリストを離れても、別のリストがその目的を保持している限り、連絡先が削除されることはありません。
  • php artisan waitlist:privacy はリスナーを受信者としてリストアップします。プロバイダーは処理者であり、契約が必要です。
  • 完全なBrevoリスナーのガイド: https://github.com/Taldres/laravel-waitlist/blob/main/docs/email-provider-sync.md

例

  • "確認済みニュースレター登録をBrevoに同期": ステップ2と3。config('services.brevo.lists.newsletter') をリストIDとして使用。
  • "Mailchimpで購読解除したユーザーが、それでもリリースメールを受信してしまう": ステップ4。

アンチパターン

  • EntrySubscribed、つまりダブルオプトイン前に同期すること。
  • EntryUnsubscribed で、プロジェクトの他のリストを確認せずに連絡先を削除すること、またはリストの主要目的のみを削除すること。
  • すべての EntryForgotten で連絡先を削除すること。保持期間による削除や forgetAll() は1つのリストだけを消去しますが、そのメールアドレスが別のリストに存在する可能性があります。
  • リスナーのメソッド名を handle* にして、さらに Event::listen() で登録すること。これにより、すべての同期が2回実行されます。
  • Webhookが1つのエントリからのみ撤回する、またはリクエストを検証せずに信頼すること。
  • ディスパッチされた EntryForgotten を、プロバイダーが連絡先を削除した証拠として扱うこと。失敗したジョブは監視する必要があります。

Individual skills in this repo

This repo contains 13 individual skills — each has its own dedicated page.

Taldres/laravel-waitlist

Use this skill when reviewing Laravel package compatibility across composer constraints, PHP versions, Laravel versions, Testbench versions, dependency stability lanes, Windows CI, or matrix-sensitive code and workflow changes.

Taldres/laravel-waitlist

Use this skill when creating or updating the bundled Laravel Boost skill under resources/boost/skills from the package implementation and package documentation. Trigger after public APIs, commands, config, routes, views, publish tags, README content, or examples change.

Taldres/laravel-waitlist

Use this skill when preparing Laravel package releases: CHANGELOG.md updates, generated release notes, GitHub release workflows, version checks, tags, release validation, or release automation changes. Never publish autonomously.

Taldres/laravel-waitlist

Use this skill when adding Laravel package capabilities or wiring them through the service provider: commands, migrations, routes, config merges, views, translations, assets, middleware, publish tags, workbench files, or console-only behavior.

Taldres/laravel-waitlist

Use this skill when writing, editing, fixing, or reviewing package tests with Pest 4/5 and Orchestra Testbench, including TDD, feature tests, unit tests, type coverage, arch tests, workbench behavior, commands, routes, config, migrations, and publishable resources.

Taldres/laravel-waitlist

Integrate taldres/laravel-waitlist in a Laravel application: define purposes, lists and fields, build the signup form, send the confirmation mail from events, add a preference page, and keep consent, retention and encryption intact.

Taldres/laravel-waitlist

Build the pages of a taldres/laravel-waitlist integration: the signup form with the registered wording, and the confirm, unsubscribe and preference pages, either in Laravel controllers (Blade, Livewire, Inertia) or in an SPA or static site over the package's JSON API, including CORS and bot protection.

Taldres/laravel-waitlist

Turn a taldres/laravel-waitlist waitlist into a launch: invite people in batches in signup order, let invited addresses register, announce the launch to everyone who agreed, and erase the list once its purpose is fulfilled.

Taldres/laravel-waitlist

Send the mails of a taldres/laravel-waitlist integration: the double opt-in confirmation, the preference page link, a welcome mail, launch mails and newsletters to the people who agreed, with the right unsubscribe links, one-click headers and a sender per project.

Taldres/laravel-waitlist

Operate a taldres/laravel-waitlist installation: answer access and erasure requests, withdraw a purpose on request, apply retention, erase a list once its purpose is fulfilled, rotate APP_KEY with waitlist:rekey, export a list, and check the setup before going live.

Taldres/laravel-waitlist

Run the waitlists of several products in one Laravel app with taldres/laravel-waitlist projects: define projects, scope facade calls with project(), resolve the project of HTTP signups, send mail per project, handle requests across all projects, or keep projects in a database for a central waitlist API.

Taldres/laravel-waitlist

Build waitlist statistics with taldres/laravel-waitlist: signups and confirmations per day for charts, totals and confirmation rates for a period, the confirmed count on any past day, and how many people are on a list right now, for dashboards, admin pages and API endpoints.

Taldres/laravel-waitlist

Write feature tests for an application's taldres/laravel-waitlist integration: get the plain tokens from events, assert the confirmation and other mails, test the signup, confirm and unsubscribe flows in PHP and over the package's HTTP routes, and bypass rate limits and bot checks in tests.

関連スキル