From 71161f842ca6281fb45994f4d9d6122884d92f71 Mon Sep 17 00:00:00 2001 From: Instinct Agent Date: Fri, 4 Dec 2026 23:06:15 +0200 Subject: [PATCH] Rename package Rehla to Stepwise (upgrade migration, changelog table) --- CHANGELOG.md | 20 +++ README.md | 112 ++++++------ composer.json | 14 +- config/{rehla.php => stepwise.php} | 40 ++--- ...000000_rename_rehla_tables_to_stepwise.php | 36 ++++ ...1_create_stepwise_step_progress_table.php} | 13 +- ...000002_create_stepwise_activity_table.php} | 13 +- ...00003_create_stepwise_templates_table.php} | 11 +- ...0004_create_stepwise_follow_ups_table.php} | 11 +- ...d_status_to_stepwise_follow_ups_table.php} | 9 +- ..._columns_to_stepwise_follow_ups_table.php} | 17 +- ...000007_create_stepwise_consents_table.php} | 11 +- ...reate_stepwise_automation_rules_table.php} | 11 +- docs/ar/README.md | 108 ++++++------ phpunit.xml.dist | 2 +- resources/lang/ar/{rehla.php => stepwise.php} | 6 +- resources/lang/en/{rehla.php => stepwise.php} | 6 +- resources/views/automation/_form.blade.php | 38 ++--- resources/views/automation/create.blade.php | 12 +- resources/views/automation/edit.blade.php | 12 +- resources/views/automation/index.blade.php | 60 +++---- resources/views/automation/preview.blade.php | 18 +- resources/views/dashboard.blade.php | 160 +++++++++--------- resources/views/layout.blade.php | 12 +- resources/views/templates/_form.blade.php | 18 +- resources/views/templates/create.blade.php | 12 +- resources/views/templates/edit.blade.php | 12 +- resources/views/templates/index.blade.php | 28 +-- routes/web.php | 10 +- routes/webhooks.php | 6 +- src/Automation/AutomationEngine.php | 92 +++++----- src/Automation/FollowUpSender.php | 34 ++-- src/Automation/OutboundMessage.php | 2 +- src/Automation/ProviderManager.php | 18 +- src/Automation/Providers/HttpProvider.php | 10 +- src/Automation/Providers/LogProvider.php | 10 +- .../Providers/MetaCloudProvider.php | 8 +- src/Automation/Rule.php | 6 +- src/Automation/RuleRepository.php | 8 +- src/Automation/RunReport.php | 2 +- src/Automation/SendResult.php | 2 +- src/Automation/UrlGuard.php | 4 +- src/Console/AutomateCommand.php | 8 +- src/Console/InstallCommand.php | 14 +- src/Console/PruneCommand.php | 16 +- src/Console/ReportCommand.php | 14 +- src/Contracts/ConsentResolver.php | 4 +- src/Contracts/WhatsAppProvider.php | 6 +- src/Data/UserProgress.php | 2 +- src/Enums/StepStatus.php | 2 +- src/Enums/TemplateType.php | 6 +- src/Events/StepCompleted.php | 2 +- src/Events/StepStarted.php | 2 +- src/Exceptions/AutomationException.php | 12 +- src/Exceptions/ConfigurationException.php | 6 +- src/Exceptions/RehlaException.php | 9 - src/Exceptions/StepwiseException.php | 9 + src/Exceptions/UnknownJourneyException.php | 6 +- src/Exceptions/UnknownStepException.php | 4 +- src/Facades/Rehla.php | 27 --- src/Facades/Stepwise.php | 27 +++ .../Controllers/AutomationRuleController.php | 62 +++---- src/Http/Controllers/DashboardController.php | 58 +++---- src/Http/Controllers/FollowUpController.php | 48 +++--- .../Controllers/MetaWebhookController.php | 34 ++-- src/Http/Controllers/TemplateController.php | 36 ++-- src/Http/Middleware/AuthorizePanel.php | 6 +- src/Http/Middleware/RecordActivity.php | 14 +- src/Jobs/SendAutomatedFollowUp.php | 40 ++--- ...RehlaActivity.php => StepwiseActivity.php} | 6 +- ...ionRule.php => StepwiseAutomationRule.php} | 6 +- .../{RehlaConsent.php => StepwiseConsent.php} | 6 +- ...RehlaFollowUp.php => StepwiseFollowUp.php} | 6 +- ...pProgress.php => StepwiseStepProgress.php} | 8 +- ...RehlaTemplate.php => StepwiseTemplate.php} | 8 +- src/Services/ConsentManager.php | 48 +++--- src/Services/JourneyRegistry.php | 10 +- src/Services/ProgressQuery.php | 14 +- src/Services/ProgressTracker.php | 50 +++--- src/Services/TemplateSuggester.php | 20 +-- src/Services/WhatsAppLink.php | 2 +- src/{RehlaManager.php => StepwiseManager.php} | 26 +-- ...ovider.php => StepwiseServiceProvider.php} | 76 ++++----- tests/Feature/ActivityTest.php | 36 ++-- tests/Feature/AutomatedSendTest.php | 40 ++--- tests/Feature/AutomationEngineTest.php | 106 ++++++------ tests/Feature/AutomationPanelTest.php | 68 ++++---- tests/Feature/AutomationProvidersTest.php | 26 +-- tests/Feature/ConsentTest.php | 94 +++++----- tests/Feature/DashboardTest.php | 66 ++++---- tests/Feature/FollowUpTest.php | 130 +++++++------- tests/Feature/HardeningTest.php | 62 +++---- tests/Feature/InstallTest.php | 54 ++++-- tests/Feature/MetaWebhookTest.php | 26 +-- tests/Feature/SuggesterTest.php | 34 ++-- tests/Feature/TemplateCrudTest.php | 44 ++--- tests/Feature/TrackingTest.php | 64 +++---- tests/Fixtures/User.php | 2 +- tests/Pest.php | 2 +- tests/TestCase.php | 18 +- tests/Unit/JourneyRegistryTest.php | 6 +- tests/Unit/WhatsAppLinkTest.php | 2 +- 102 files changed, 1399 insertions(+), 1275 deletions(-) rename config/{rehla.php => stepwise.php} (84%) create mode 100644 database/migrations/2025_12_31_000000_rename_rehla_tables_to_stepwise.php rename database/migrations/{2026_01_01_000001_create_rehla_step_progress_table.php => 2026_01_01_000001_create_stepwise_step_progress_table.php} (63%) rename database/migrations/{2026_01_01_000002_create_rehla_activity_table.php => 2026_01_01_000002_create_stepwise_activity_table.php} (59%) rename database/migrations/{2026_01_01_000003_create_rehla_templates_table.php => 2026_01_01_000003_create_stepwise_templates_table.php} (60%) rename database/migrations/{2026_01_01_000004_create_rehla_follow_ups_table.php => 2026_01_01_000004_create_stepwise_follow_ups_table.php} (74%) rename database/migrations/{2026_01_01_000005_add_status_to_rehla_follow_ups_table.php => 2026_01_01_000005_add_status_to_stepwise_follow_ups_table.php} (66%) rename database/migrations/{2026_01_01_000006_add_automation_columns_to_rehla_follow_ups_table.php => 2026_01_01_000006_add_automation_columns_to_stepwise_follow_ups_table.php} (70%) rename database/migrations/{2026_01_01_000007_create_rehla_consents_table.php => 2026_01_01_000007_create_stepwise_consents_table.php} (70%) rename database/migrations/{2026_01_01_000008_create_rehla_automation_rules_table.php => 2026_01_01_000008_create_stepwise_automation_rules_table.php} (71%) rename resources/lang/ar/{rehla.php => stepwise.php} (95%) rename resources/lang/en/{rehla.php => stepwise.php} (95%) delete mode 100644 src/Exceptions/RehlaException.php create mode 100644 src/Exceptions/StepwiseException.php delete mode 100644 src/Facades/Rehla.php create mode 100644 src/Facades/Stepwise.php rename src/Models/{RehlaActivity.php => StepwiseActivity.php} (85%) rename src/Models/{RehlaAutomationRule.php => StepwiseAutomationRule.php} (88%) rename src/Models/{RehlaConsent.php => StepwiseConsent.php} (86%) rename src/Models/{RehlaFollowUp.php => StepwiseFollowUp.php} (95%) rename src/Models/{RehlaStepProgress.php => StepwiseStepProgress.php} (86%) rename src/Models/{RehlaTemplate.php => StepwiseTemplate.php} (77%) rename src/{RehlaManager.php => StepwiseManager.php} (81%) rename src/{RehlaServiceProvider.php => StepwiseServiceProvider.php} (56%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc77d1..02a325e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,26 @@ ## Unreleased +### Changed (breaking: renamed from Rehla to Stepwise) +The package is now **Stepwise** (`elbanbydev/stepwise`). Everything that carried the old name changed: + +| Was (Rehla) | Now (Stepwise) | +| --- | --- | +| Composer `elbanbydev/rehla` | `elbanbydev/stepwise` | +| Namespace `Rehla\` and facade `Rehla` | `Stepwise\` and `Stepwise` | +| `config/rehla.php`, config key `rehla.*` | `config/stepwise.php`, `stepwise.*` | +| Env `REHLA_*` | `STEPWISE_*` | +| Tables `rehla_*` | `stepwise_*` (renamed for you by an upgrade migration, data kept) | +| Artisan `rehla:install`, `rehla:report`, `rehla:automate`, `rehla:prune` | `stepwise:install`, `stepwise:report`, `stepwise:automate`, `stepwise:prune` | +| Panel path `/rehla`, routes `rehla.*` | `/stepwise`, `stepwise.*` | +| Gate ability `viewRehla` | `viewStepwise` | +| Webhook path `rehla/webhooks/meta` | `stepwise/webhooks/meta` (update it in Meta's dashboard) | +| Views and translations `rehla::` | `stepwise::` | + +To upgrade: `composer remove elbanbydev/rehla && composer require elbanbydev/stepwise`, rename `config/rehla.php` to `config/stepwise.php` (and its keys' env vars), replace `Rehla\` with `Stepwise\` in your code, update the Gate name and the Meta webhook URL, then run `php artisan migrate`. Your data is kept. + +Fresh installs are not affected. The old `elbanbydev/rehla` package and its v0.5.0 tag are no longer maintained. + ## v0.5.0 - 2026-12-03 First tagged release (earlier version headings below are development history and were never tagged). Highlights: automatic WhatsApp sending (rules, consent, webhook, panel tab, dry run, hardening), the "confirm sent" step, the rename to Rehla, and a refreshed package description and README. diff --git a/README.md b/README.md index 3381804..0d33cba 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# Rehla (رحلة) +# Stepwise Track where every user is in your site's journey, and bring back the ones who stall. بالعربي: [docs/ar/README.md](docs/ar/README.md) -Some sites are not a pile of pages; they are a journey. The user creates an account, completes a profile, places a first order — defined steps, one after another. Rehla records where each user stands and gives the admin one table that always answers three questions: +Some sites are not a pile of pages; they are a journey. The user creates an account, completes a profile, places a first order — defined steps, one after another. Stepwise records where each user stands and gives the admin one table that always answers three questions: 1. Which steps did this user **finish**? 2. Which steps did they **start but never finish**? @@ -12,7 +12,7 @@ Some sites are not a pile of pages; they are a journey. The user creates an acco On top of that table sits a re-engagement flow: a WhatsApp button per user that opens a modal (name, number, message) with a ready-made template pre-selected by where the user is stuck — "encourage to continue" when they have a half-finished step, "encourage to start" for the next step they never touched. Confirming opens the WhatsApp chat with the message prefilled, ready to send. -Optionally, Rehla can also send nudges automatically (off by default): rules such as "started a step but not finished for 2 days", consent and STOP handling, quiet hours, cooldowns, a dry run, a panel tab, and Meta WhatsApp Cloud API, generic HTTP or log drivers. See [Automatic WhatsApp sending](#automatic-whatsapp-sending-optional). +Optionally, Stepwise can also send nudges automatically (off by default): rules such as "started a step but not finished for 2 days", consent and STOP handling, quiet hours, cooldowns, a dry run, a panel tab, and Meta WhatsApp Cloud API, generic HTTP or log drivers. See [Automatic WhatsApp sending](#automatic-whatsapp-sending-optional). > **Status: v0.5.0, pre-1.0.** Covered by an automated suite (Pest, PHPStan level 8, Pint, CI on PHP 8.2 to 8.4 with Laravel 11 and 12). The automatic sending layer is tested against faked Meta/HTTP responses only; try it with your own number and the `log` provider first (see the go-live checklist below). Minor releases before 1.0 may change behavior; see the [CHANGELOG](CHANGELOG.md). @@ -24,17 +24,17 @@ Optionally, Rehla can also send nudges automatically (off by default): rules suc ## Installation ```bash -composer require elbanbydev/rehla -php artisan rehla:install +composer require elbanbydev/stepwise +php artisan stepwise:install ``` -`rehla:install` publishes `config/rehla.php` (if missing) and creates the Rehla tables. Run it again any time; it only applies what is pending. +`stepwise:install` publishes `config/stepwise.php` (if missing) and creates the Stepwise tables. Run it again any time; it only applies what is pending. -Rehla registers its migrations itself, so no `vendor:publish` is needed for them: your normal deploy step `php artisan migrate` picks them up too. Composer cannot run migrations on `composer require` (Laravel packages have no install hook, and running database changes from a Composer script would be unsafe), so one of those two commands has to run once. If the tables are missing, the panel answers with a clear message and the tracking middleware stays quiet instead of breaking your site. +Stepwise registers its migrations itself, so no `vendor:publish` is needed for them: your normal deploy step `php artisan migrate` picks them up too. Composer cannot run migrations on `composer require` (Laravel packages have no install hook, and running database changes from a Composer script would be unsafe), so one of those two commands has to run once. If the tables are missing, the panel answers with a clear message and the tracking middleware stays quiet instead of breaking your site. ## Define your journey -In `config/rehla.php`: +In `config/stepwise.php`: ```php 'journeys' => [ @@ -54,20 +54,20 @@ Steps are ordered. "Not started" is derived from this order: any step the user h ## Track progress ```php -use Rehla\Facades\Rehla; +use Stepwise\Facades\Stepwise; -Rehla::start($user, 'profile'); // user began the step -Rehla::complete($user, 'profile'); // user finished it -Rehla::reset($user, step: 'profile'); // forget one step -Rehla::reset($user); // forget the whole journey +Stepwise::start($user, 'profile'); // user began the step +Stepwise::complete($user, 'profile'); // user finished it +Stepwise::reset($user, step: 'profile'); // forget one step +Stepwise::reset($user); // forget the whole journey -$summary = Rehla::progress($user); +$summary = Stepwise::progress($user); $summary->completedSteps; // ['account'] $summary->startedSteps; // ['profile'] $summary->notStartedSteps; // ['first-order'] ``` -All transitions are idempotent: starting a started step (or completing a completed one) changes nothing and fires no event. Completing a step that was never started stamps both dates. Events `Rehla\Events\StepStarted` and `Rehla\Events\StepCompleted` fire on real transitions only. +All transitions are idempotent: starting a started step (or completing a completed one) changes nothing and fires no event. Completing a step that was never started stamps both dates. Events `Stepwise\Events\StepStarted` and `Stepwise\Events\StepCompleted` fire on real transitions only. ## Track the last visit @@ -75,43 +75,43 @@ The "days absent" filter needs to know when each user was last seen. Add the mid ```php ->withMiddleware(function (Middleware $middleware) { - $middleware->appendToGroup('web', [\Rehla\Http\Middleware\RecordActivity::class]); + $middleware->appendToGroup('web', [\Stepwise\Http\Middleware\RecordActivity::class]); }) ``` -or by its alias `rehla.activity`. Every authenticated request refreshes the user's `last_seen_at`, throttled by `rehla.activity.throttle_seconds` (default 300) so a busy session costs at most one write per window. Guests are never tracked. +or by its alias `stepwise.activity`. Every authenticated request refreshes the user's `last_seen_at`, throttled by `stepwise.activity.throttle_seconds` (default 300) so a busy session costs at most one write per window. Guests are never tracked. ## Open the panel -The panel stays closed until you name a Gate ability in `rehla.panel.gate` (default `viewRehla`) and define it: +The panel stays closed until you name a Gate ability in `stepwise.panel.gate` (default `viewStepwise`) and define it: ```php -Gate::define('viewRehla', fn (User $user) => $user->isAdmin()); +Gate::define('viewStepwise', fn (User $user) => $user->isAdmin()); ``` -Then visit `/rehla` (path configurable). The table shows, per user: name, your configured columns (`rehla.user_columns`, e.g. email, role), and the three journey columns as badges. The filter above the table reads "no visit for at least N day(s)": +Then visit `/stepwise` (path configurable). The table shows, per user: name, your configured columns (`stepwise.user_columns`, e.g. email, role), and the three journey columns as badges. The filter above the table reads "no visit for at least N day(s)": - **0** shows everyone, even someone who registered seconds ago. - **N** shows only users with no recorded visit in the last N days. A user with no visit at all counts from their registration date. ## WhatsApp re-engagement -Each row with a phone number gets a WhatsApp button. The modal shows the user's name, the destination number (normalised to wa.me digits: local `0107…` becomes `20107…` via `rehla.whatsapp.default_country_code`), a template dropdown, and the message. Confirming opens `https://wa.me/?text=` in a new tab — nothing is sent without a human clicking send in WhatsApp. +Each row with a phone number gets a WhatsApp button. The modal shows the user's name, the destination number (normalised to wa.me digits: local `0107…` becomes `20107…` via `stepwise.whatsapp.default_country_code`), a template dropdown, and the message. Confirming opens `https://wa.me/?text=` in a new tab — nothing is sent without a human clicking send in WhatsApp. -Templates are managed at `/rehla/templates`: title + content, plus an optional binding to a specific step of a journey and one of two types: +Templates are managed at `/stepwise/templates`: title + content, plus an optional binding to a specific step of a journey and one of two types: - **Encourage to continue the step** — pre-selected when the user has that step started but unfinished. - **Encourage to start the step** — pre-selected for the next never-started step, when the user has nothing in progress. The modal pre-selects by that rule (most recently updated matching template wins) and the admin can always pick another template or edit the text before opening WhatsApp. Templates with no step binding are never auto-selected. -Set `rehla.phone_attribute` (default `phone`) and `rehla.name_attribute` (default `name`) to match your user model. The placeholder `{name}` inside a template's content is replaced with the user's name when the modal fills the message. +Set `stepwise.phone_attribute` (default `phone`) and `stepwise.name_attribute` (default `name`) to match your user model. The placeholder `{name}` inside a template's content is replaced with the user's name when the modal fills the message. ## Follow-up tracking -When several people have follow-up permission, nobody should message the same user twice. So Rehla records every follow-up the moment the admin confirms the WhatsApp modal: who sent it, when, the exact message, and what it was about (the template title is snapshotted, so the record survives template edits and deletions). +When several people have follow-up permission, nobody should message the same user twice. So Stepwise records every follow-up the moment the admin confirms the WhatsApp modal: who sent it, when, the exact message, and what it was about (the template title is snapshotted, so the record survives template edits and deletions). -The table's **Last follow-up** column sits next to **Last visit**, and each row's **(i)** button opens the full history popup: every message ever sent to that user, newest first. Recording is best-effort and never blocks opening WhatsApp. Set `rehla.follow_up.confirm_sent` to `false` to skip the confirm step: opening WhatsApp then records the follow-up as sent right away. +The table's **Last follow-up** column sits next to **Last visit**, and each row's **(i)** button opens the full history popup: every message ever sent to that user, newest first. Recording is best-effort and never blocks opening WhatsApp. Set `stepwise.follow_up.confirm_sent` to `false` to skip the confirm step: opening WhatsApp then records the follow-up as sent right away. Opening WhatsApp is not the same as sending. The record starts as unconfirmed; after the admin comes back, the modal asks "Did you actually send it?" (with a chance to fix the text). Only confirmed sends count as the last follow-up and trigger the "followed up recently" warning. Abandoned drafts stay in the history labelled "Not sent". @@ -120,14 +120,14 @@ Opening WhatsApp is not the same as sending. The record starts as unconfirmed; a When your app deletes a user, drop their journey data too: ```php -Rehla::forget($user); // removes progress rows and the visit record +Stepwise::forget($user); // removes progress rows and the visit record ``` ## Artisan report ```bash -php artisan rehla:report # every journey -php artisan rehla:report onboarding # one journey +php artisan stepwise:report # every journey +php artisan stepwise:report onboarding # one journey ``` Prints, per step: how many users completed it, started it without finishing, and never started it. @@ -138,6 +138,10 @@ Prints, per step: how many users completed it, started it without finishing, and composer check # pint --test, phpstan level 8, pest ``` +## Upgrading from Rehla + +Stepwise was called Rehla until v0.5.0. If you installed `elbanbydev/rehla`, see the rename table in the [CHANGELOG](CHANGELOG.md#unreleased). Short version: `composer remove elbanbydev/rehla && composer require elbanbydev/stepwise`, rename `config/rehla.php` to `config/stepwise.php`, replace `Rehla\` with `Stepwise\`, `REHLA_*` env vars with `STEPWISE_*`, the Gate `viewRehla` with `viewStepwise`, update the Meta webhook URL, then `php artisan migrate` (tables are renamed, data is kept). + ## License MIT. See [LICENSE.md](LICENSE.md). @@ -145,42 +149,42 @@ MIT. See [LICENSE.md](LICENSE.md). ## Automatic WhatsApp sending (optional) -Manual follow-up stays as it is. Automation is a separate, optional layer that is **off by default**. Every setting lives in `config/rehla.php` and env first; showing any of it in the panel is your choice. +Manual follow-up stays as it is. Automation is a separate, optional layer that is **off by default**. Every setting lives in `config/stepwise.php` and env first; showing any of it in the panel is your choice. ```env -REHLA_AUTOMATION_ENABLED=true -REHLA_AUTOMATION_PROVIDER=log # log (dry run), meta, http, or your own -REHLA_META_PHONE_NUMBER_ID=... -REHLA_META_ACCESS_TOKEN=... -REHLA_META_VERIFY_TOKEN=... # for the webhook -REHLA_META_APP_SECRET=... +STEPWISE_AUTOMATION_ENABLED=true +STEPWISE_AUTOMATION_PROVIDER=log # log (dry run), meta, http, or your own +STEPWISE_META_PHONE_NUMBER_ID=... +STEPWISE_META_ACCESS_TOKEN=... +STEPWISE_META_VERIFY_TOKEN=... # for the webhook +STEPWISE_META_APP_SECRET=... ``` -Providers (`rehla.automation.providers`): +Providers (`stepwise.automation.providers`): - `log`: dry run. Logs the message, sends nothing. Its rows are marked "Dry run" and never count as a real follow-up. Start here. -- `meta`: WhatsApp Business Cloud API. Outside the 24-hour customer service window Meta only accepts approved templates, so automatic nudges need a template name; free text only works inside the window. Meta bills per message by category, and you pay Meta, not Rehla. +- `meta`: WhatsApp Business Cloud API. Outside the 24-hour customer service window Meta only accepts approved templates, so automatic nudges need a template name; free text only works inside the window. Meta bills per message by category, and you pay Meta, not Stepwise. - `http`: any service that takes an HTTP request. The body is a config array with `{phone}`, `{message}`, `{template}`, `{language}`, `{idempotency_key}` placeholders. HTTPS only, and private or loopback addresses are refused unless you turn that off for development. -- Your own: `app(Rehla\Automation\ProviderManager::class)->extend('acme', fn (array $config) => new AcmeProvider(...))`, then `'driver' => 'acme'` in config. +- Your own: `app(Stepwise\Automation\ProviderManager::class)->extend('acme', fn (array $config) => new AcmeProvider(...))`, then `'driver' => 'acme'` in config. -Sends run on your queue (`rehla.automation.queue`), so run a queue worker. Temporary failures (timeouts, 429, 5xx) retry with the delays in `rehla.automation.retry.backoff_seconds` (seconds: 60 = a minute, 3600 = an hour); permanent ones are marked failed with the provider's reason. Every automatic send is recorded in the same follow-up history as manual ones, labelled "Automatic". +Sends run on your queue (`stepwise.automation.queue`), so run a queue worker. Temporary failures (timeouts, 429, 5xx) retry with the delays in `stepwise.automation.retry.backoff_seconds` (seconds: 60 = a minute, 3600 = an hour); permanent ones are marked failed with the provider's reason. Every automatic send is recorded in the same follow-up history as manual ones, labelled "Automatic". -Consent comes first. By default Rehla only sends to users who opted in (`rehla.consent.required`). Meta requires opt-in too: https://developers.facebook.com/docs/whatsapp/overview/getting-opt-in/ +Consent comes first. By default Stepwise only sends to users who opted in (`stepwise.consent.required`). Meta requires opt-in too: https://developers.facebook.com/docs/whatsapp/overview/getting-opt-in/ ```php -Rehla::consent()->optIn($user, 'signup_form', 'ticked the box'); -Rehla::consent()->optOut($user); // also cancels their queued automatic sends +Stepwise::consent()->optIn($user, 'signup_form', 'ticked the box'); +Stepwise::consent()->optOut($user); // also cancels their queued automatic sends ``` -Where consent comes from (`rehla.consent.source`): `table` (the calls above, latest decision wins and the history is kept), `attribute` (a truthy column or accessor named in `attribute`), or `resolver` (an invokable class implementing `Rehla\Contracts\ConsentResolver`). An opt-out recorded through Rehla blocks sends with any source. Set `required` to `false` only if you collect consent elsewhere. `Rehla::forget($user)` deletes their consent history too. +Where consent comes from (`stepwise.consent.source`): `table` (the calls above, latest decision wins and the history is kept), `attribute` (a truthy column or accessor named in `attribute`), or `resolver` (an invokable class implementing `Stepwise\Contracts\ConsentResolver`). An opt-out recorded through Stepwise blocks sends with any source. Set `required` to `false` only if you collect consent elsewhere. `Stepwise::forget($user)` deletes their consent history too. -Webhook (delivery status and STOP replies). It is only registered when the meta provider has both `REHLA_META_VERIFY_TOKEN` and `REHLA_META_APP_SECRET`. Point Meta at `https://your-app/rehla/webhooks/meta` (`rehla.webhooks.path`, `rehla.webhooks.middleware`). Requests without a valid `X-Hub-Signature-256` are rejected. Delivery states only move forward (sent, delivered, read); a failure is recorded with Meta's error. A user who replies with a stop keyword (`rehla.webhooks.stop_keywords`, English and Arabic by default, whole-message match, Arabic hamza forms treated alike) is opted out; `start_keywords` and the optional `stop_reply` / `start_reply` are config too. Matching a number to a user needs `rehla.phone_attribute` to be a real column. Webhook reference: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/messages/ +Webhook (delivery status and STOP replies). It is only registered when the meta provider has both `STEPWISE_META_VERIFY_TOKEN` and `STEPWISE_META_APP_SECRET`. Point Meta at `https://your-app/stepwise/webhooks/meta` (`stepwise.webhooks.path`, `stepwise.webhooks.middleware`). Requests without a valid `X-Hub-Signature-256` are rejected. Delivery states only move forward (sent, delivered, read); a failure is recorded with Meta's error. A user who replies with a stop keyword (`stepwise.webhooks.stop_keywords`, English and Arabic by default, whole-message match, Arabic hamza forms treated alike) is opted out; `start_keywords` and the optional `stop_reply` / `start_reply` are config too. Matching a number to a user needs `stepwise.phone_attribute` to be a real column. Webhook reference: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/messages/ In the panel, opted-out users get an "Opted out" mark and the follow-up modal asks for an explicit override before a manual message to them. ### Rules and the engine -Rules say who gets which message and when. Define them in `rehla.automation.rules` (code, always available) or in the `rehla_automation_rules` table (managed in the panel's Automation tab). Both run together. +Rules say who gets which message and when. Define them in `stepwise.automation.rules` (code, always available) or in the `stepwise_automation_rules` table (managed in the panel's Automation tab). Both run together. ```php 'rules' => [ @@ -202,23 +206,23 @@ Conditions: `inactive_for` (no visit for the time), `step_not_started_for` (the Run it from the scheduler (every 5 to 15 minutes) and start with a dry run: ```php -Schedule::command('rehla:automate')->everyTenMinutes(); +Schedule::command('stepwise:automate')->everyTenMinutes(); ``` ```bash -php artisan rehla:automate --dry-run # who would be messaged, who is skipped and why -php artisan rehla:automate --rule=stuck-profile +php artisan stepwise:automate --dry-run # who would be messaged, who is skipped and why +php artisan stepwise:automate --rule=stuck-profile ``` -Guards, in order, each skip counted with its reason: valid phone, consent (and no opt-out), quiet hours, cooldown, manual lock, already queued, max sends per user, then global limits. All are in `rehla.automation`: `quiet_hours` (default 21:00 to 09:00, app timezone, optional per-user timezone column), `cooldown_hours` (72, or per rule), `manual_lock_hours` (2: an admin's open WhatsApp draft blocks automation), `limits` (`per_hour`, `per_day`, `per_run`; 0 turns one off). Just before sending, the job cancels the message if an admin messaged that user by hand in the meantime. +Guards, in order, each skip counted with its reason: valid phone, consent (and no opt-out), quiet hours, cooldown, manual lock, already queued, max sends per user, then global limits. All are in `stepwise.automation`: `quiet_hours` (default 21:00 to 09:00, app timezone, optional per-user timezone column), `cooldown_hours` (72, or per rule), `manual_lock_hours` (2: an admin's open WhatsApp draft blocks automation), `limits` (`per_hour`, `per_day`, `per_run`; 0 turns one off). Just before sending, the job cancels the message if an admin messaged that user by hand in the meantime. -The panel has an **Automation** tab: rules from the database (add, edit, turn on or off, delete), config rules (read-only), a dry-run preview per rule (who would be messaged now, who is skipped and why) and the latest 50 automatic sends with delivery status. It is optional: set `rehla.panel.automation_tab` to `false` to hide it and close its routes. Everything it does is also possible from config and `rehla:automate`. +The panel has an **Automation** tab: rules from the database (add, edit, turn on or off, delete), config rules (read-only), a dry-run preview per rule (who would be messaged now, who is skipped and why) and the latest 50 automatic sends with delivery status. It is optional: set `stepwise.panel.automation_tab` to `false` to hide it and close its routes. Everything it does is also possible from config and `stepwise:automate`. ### Before real users (checklist) -1. Start with `REHLA_AUTOMATION_PROVIDER=log` and `php artisan rehla:automate --dry-run`; read the preview in the Automation tab. -2. Collect opt-in (`Rehla::consent()->optIn($user)` when the user agrees), keep `rehla.consent.required` on. +1. Start with `STEPWISE_AUTOMATION_PROVIDER=log` and `php artisan stepwise:automate --dry-run`; read the preview in the Automation tab. +2. Collect opt-in (`Stepwise::consent()->optIn($user)` when the user agrees), keep `stepwise.consent.required` on. 3. Create and get your Meta templates approved in Meta Business Manager; map them with `provider_template`. 4. Set the webhook (verify token, app secret) so STOP replies and delivery status work, and test it with a number you own. -5. Run a queue worker and the scheduler (`rehla:automate` every 5 to 15 minutes). +5. Run a queue worker and the scheduler (`stepwise:automate` every 5 to 15 minutes). 6. Send to your own number first with a rule limited by `limits.per_run`. -7. Optional: `rehla.automation.retention_days` with `Schedule::command('rehla:prune')->daily()` to delete old automatic rows. Queued sends that never ran are cancelled after `stale_queued_hours` (24). +7. Optional: `stepwise.automation.retention_days` with `Schedule::command('stepwise:prune')->daily()` to delete old automatic rows. Queued sends that never ran are cancelled after `stale_queued_hours` (24). diff --git a/composer.json b/composer.json index f79bed8..8b398c4 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "elbanbydev/rehla", - "description": "Rehla (رحلة) - track where every user is in your site's journey (finished, started, never started), re-engage them with a WhatsApp panel, and optionally send rule-based automatic WhatsApp nudges with consent, quiet hours and a dry run.", + "name": "elbanbydev/stepwise", + "description": "Stepwise - track where every user is in your site's journey (finished, started, never started), re-engage them with a WhatsApp panel, and optionally send rule-based automatic WhatsApp nudges with consent, quiet hours and a dry run.", "keywords": [ "laravel", "user-journey", @@ -9,7 +9,7 @@ "user-progress", "whatsapp", "egypt", - "rehla", + "stepwise", "whatsapp-automation", "whatsapp-cloud-api", "laravel-package" @@ -33,21 +33,21 @@ }, "autoload": { "psr-4": { - "Rehla\\": "src/" + "Stepwise\\": "src/" } }, "autoload-dev": { "psr-4": { - "Rehla\\Tests\\": "tests/" + "Stepwise\\Tests\\": "tests/" } }, "extra": { "laravel": { "providers": [ - "Rehla\\RehlaServiceProvider" + "Stepwise\\StepwiseServiceProvider" ], "aliases": { - "Rehla": "Rehla\\Facades\\Rehla" + "Stepwise": "Stepwise\\Facades\\Stepwise" } } }, diff --git a/config/rehla.php b/config/stepwise.php similarity index 84% rename from config/rehla.php rename to config/stepwise.php index cd49043..0d97613 100644 --- a/config/rehla.php +++ b/config/stepwise.php @@ -5,10 +5,10 @@ return [ /* - | The Eloquent model that moves through the journey. Rehla never + | The Eloquent model that moves through the journey. Stepwise never | migrates this model's table; it keeps its own tables instead. */ - 'user_model' => env('REHLA_USER_MODEL', 'App\\Models\\User'), + 'user_model' => env('STEPWISE_USER_MODEL', 'App\\Models\\User'), /* | Attributes used in the panel: the display name and the WhatsApp @@ -44,7 +44,7 @@ ], /* - | Last-visit tracking. Add the `rehla.activity` middleware alias to + | Last-visit tracking. Add the `stepwise.activity` middleware alias to | your web (and/or api) middleware group. Writes are throttled so a | busy user costs at most one write per throttle window. */ @@ -56,13 +56,13 @@ /* | The admin panel. It stays closed (403) until you name a Gate | ability in `panel.gate` and define it in your AuthServiceProvider: - | Gate::define('viewRehla', fn (User $user) => $user->isAdmin()); + | Gate::define('viewStepwise', fn (User $user) => $user->isAdmin()); */ 'panel' => [ 'enabled' => true, - 'path' => 'rehla', + 'path' => 'stepwise', 'middleware' => ['web'], - 'gate' => 'viewRehla', + 'gate' => 'viewStepwise', // Show the Automation tab (rules, dry-run preview, history). false // hides it and closes its routes; rules still work from config. 'automation_tab' => true, @@ -93,23 +93,23 @@ | window, so automatic nudges need an approved template. */ 'automation' => [ - 'enabled' => (bool) env('REHLA_AUTOMATION_ENABLED', false), - 'provider' => env('REHLA_AUTOMATION_PROVIDER', 'log'), + 'enabled' => (bool) env('STEPWISE_AUTOMATION_ENABLED', false), + 'provider' => env('STEPWISE_AUTOMATION_PROVIDER', 'log'), 'providers' => [ 'log' => ['driver' => 'log', 'channel' => null], 'meta' => [ 'driver' => 'meta', - 'phone_number_id' => env('REHLA_META_PHONE_NUMBER_ID'), - 'access_token' => env('REHLA_META_ACCESS_TOKEN'), - 'api_version' => env('REHLA_META_API_VERSION', 'v21.0'), - 'language' => env('REHLA_META_TEMPLATE_LANGUAGE', 'ar'), + 'phone_number_id' => env('STEPWISE_META_PHONE_NUMBER_ID'), + 'access_token' => env('STEPWISE_META_ACCESS_TOKEN'), + 'api_version' => env('STEPWISE_META_API_VERSION', 'v21.0'), + 'language' => env('STEPWISE_META_TEMPLATE_LANGUAGE', 'ar'), 'timeout' => 15, // For the webhook below: the token you type in Meta's webhook // setup, and your Meta app secret (checks the signature). - 'verify_token' => env('REHLA_META_VERIFY_TOKEN'), - 'app_secret' => env('REHLA_META_APP_SECRET'), + 'verify_token' => env('STEPWISE_META_VERIFY_TOKEN'), + 'app_secret' => env('STEPWISE_META_APP_SECRET'), ], // Any service that takes an HTTP request. Body values may use @@ -117,7 +117,7 @@ // a value of exactly {params} becomes the template parameter list. 'http' => [ 'driver' => 'http', - 'url' => env('REHLA_HTTP_URL'), + 'url' => env('STEPWISE_HTTP_URL'), 'method' => 'POST', 'headers' => [], 'body' => ['to' => '{phone}', 'text' => '{message}'], @@ -131,7 +131,7 @@ // A queued send whose job never ran (stopped worker, lost queue) is // cancelled after this many hours so it cannot block the user. 0 = never. 'stale_queued_hours' => 24, - // `php artisan rehla:prune` deletes finished automatic sends older + // `php artisan stepwise:prune` deletes finished automatic sends older // than this many days. null/0 = keep everything. 'retention_days' => null, @@ -178,9 +178,9 @@ | Consent for automatic messages. Meta requires the user's opt-in. | required: false lets automation message users without a record | (an opt-out always blocks, whatever this says). - | source: "table" (Rehla::consent()->optIn($user)), "attribute" (a + | source: "table" (Stepwise::consent()->optIn($user)), "attribute" (a | truthy column or accessor named in `attribute`), or "resolver" - | (an invokable class implementing Rehla\Contracts\ConsentResolver). + | (an invokable class implementing Stepwise\Contracts\ConsentResolver). */ 'consent' => [ 'required' => true, @@ -199,7 +199,7 @@ | match (allowed because the user just wrote to you); null = silent. */ 'webhooks' => [ - 'path' => 'rehla/webhooks/meta', + 'path' => 'stepwise/webhooks/meta', 'middleware' => ['api'], 'stop_keywords' => ['stop', 'unsubscribe', 'إيقاف', 'توقف', 'إلغاء الاشتراك'], 'start_keywords' => [], @@ -212,7 +212,7 @@ | without "+". Local numbers (leading 0) get the country code. */ 'whatsapp' => [ - 'default_country_code' => env('REHLA_WHATSAPP_COUNTRY_CODE', '20'), + 'default_country_code' => env('STEPWISE_WHATSAPP_COUNTRY_CODE', '20'), ], ]; diff --git a/database/migrations/2025_12_31_000000_rename_rehla_tables_to_stepwise.php b/database/migrations/2025_12_31_000000_rename_rehla_tables_to_stepwise.php new file mode 100644 index 0000000..c625bdf --- /dev/null +++ b/database/migrations/2025_12_31_000000_rename_rehla_tables_to_stepwise.php @@ -0,0 +1,36 @@ + 'stepwise_step_progress', + 'rehla_activity' => 'stepwise_activity', + 'rehla_templates' => 'stepwise_templates', + 'rehla_follow_ups' => 'stepwise_follow_ups', + 'rehla_consents' => 'stepwise_consents', + 'rehla_automation_rules' => 'stepwise_automation_rules', + ]; + + public function up(): void + { + foreach (self::TABLES as $old => $new) { + if (Schema::hasTable($old) && ! Schema::hasTable($new)) { + Schema::rename($old, $new); + } + } + } + + public function down(): void + { + // Intentionally empty: renaming back would break the other migrations. + } +}; diff --git a/database/migrations/2026_01_01_000001_create_rehla_step_progress_table.php b/database/migrations/2026_01_01_000001_create_stepwise_step_progress_table.php similarity index 63% rename from database/migrations/2026_01_01_000001_create_rehla_step_progress_table.php rename to database/migrations/2026_01_01_000001_create_stepwise_step_progress_table.php index 64f8ce5..402b391 100644 --- a/database/migrations/2026_01_01_000001_create_rehla_step_progress_table.php +++ b/database/migrations/2026_01_01_000001_create_stepwise_step_progress_table.php @@ -10,7 +10,12 @@ { public function up(): void { - Schema::create('rehla_step_progress', function (Blueprint $table): void { + // Already there: an install upgraded from the former Rehla package. + if (Schema::hasTable('stepwise_step_progress')) { + return; + } + + Schema::create('stepwise_step_progress', function (Blueprint $table): void { $table->id(); $table->string('trackable_type'); $table->unsignedBigInteger('trackable_id'); @@ -21,13 +26,13 @@ public function up(): void $table->timestamp('completed_at')->nullable(); $table->timestamps(); - $table->unique(['trackable_type', 'trackable_id', 'journey', 'step'], 'rehla_progress_unique'); - $table->index(['journey', 'step'], 'rehla_progress_step_index'); + $table->unique(['trackable_type', 'trackable_id', 'journey', 'step'], 'stepwise_progress_unique'); + $table->index(['journey', 'step'], 'stepwise_progress_step_index'); }); } public function down(): void { - Schema::dropIfExists('rehla_step_progress'); + Schema::dropIfExists('stepwise_step_progress'); } }; diff --git a/database/migrations/2026_01_01_000002_create_rehla_activity_table.php b/database/migrations/2026_01_01_000002_create_stepwise_activity_table.php similarity index 59% rename from database/migrations/2026_01_01_000002_create_rehla_activity_table.php rename to database/migrations/2026_01_01_000002_create_stepwise_activity_table.php index 88d0f1f..ffd4210 100644 --- a/database/migrations/2026_01_01_000002_create_rehla_activity_table.php +++ b/database/migrations/2026_01_01_000002_create_stepwise_activity_table.php @@ -10,20 +10,25 @@ { public function up(): void { - Schema::create('rehla_activity', function (Blueprint $table): void { + // Already there: an install upgraded from the former Rehla package. + if (Schema::hasTable('stepwise_activity')) { + return; + } + + Schema::create('stepwise_activity', function (Blueprint $table): void { $table->id(); $table->string('trackable_type'); $table->unsignedBigInteger('trackable_id'); $table->timestamp('last_seen_at'); $table->timestamps(); - $table->unique(['trackable_type', 'trackable_id'], 'rehla_activity_unique'); - $table->index('last_seen_at', 'rehla_activity_last_seen_index'); + $table->unique(['trackable_type', 'trackable_id'], 'stepwise_activity_unique'); + $table->index('last_seen_at', 'stepwise_activity_last_seen_index'); }); } public function down(): void { - Schema::dropIfExists('rehla_activity'); + Schema::dropIfExists('stepwise_activity'); } }; diff --git a/database/migrations/2026_01_01_000003_create_rehla_templates_table.php b/database/migrations/2026_01_01_000003_create_stepwise_templates_table.php similarity index 60% rename from database/migrations/2026_01_01_000003_create_rehla_templates_table.php rename to database/migrations/2026_01_01_000003_create_stepwise_templates_table.php index 44775c9..71688e7 100644 --- a/database/migrations/2026_01_01_000003_create_rehla_templates_table.php +++ b/database/migrations/2026_01_01_000003_create_stepwise_templates_table.php @@ -10,7 +10,12 @@ { public function up(): void { - Schema::create('rehla_templates', function (Blueprint $table): void { + // Already there: an install upgraded from the former Rehla package. + if (Schema::hasTable('stepwise_templates')) { + return; + } + + Schema::create('stepwise_templates', function (Blueprint $table): void { $table->id(); $table->string('title'); $table->text('content'); @@ -19,12 +24,12 @@ public function up(): void $table->string('type', 24); $table->timestamps(); - $table->index(['journey', 'step', 'type'], 'rehla_templates_lookup'); + $table->index(['journey', 'step', 'type'], 'stepwise_templates_lookup'); }); } public function down(): void { - Schema::dropIfExists('rehla_templates'); + Schema::dropIfExists('stepwise_templates'); } }; diff --git a/database/migrations/2026_01_01_000004_create_rehla_follow_ups_table.php b/database/migrations/2026_01_01_000004_create_stepwise_follow_ups_table.php similarity index 74% rename from database/migrations/2026_01_01_000004_create_rehla_follow_ups_table.php rename to database/migrations/2026_01_01_000004_create_stepwise_follow_ups_table.php index 91c352d..fd44ee6 100644 --- a/database/migrations/2026_01_01_000004_create_rehla_follow_ups_table.php +++ b/database/migrations/2026_01_01_000004_create_stepwise_follow_ups_table.php @@ -10,7 +10,12 @@ { public function up(): void { - Schema::create('rehla_follow_ups', function (Blueprint $table): void { + // Already there: an install upgraded from the former Rehla package. + if (Schema::hasTable('stepwise_follow_ups')) { + return; + } + + Schema::create('stepwise_follow_ups', function (Blueprint $table): void { $table->id(); $table->string('trackable_type'); $table->unsignedBigInteger('trackable_id'); @@ -25,12 +30,12 @@ public function up(): void $table->string('channel', 24)->default('whatsapp'); $table->timestamps(); - $table->index(['trackable_type', 'trackable_id', 'created_at'], 'rehla_followups_user_index'); + $table->index(['trackable_type', 'trackable_id', 'created_at'], 'stepwise_followups_user_index'); }); } public function down(): void { - Schema::dropIfExists('rehla_follow_ups'); + Schema::dropIfExists('stepwise_follow_ups'); } }; diff --git a/database/migrations/2026_01_01_000005_add_status_to_rehla_follow_ups_table.php b/database/migrations/2026_01_01_000005_add_status_to_stepwise_follow_ups_table.php similarity index 66% rename from database/migrations/2026_01_01_000005_add_status_to_rehla_follow_ups_table.php rename to database/migrations/2026_01_01_000005_add_status_to_stepwise_follow_ups_table.php index 588dd01..a344667 100644 --- a/database/migrations/2026_01_01_000005_add_status_to_rehla_follow_ups_table.php +++ b/database/migrations/2026_01_01_000005_add_status_to_stepwise_follow_ups_table.php @@ -14,7 +14,12 @@ */ public function up(): void { - Schema::table('rehla_follow_ups', function (Blueprint $table): void { + // Already there: an install upgraded from the former Rehla package. + if (Schema::hasColumn('stepwise_follow_ups', 'status')) { + return; + } + + Schema::table('stepwise_follow_ups', function (Blueprint $table): void { $table->string('status', 16)->default('opened')->after('channel'); $table->timestamp('sent_at')->nullable()->after('status'); }); @@ -22,7 +27,7 @@ public function up(): void public function down(): void { - Schema::table('rehla_follow_ups', function (Blueprint $table): void { + Schema::table('stepwise_follow_ups', function (Blueprint $table): void { $table->dropColumn(['status', 'sent_at']); }); } diff --git a/database/migrations/2026_01_01_000006_add_automation_columns_to_rehla_follow_ups_table.php b/database/migrations/2026_01_01_000006_add_automation_columns_to_stepwise_follow_ups_table.php similarity index 70% rename from database/migrations/2026_01_01_000006_add_automation_columns_to_rehla_follow_ups_table.php rename to database/migrations/2026_01_01_000006_add_automation_columns_to_stepwise_follow_ups_table.php index d3bf97f..027f2e1 100644 --- a/database/migrations/2026_01_01_000006_add_automation_columns_to_rehla_follow_ups_table.php +++ b/database/migrations/2026_01_01_000006_add_automation_columns_to_stepwise_follow_ups_table.php @@ -11,7 +11,12 @@ /** Existing rows keep working: they become source "manual". */ public function up(): void { - Schema::table('rehla_follow_ups', function (Blueprint $table): void { + // Already there: an install upgraded from the former Rehla package. + if (Schema::hasColumn('stepwise_follow_ups', 'source')) { + return; + } + + Schema::table('stepwise_follow_ups', function (Blueprint $table): void { $table->string('source', 16)->default('manual')->after('status'); $table->unsignedBigInteger('rule_id')->nullable()->after('source'); $table->string('provider', 32)->nullable()->after('rule_id'); @@ -22,16 +27,16 @@ public function up(): void $table->unsignedSmallInteger('attempts')->default(0)->after('error_message'); $table->string('skip_reason')->nullable()->after('attempts'); $table->json('payload')->nullable()->after('skip_reason'); - $table->string('idempotency_key')->nullable()->unique('rehla_followups_idem_unique')->after('payload'); - $table->index('provider_message_id', 'rehla_followups_provider_msg_index'); + $table->string('idempotency_key')->nullable()->unique('stepwise_followups_idem_unique')->after('payload'); + $table->index('provider_message_id', 'stepwise_followups_provider_msg_index'); }); } public function down(): void { - Schema::table('rehla_follow_ups', function (Blueprint $table): void { - $table->dropUnique('rehla_followups_idem_unique'); - $table->dropIndex('rehla_followups_provider_msg_index'); + Schema::table('stepwise_follow_ups', function (Blueprint $table): void { + $table->dropUnique('stepwise_followups_idem_unique'); + $table->dropIndex('stepwise_followups_provider_msg_index'); $table->dropColumn([ 'source', 'rule_id', 'provider', 'provider_message_id', 'delivery_status', 'error_code', 'error_message', 'attempts', 'skip_reason', 'payload', 'idempotency_key', diff --git a/database/migrations/2026_01_01_000007_create_rehla_consents_table.php b/database/migrations/2026_01_01_000007_create_stepwise_consents_table.php similarity index 70% rename from database/migrations/2026_01_01_000007_create_rehla_consents_table.php rename to database/migrations/2026_01_01_000007_create_stepwise_consents_table.php index fdac292..e38a98b 100644 --- a/database/migrations/2026_01_01_000007_create_rehla_consents_table.php +++ b/database/migrations/2026_01_01_000007_create_stepwise_consents_table.php @@ -11,7 +11,12 @@ /** Append-only: the latest row per user and channel is the current state. */ public function up(): void { - Schema::create('rehla_consents', function (Blueprint $table): void { + // Already there: an install upgraded from the former Rehla package. + if (Schema::hasTable('stepwise_consents')) { + return; + } + + Schema::create('stepwise_consents', function (Blueprint $table): void { $table->id(); $table->string('trackable_type'); $table->unsignedBigInteger('trackable_id'); @@ -21,12 +26,12 @@ public function up(): void $table->text('evidence')->nullable(); $table->timestamps(); - $table->index(['trackable_type', 'trackable_id', 'channel', 'id'], 'rehla_consents_user_index'); + $table->index(['trackable_type', 'trackable_id', 'channel', 'id'], 'stepwise_consents_user_index'); }); } public function down(): void { - Schema::dropIfExists('rehla_consents'); + Schema::dropIfExists('stepwise_consents'); } }; diff --git a/database/migrations/2026_01_01_000008_create_rehla_automation_rules_table.php b/database/migrations/2026_01_01_000008_create_stepwise_automation_rules_table.php similarity index 71% rename from database/migrations/2026_01_01_000008_create_rehla_automation_rules_table.php rename to database/migrations/2026_01_01_000008_create_stepwise_automation_rules_table.php index 0809b40..52e69fa 100644 --- a/database/migrations/2026_01_01_000008_create_rehla_automation_rules_table.php +++ b/database/migrations/2026_01_01_000008_create_stepwise_automation_rules_table.php @@ -10,7 +10,12 @@ { public function up(): void { - Schema::create('rehla_automation_rules', function (Blueprint $table): void { + // Already there: an install upgraded from the former Rehla package. + if (Schema::hasTable('stepwise_automation_rules')) { + return; + } + + Schema::create('stepwise_automation_rules', function (Blueprint $table): void { $table->id(); $table->string('name'); $table->boolean('enabled')->default(true); @@ -26,12 +31,12 @@ public function up(): void $table->string('created_by')->nullable(); $table->timestamps(); - $table->index(['enabled', 'journey'], 'rehla_rules_enabled_journey'); + $table->index(['enabled', 'journey'], 'stepwise_rules_enabled_journey'); }); } public function down(): void { - Schema::dropIfExists('rehla_automation_rules'); + Schema::dropIfExists('stepwise_automation_rules'); } }; diff --git a/docs/ar/README.md b/docs/ar/README.md index 56d471a..e1bbcef 100644 --- a/docs/ar/README.md +++ b/docs/ar/README.md @@ -1,4 +1,4 @@ -# رحلة (Rehla) +# Stepwise اعرف كل مستخدم واقف فين في رحلة موقعك، ورجّع اللي وقف في النص. @@ -12,7 +12,7 @@ وفوق الجدول ده فيه تدفق لإعادة التواصل: زرار واتساب جنب كل مستخدم بيفتح نافذة فيها الاسم والرقم والرسالة، وبقالب جاهز مختار تلقائياً حسب مكان المستخدم — «شجّعه يكمّل» لو عنده خطوة بدأها، و«شجّعه يبدأ» لأول خطوة مابدأهاش. لما تأكد، بيفتح شات واتساب والرسالة جاهزة للإرسال. -واختيارياً، رحلة تقدر كمان تبعت التذكيرات تلقائياً (مقفول افتراضياً): قواعد زي «بدأ خطوة ومخلصهاش من يومين»، وموافقة ومعالجة STOP، وساعات هدوء وفترات انتظار، وتجربة بدون إرسال، وتاب في البانل، ومزوّدين: Meta WhatsApp Cloud API أو HTTP عام أو log. شوف قسم الإرسال التلقائي تحت. +واختيارياً، Stepwise تقدر كمان تبعت التذكيرات تلقائياً (مقفول افتراضياً): قواعد زي «بدأ خطوة ومخلصهاش من يومين»، وموافقة ومعالجة STOP، وساعات هدوء وفترات انتظار، وتجربة بدون إرسال، وتاب في البانل، ومزوّدين: Meta WhatsApp Cloud API أو HTTP عام أو log. شوف قسم الإرسال التلقائي تحت. > **الحالة: v0.5.0 قبل 1.0.** عليها اختبارات آلية (Pest وPHPStan مستوى 8 وPint، وCI على PHP 8.2 لـ8.4 مع Laravel 11 و12). طبقة الإرسال التلقائي متجربة على ردود ميتا/HTTP مزيّفة بس، فجرّبها برقمك وبمزوّد `log` الأول (شوف قايمة المراجعة تحت). الإصدارات الصغيرة قبل 1.0 ممكن تغيّر السلوك؛ شوف [CHANGELOG](../../CHANGELOG.md). @@ -24,17 +24,17 @@ ## التثبيت ```bash -composer require elbanbydev/rehla -php artisan rehla:install +composer require elbanbydev/stepwise +php artisan stepwise:install ``` -الأمر `rehla:install` بينشر `config/rehla.php` (لو مش موجود) وبيعمل جداول Rehla. تقدر تشغله تاني في أي وقت، بيطبق بس اللي لسه ماتطبقش. +الأمر `stepwise:install` بينشر `config/stepwise.php` (لو مش موجود) وبيعمل جداول Stepwise. تقدر تشغله تاني في أي وقت، بيطبق بس اللي لسه ماتطبقش. -Rehla بيسجّل الـ migrations بتاعته بنفسه، فمفيش `vendor:publish` ليهم: أمر النشر العادي `php artisan migrate` بياخدهم برضه. Composer مبيقدرش يشغّل migrations وقت `composer require` (باكيدجات لارافل ملهاش install hook، وتشغيل تغييرات داتابيز من سكريبت Composer مش آمن)، فلازم واحد من الأمرين يتشغل مرة واحدة. لو الجداول ناقصة، اللوحة بترد برسالة واضحة، والـ middleware بتاع التتبع بيسكت بدل ما يوقّع موقعك. +Stepwise بيسجّل الـ migrations بتاعته بنفسه، فمفيش `vendor:publish` ليهم: أمر النشر العادي `php artisan migrate` بياخدهم برضه. Composer مبيقدرش يشغّل migrations وقت `composer require` (باكيدجات لارافل ملهاش install hook، وتشغيل تغييرات داتابيز من سكريبت Composer مش آمن)، فلازم واحد من الأمرين يتشغل مرة واحدة. لو الجداول ناقصة، اللوحة بترد برسالة واضحة، والـ middleware بتاع التتبع بيسكت بدل ما يوقّع موقعك. ## عرّف الرحلة بتاعتك -في `config/rehla.php`: +في `config/stepwise.php`: ```php 'journeys' => [ @@ -54,20 +54,20 @@ Rehla بيسجّل الـ migrations بتاعته بنفسه، فمفيش `vendo ## تتبّع التقدم ```php -use Rehla\Facades\Rehla; +use Stepwise\Facades\Stepwise; -Rehla::start($user, 'profile'); // المستخدم بدأ الخطوة -Rehla::complete($user, 'profile'); // المستخدم خلّصها -Rehla::reset($user, step: 'profile'); // انسَ خطوة واحدة -Rehla::reset($user); // انسَ الرحلة كلها +Stepwise::start($user, 'profile'); // المستخدم بدأ الخطوة +Stepwise::complete($user, 'profile'); // المستخدم خلّصها +Stepwise::reset($user, step: 'profile'); // انسَ خطوة واحدة +Stepwise::reset($user); // انسَ الرحلة كلها -$summary = Rehla::progress($user); +$summary = Stepwise::progress($user); $summary->completedSteps; // ['account'] $summary->startedSteps; // ['profile'] $summary->notStartedSteps; // ['first-order'] ``` -كل التحولات idempotent: بدء خطوة مبدوءة (أو إكمال مكتملة) مبيغيرش حاجة ومبيطلعش حدث. إكمال خطوة مابدأتش بيسجّل التاريخين. الحدثان `Rehla\Events\StepStarted` و`Rehla\Events\StepCompleted` بيطلعوا عند التحول الحقيقي بس. +كل التحولات idempotent: بدء خطوة مبدوءة (أو إكمال مكتملة) مبيغيرش حاجة ومبيطلعش حدث. إكمال خطوة مابدأتش بيسجّل التاريخين. الحدثان `Stepwise\Events\StepStarted` و`Stepwise\Events\StepCompleted` بيطلعوا عند التحول الحقيقي بس. ## تتبّع آخر زيارة @@ -75,43 +75,43 @@ $summary->notStartedSteps; // ['first-order'] ```php ->withMiddleware(function (Middleware $middleware) { - $middleware->appendToGroup('web', [\Rehla\Http\Middleware\RecordActivity::class]); + $middleware->appendToGroup('web', [\Stepwise\Http\Middleware\RecordActivity::class]); }) ``` -أو بالاسم المختصر `rehla.activity`. أي طلب من مستخدم مسجّل بيحدّث `last_seen_at`، مع خنق (throttle) من `rehla.activity.throttle_seconds` (افتراضياً 300) عشان الجلسة النشيطة متكلفش أكتر من كتابة واحدة في الفترة. الزوار غير المسجلين مبيتتبعوش. +أو بالاسم المختصر `stepwise.activity`. أي طلب من مستخدم مسجّل بيحدّث `last_seen_at`، مع خنق (throttle) من `stepwise.activity.throttle_seconds` (افتراضياً 300) عشان الجلسة النشيطة متكلفش أكتر من كتابة واحدة في الفترة. الزوار غير المسجلين مبيتتبعوش. ## افتح اللوحة -اللوحة مقفولة لحد ما تسمّي صلاحية Gate في `rehla.panel.gate` (الافتراضي `viewRehla`) وتعرّفها: +اللوحة مقفولة لحد ما تسمّي صلاحية Gate في `stepwise.panel.gate` (الافتراضي `viewStepwise`) وتعرّفها: ```php -Gate::define('viewRehla', fn (User $user) => $user->isAdmin()); +Gate::define('viewStepwise', fn (User $user) => $user->isAdmin()); ``` -وبعدين افتح `/rehla` (المسار قابل للتغيير). الجدول بيعرض لكل مستخدم: الاسم، وأعمدة تانية تختارها (`rehla.user_columns` زي الإيميل والدور)، والأعمدة الثلاثة بتاعة الرحلة كشارات ملونة. الفلتر فوق الجدول معناه «لم يزر الموقع منذ N يوم»: +وبعدين افتح `/stepwise` (المسار قابل للتغيير). الجدول بيعرض لكل مستخدم: الاسم، وأعمدة تانية تختارها (`stepwise.user_columns` زي الإيميل والدور)، والأعمدة الثلاثة بتاعة الرحلة كشارات ملونة. الفلتر فوق الجدول معناه «لم يزر الموقع منذ N يوم»: - **صفر** بيعرض الكل، حتى لواحد سجّل من ثواني. - **N** بيعرض بس اللي مفيش ليهم زيارة مسجلة في آخر N يوم. اللي ماعملوش أي زيارة بيتحسب من تاريخ التسجيل. ## إعادة التواصل عبر واتساب -كل صف ليه رقم بياخد زرار واتساب. النافذة بتعرض اسم المستخدم، الرقم (بيتحوّل لصيغة wa.me: الرقم المحلي `0107…` بيبقى `20107…` عن طريق `rehla.whatsapp.default_country_code`)، وقائمة القوالب، ونص الرسالة. التأكيد بيفتح `https://wa.me/<الرقم>?text=<الرسالة>` في تاب جديد — مفيش رسالة بتتبعت غير لما إنسان يدوس إرسال جوه واتساب نفسه. +كل صف ليه رقم بياخد زرار واتساب. النافذة بتعرض اسم المستخدم، الرقم (بيتحوّل لصيغة wa.me: الرقم المحلي `0107…` بيبقى `20107…` عن طريق `stepwise.whatsapp.default_country_code`)، وقائمة القوالب، ونص الرسالة. التأكيد بيفتح `https://wa.me/<الرقم>?text=<الرسالة>` في تاب جديد — مفيش رسالة بتتبعت غير لما إنسان يدوس إرسال جوه واتساب نفسه. -القوالب بتتدار من `/rehla/templates`: عنوان + محتوى، وربط اختياري بخطوة معينة في رحلة معينة، وواحد من نوعين: +القوالب بتتدار من `/stepwise/templates`: عنوان + محتوى، وربط اختياري بخطوة معينة في رحلة معينة، وواحد من نوعين: - **تشجيع على إكمال الخطوة** — بيتختار تلقائياً لما يكون المستخدم بدأ الخطوة دي وماكملهاش. - **تشجيع على بدء الخطوة** — بيتختار لأول خطوة مابدأهاش، لما المستخدم ماعندوش خطوة في النص. النافذة بتختار بالقاعدة دي (أحدث قالب مطابق بيكسب) والأدمن يقدر يختار قالب تاني أو يعدّل النص قبل ما يفتح واتساب. القوالب العامة (غير المرتبطة بخطوة) مبتتختارش تلقائياً أبداً. -ظبط `rehla.phone_attribute` (افتراضياً `phone`) و`rehla.name_attribute` (افتراضياً `name`) على موديل المستخدم بتاعك. ولو كتبت `{name}` جوه نص القالب، بتتبدل باسم المستخدم لما النافذة تملأ الرسالة. +ظبط `stepwise.phone_attribute` (افتراضياً `phone`) و`stepwise.name_attribute` (افتراضياً `name`) على موديل المستخدم بتاعك. ولو كتبت `{name}` جوه نص القالب، بتتبدل باسم المستخدم لما النافذة تملأ الرسالة. ## تتبّع المتابعة لما يكون أكتر من واحد معاهم صلاحية المتابعة، محدش المفروض يبعت لنفس المستخدم مرتين. عشان كده رحلة بيسجّل كل متابعة لحظة ما الأدمن يأكد نافذة الواتساب: مين بعت، إمتى، نص الرسالة بالظبط، والموضوع (عنوان القالب بيتسجّل كـ snapshot، فالسجل بيفضل سليم حتى لو القالب اتعدّل أو اتمسح). -عمود **آخر متابعة** جنب **آخر زيارة** في الجدول، وزرار **(i)** في كل صف بيفتح نافذة سجل كامل: كل رسالة اتبعتت للمستخدم ده، الأحدث الأول. التسجيل بيحصل على أساس best-effort ولا يمنع فتح واتساب أبداً. ظبط `rehla.follow_up.confirm_sent` على `false` لو عاوز تتخطى خطوة التأكيد: فتح واتساب وقتها بيسجّل المتابعة «اتبعتت» على طول. +عمود **آخر متابعة** جنب **آخر زيارة** في الجدول، وزرار **(i)** في كل صف بيفتح نافذة سجل كامل: كل رسالة اتبعتت للمستخدم ده، الأحدث الأول. التسجيل بيحصل على أساس best-effort ولا يمنع فتح واتساب أبداً. ظبط `stepwise.follow_up.confirm_sent` على `false` لو عاوز تتخطى خطوة التأكيد: فتح واتساب وقتها بيسجّل المتابعة «اتبعتت» على طول. فتح واتساب مش معناه إن الرسالة اتبعتت. السجل بيبدأ "غير مؤكد"، ولما الأدمن يرجع النافذة بتسأله "بعتّها فعلاً؟" (وممكن يصحح النص). المتابعات المؤكدة بس هي اللي بتتحسب "آخر متابعة" وبتطلّع تحذير "اتابع قريب". المسودات اللي اتساب بتفضل في السجل بعلامة "ماتبعتتش". @@ -120,14 +120,14 @@ Gate::define('viewRehla', fn (User $user) => $user->isAdmin()); لما التطبيق يمسح مستخدم، امسح بيانات رحلته كمان: ```php -Rehla::forget($user); // بيمسح سجلات التقدم وآخر زيارة +Stepwise::forget($user); // بيمسح سجلات التقدم وآخر زيارة ``` ## تقرير Artisan ```bash -php artisan rehla:report # كل الرحلات -php artisan rehla:report onboarding # رحلة واحدة +php artisan stepwise:report # كل الرحلات +php artisan stepwise:report onboarding # رحلة واحدة ``` بيطبع لكل خطوة: كام مستخدم خلّصها، وكام بدأها وماكملهاش، وكام مابدأهاش أصلاً. @@ -138,6 +138,10 @@ php artisan rehla:report onboarding # رحلة واحدة composer check # pint --test, phpstan level 8, pest ``` +## الترقية من Rehla + +Stepwise كان اسمه Rehla لحد v0.5.0. لو كنت منزّل `elbanbydev/rehla`، شوف جدول تغيير الأسماء في [CHANGELOG](../../CHANGELOG.md#unreleased). باختصار: `composer remove elbanbydev/rehla && composer require elbanbydev/stepwise`، وغيّر اسم `config/rehla.php` لـ `config/stepwise.php`، وبدّل `Rehla\` بـ `Stepwise\` و`REHLA_*` بـ `STEPWISE_*` والـ Gate من `viewRehla` لـ `viewStepwise`، وحدّث رابط الـ webhook في ميتا، وبعدين `php artisan migrate` (الجداول بتتغيّر أسماؤها والبيانات بتفضل). + ## الترخيص MIT. شوف [LICENSE.md](../../LICENSE.md). @@ -145,42 +149,42 @@ MIT. شوف [LICENSE.md](../../LICENSE.md). ## الإرسال التلقائي على واتساب (اختياري) -المتابعة اليدوية زي ما هي. الإرسال التلقائي طبقة منفصلة واختيارية و**مقفولة افتراضياً**. كل إعداد موجود في `config/rehla.php` والـ env الأول، وإظهار أي حاجة منها في البانل قرارك أنت. +المتابعة اليدوية زي ما هي. الإرسال التلقائي طبقة منفصلة واختيارية و**مقفولة افتراضياً**. كل إعداد موجود في `config/stepwise.php` والـ env الأول، وإظهار أي حاجة منها في البانل قرارك أنت. ```env -REHLA_AUTOMATION_ENABLED=true -REHLA_AUTOMATION_PROVIDER=log # log (تجريبي), meta, http, أو بتاعك -REHLA_META_PHONE_NUMBER_ID=... -REHLA_META_ACCESS_TOKEN=... -REHLA_META_VERIFY_TOKEN=... # للـ webhook -REHLA_META_APP_SECRET=... +STEPWISE_AUTOMATION_ENABLED=true +STEPWISE_AUTOMATION_PROVIDER=log # log (تجريبي), meta, http, أو بتاعك +STEPWISE_META_PHONE_NUMBER_ID=... +STEPWISE_META_ACCESS_TOKEN=... +STEPWISE_META_VERIFY_TOKEN=... # للـ webhook +STEPWISE_META_APP_SECRET=... ``` -مقدّمو الخدمة (`rehla.automation.providers`): +مقدّمو الخدمة (`stepwise.automation.providers`): - `log`: تجربة. بيسجّل الرسالة في اللوج ومبيبعتش حاجة. سجلاته بتتعلّم "تجريبي" ومبتتحسبش متابعة حقيقية. ابدأ بيه. -- `meta`: واجهة WhatsApp Business Cloud. برّه نافذة الـ24 ساعة ميتا بتقبل قوالب معتمدة بس، فالرسائل التلقائية محتاجة اسم قالب. النص الحر بيشتغل جوه النافذة بس. ميتا بتحاسب على كل رسالة حسب الفئة، وأنت بتدفع لميتا مش لـ Rehla. +- `meta`: واجهة WhatsApp Business Cloud. برّه نافذة الـ24 ساعة ميتا بتقبل قوالب معتمدة بس، فالرسائل التلقائية محتاجة اسم قالب. النص الحر بيشتغل جوه النافذة بس. ميتا بتحاسب على كل رسالة حسب الفئة، وأنت بتدفع لميتا مش لـ Stepwise. - `http`: أي خدمة بتقبل طلب HTTP. الـ body مصفوفة في الكونفيج فيها `{phone}` و`{message}` و`{template}` و`{language}` و`{idempotency_key}`. HTTPS بس، والعناوين الخاصة والـ loopback مرفوضة إلا لو قفلت ده للتطوير. -- بتاعك: `app(Rehla\Automation\ProviderManager::class)->extend('acme', fn (array $config) => new AcmeProvider(...))` وبعدين `'driver' => 'acme'` في الكونفيج. +- بتاعك: `app(Stepwise\Automation\ProviderManager::class)->extend('acme', fn (array $config) => new AcmeProvider(...))` وبعدين `'driver' => 'acme'` في الكونفيج. -الإرسال بيشتغل على الـ queue بتاعك (`rehla.automation.queue`)، فلازم يكون عندك queue worker شغال. الأعطال المؤقتة (timeout أو 429 أو 5xx) بتتعاد بالمهل في `rehla.automation.retry.backoff_seconds` (بالثواني: 60 = دقيقة، 3600 = ساعة)، والدائمة بتتعلّم فاشلة مع سبب المزوّد. كل إرسال تلقائي بيتسجّل في نفس سجل المتابعات زي اليدوي وعليه علامة "تلقائي". +الإرسال بيشتغل على الـ queue بتاعك (`stepwise.automation.queue`)، فلازم يكون عندك queue worker شغال. الأعطال المؤقتة (timeout أو 429 أو 5xx) بتتعاد بالمهل في `stepwise.automation.retry.backoff_seconds` (بالثواني: 60 = دقيقة، 3600 = ساعة)، والدائمة بتتعلّم فاشلة مع سبب المزوّد. كل إرسال تلقائي بيتسجّل في نفس سجل المتابعات زي اليدوي وعليه علامة "تلقائي". -الموافقة الأول. افتراضياً Rehla بتبعت للمستخدمين اللي وافقوا بس (`rehla.consent.required`). وميتا كمان بتشترط الموافقة: https://developers.facebook.com/docs/whatsapp/overview/getting-opt-in/ +الموافقة الأول. افتراضياً Stepwise بتبعت للمستخدمين اللي وافقوا بس (`stepwise.consent.required`). وميتا كمان بتشترط الموافقة: https://developers.facebook.com/docs/whatsapp/overview/getting-opt-in/ ```php -Rehla::consent()->optIn($user, 'signup_form', 'ticked the box'); -Rehla::consent()->optOut($user); // وكمان بيلغي الرسائل التلقائية الواقفة في الطابور +Stepwise::consent()->optIn($user, 'signup_form', 'ticked the box'); +Stepwise::consent()->optOut($user); // وكمان بيلغي الرسائل التلقائية الواقفة في الطابور ``` -مصدر الموافقة (`rehla.consent.source`): `table` (النداءات اللي فوق، آخر قرار هو المعتمد والتاريخ محفوظ)، أو `attribute` (عمود أو accessor قيمته صحيحة، اسمه في `attribute`)، أو `resolver` (كلاس بيطبّق `Rehla\Contracts\ConsentResolver`). أي إيقاف متسجّل عن طريق Rehla بيمنع الإرسال مهما كان المصدر. خلّي `required` بـ `false` بس لو بتجمع الموافقة من مكان تاني. و`Rehla::forget($user)` بيمسح تاريخ الموافقة كمان. +مصدر الموافقة (`stepwise.consent.source`): `table` (النداءات اللي فوق، آخر قرار هو المعتمد والتاريخ محفوظ)، أو `attribute` (عمود أو accessor قيمته صحيحة، اسمه في `attribute`)، أو `resolver` (كلاس بيطبّق `Stepwise\Contracts\ConsentResolver`). أي إيقاف متسجّل عن طريق Stepwise بيمنع الإرسال مهما كان المصدر. خلّي `required` بـ `false` بس لو بتجمع الموافقة من مكان تاني. و`Stepwise::forget($user)` بيمسح تاريخ الموافقة كمان. -الـ webhook (حالة التسليم وردود STOP). بيتسجّل بس لما الـ meta يكون عنده `REHLA_META_VERIFY_TOKEN` و`REHLA_META_APP_SECRET`. وجّه ميتا على `https://your-app/rehla/webhooks/meta` (`rehla.webhooks.path` و`rehla.webhooks.middleware`). أي طلب من غير `X-Hub-Signature-256` صحيح بيترفض. حالات التسليم بتتحرك لقدّام بس (sent ثم delivered ثم read)، والفشل بيتسجّل مع سبب ميتا. المستخدم اللي يرد بكلمة إيقاف (`rehla.webhooks.stop_keywords`، عربي وإنجليزي افتراضياً، لازم الرسالة كلها تطابق، وأشكال الهمزة متساوية) بيتعمله إيقاف. و`start_keywords` و`stop_reply` / `start_reply` اختيارية وكلها في الكونفيج. مطابقة الرقم بمستخدم محتاجة `rehla.phone_attribute` يكون عمود حقيقي. مرجع ميتا: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/messages/ +الـ webhook (حالة التسليم وردود STOP). بيتسجّل بس لما الـ meta يكون عنده `STEPWISE_META_VERIFY_TOKEN` و`STEPWISE_META_APP_SECRET`. وجّه ميتا على `https://your-app/stepwise/webhooks/meta` (`stepwise.webhooks.path` و`stepwise.webhooks.middleware`). أي طلب من غير `X-Hub-Signature-256` صحيح بيترفض. حالات التسليم بتتحرك لقدّام بس (sent ثم delivered ثم read)، والفشل بيتسجّل مع سبب ميتا. المستخدم اللي يرد بكلمة إيقاف (`stepwise.webhooks.stop_keywords`، عربي وإنجليزي افتراضياً، لازم الرسالة كلها تطابق، وأشكال الهمزة متساوية) بيتعمله إيقاف. و`start_keywords` و`stop_reply` / `start_reply` اختيارية وكلها في الكونفيج. مطابقة الرقم بمستخدم محتاجة `stepwise.phone_attribute` يكون عمود حقيقي. مرجع ميتا: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/messages/ في البانل المستخدمين اللي عملوا إيقاف عليهم علامة "أوقف الرسائل"، والمودال بيطلب تأكيد صريح قبل رسالة يدوية ليهم. ### القواعد والمحرّك -القواعد بتحدد مين ياخد أنهي رسالة وإمتى. عرّفها في `rehla.automation.rules` (في الكود، متاحة دايماً) أو في جدول `rehla_automation_rules` (بتتدار من تاب الأتمتة في البانل). الاتنين بيشتغلوا مع بعض. +القواعد بتحدد مين ياخد أنهي رسالة وإمتى. عرّفها في `stepwise.automation.rules` (في الكود، متاحة دايماً) أو في جدول `stepwise_automation_rules` (بتتدار من تاب الأتمتة في البانل). الاتنين بيشتغلوا مع بعض. ```php 'rules' => [ @@ -202,23 +206,23 @@ Rehla::consent()->optOut($user); // وكمان بيلغي الرسائل شغّله من الـscheduler (كل 5 لـ15 دقيقة) وابدأ بتجربة: ```php -Schedule::command('rehla:automate')->everyTenMinutes(); +Schedule::command('stepwise:automate')->everyTenMinutes(); ``` ```bash -php artisan rehla:automate --dry-run # مين هيتبعتله ومين اتخطّى وليه -php artisan rehla:automate --rule=stuck-profile +php artisan stepwise:automate --dry-run # مين هيتبعتله ومين اتخطّى وليه +php artisan stepwise:automate --rule=stuck-profile ``` -الحمايات بالترتيب، وكل تخطّي بيتعدّ بسببه: رقم صالح، الموافقة (ومفيش إيقاف)، ساعات الهدوء، فترة الانتظار، قفل اليدوي، مستني في الطابور، أقصى عدد رسائل للمستخدم، وبعدين الحدود العامة. كلها في `rehla.automation`: `quiet_hours` (الافتراضي 21:00 لـ09:00 بتوقيت التطبيق، وعمود توقيت لكل مستخدم اختياري)، و`cooldown_hours` (72، أو لكل قاعدة)، و`manual_lock_hours` (2: مسودة واتساب مفتوحة عند أدمن بتوقّف الأتمتة)، و`limits` (`per_hour` و`per_day` و`per_run`؛ 0 بيقفل الحد). قبل الإرسال مباشرة، الـjob بيلغي الرسالة لو أدمن بعت للمستخدم يدوي في الوقت ده. +الحمايات بالترتيب، وكل تخطّي بيتعدّ بسببه: رقم صالح، الموافقة (ومفيش إيقاف)، ساعات الهدوء، فترة الانتظار، قفل اليدوي، مستني في الطابور، أقصى عدد رسائل للمستخدم، وبعدين الحدود العامة. كلها في `stepwise.automation`: `quiet_hours` (الافتراضي 21:00 لـ09:00 بتوقيت التطبيق، وعمود توقيت لكل مستخدم اختياري)، و`cooldown_hours` (72، أو لكل قاعدة)، و`manual_lock_hours` (2: مسودة واتساب مفتوحة عند أدمن بتوقّف الأتمتة)، و`limits` (`per_hour` و`per_day` و`per_run`؛ 0 بيقفل الحد). قبل الإرسال مباشرة، الـjob بيلغي الرسالة لو أدمن بعت للمستخدم يدوي في الوقت ده. -في البانل تاب **الأتمتة**: قواعد من الداتابيز (إضافة وتعديل وتشغيل وإيقاف وحذف)، وقواعد الكونفيج (للقراءة بس)، ومعاينة تجريبية لكل قاعدة (مين هيتبعتله دلوقتي ومين اتخطّى وليه)، وآخر 50 رسالة تلقائية مع حالة التسليم. اختياري: خلّي `rehla.panel.automation_tab` بـ `false` عشان تخفيه وتقفل مساراته. وكل اللي بيعمله ممكن من الكونفيج و`rehla:automate`. +في البانل تاب **الأتمتة**: قواعد من الداتابيز (إضافة وتعديل وتشغيل وإيقاف وحذف)، وقواعد الكونفيج (للقراءة بس)، ومعاينة تجريبية لكل قاعدة (مين هيتبعتله دلوقتي ومين اتخطّى وليه)، وآخر 50 رسالة تلقائية مع حالة التسليم. اختياري: خلّي `stepwise.panel.automation_tab` بـ `false` عشان تخفيه وتقفل مساراته. وكل اللي بيعمله ممكن من الكونفيج و`stepwise:automate`. ### قبل المستخدمين الحقيقيين (قايمة مراجعة) -1. ابدأ بـ `REHLA_AUTOMATION_PROVIDER=log` و`php artisan rehla:automate --dry-run`، واقرا المعاينة في تاب الأتمتة. -2. اجمع الموافقة (`Rehla::consent()->optIn($user)` لما المستخدم يوافق)، وسيب `rehla.consent.required` شغّال. +1. ابدأ بـ `STEPWISE_AUTOMATION_PROVIDER=log` و`php artisan stepwise:automate --dry-run`، واقرا المعاينة في تاب الأتمتة. +2. اجمع الموافقة (`Stepwise::consent()->optIn($user)` لما المستخدم يوافق)، وسيب `stepwise.consent.required` شغّال. 3. اعمل قوالب ميتا واعتمدها من Meta Business Manager، واربطها بـ `provider_template`. 4. فعّل الـ webhook (verify token وapp secret) عشان ردود STOP وحالة التسليم تشتغل، وجرّبه برقم بتاعك. -5. شغّل queue worker والـ scheduler (`rehla:automate` كل 5 لـ15 دقيقة). +5. شغّل queue worker والـ scheduler (`stepwise:automate` كل 5 لـ15 دقيقة). 6. ابعت لرقمك الأول بقاعدة محدودة بـ `limits.per_run`. -7. اختياري: `rehla.automation.retention_days` مع `Schedule::command('rehla:prune')->daily()` لمسح الصفوف التلقائية القديمة. والرسائل الواقفة في الطابور ومشتغلتش بتتلغي بعد `stale_queued_hours` (24). +7. اختياري: `stepwise.automation.retention_days` مع `Schedule::command('stepwise:prune')->daily()` لمسح الصفوف التلقائية القديمة. والرسائل الواقفة في الطابور ومشتغلتش بتتلغي بعد `stale_queued_hours` (24). diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b76b855..db697a0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,7 +5,7 @@ colors="true" cacheDirectory=".phpunit.cache"> - + tests diff --git a/resources/lang/ar/rehla.php b/resources/lang/ar/stepwise.php similarity index 95% rename from resources/lang/ar/rehla.php rename to resources/lang/ar/stepwise.php index ed13323..a4ddf4b 100644 --- a/resources/lang/ar/rehla.php +++ b/resources/lang/ar/stepwise.php @@ -20,7 +20,7 @@ 'last_visit' => 'آخر زيارة', 'last_followup' => 'آخر متابعة', 'never_followup' => 'لسه', - 'missing_tables' => 'جداول Rehla مش موجودة. شغّل: php artisan rehla:install', + 'missing_tables' => 'جداول Stepwise مش موجودة. شغّل: php artisan stepwise:install', 'confirm' => [ 'question' => 'بعتّها فعلاً على واتساب؟', 'actual_text' => 'النص اللي بعتّه فعلاً', @@ -86,7 +86,7 @@ 'encourage_start' => 'تشجيع على بدء الخطوة', ], 'validation' => [ - 'unknown_journey' => 'هذه الرحلة غير معرّفة في إعدادات rehla.journeys.', + 'unknown_journey' => 'هذه الرحلة غير معرّفة في إعدادات stepwise.journeys.', 'opted_out' => 'المستخدم ده طلب إيقاف رسائل واتساب.', 'unknown_user' => 'هذا المستخدم غير موجود.', 'unknown_step' => 'هذه الخطوة غير معرّفة في الرحلة المختارة.', @@ -119,7 +119,7 @@ 'empty' => 'مفيش قواعد لسه.', 'no_history' => 'مفيش رسائل تلقائية لسه.', 'confirm_delete' => 'تمسح القاعدة دي؟', - 'disabled_notice' => 'الأتمتة مقفولة (rehla.automation.enabled). القواعد محفوظة بس مفيش حاجة هتتبعت.', + 'disabled_notice' => 'الأتمتة مقفولة (stepwise.automation.enabled). القواعد محفوظة بس مفيش حاجة هتتبعت.', 'provider_hint' => 'المزوّد: :provider', 'any_step' => 'الخطوة المستحقة عليه', 'after' => 'بعد', diff --git a/resources/lang/en/rehla.php b/resources/lang/en/stepwise.php similarity index 95% rename from resources/lang/en/rehla.php rename to resources/lang/en/stepwise.php index 5f7265a..2efbb60 100644 --- a/resources/lang/en/rehla.php +++ b/resources/lang/en/stepwise.php @@ -20,7 +20,7 @@ 'last_visit' => 'Last visit', 'last_followup' => 'Last follow-up', 'never_followup' => 'Never', - 'missing_tables' => 'Rehla tables are missing. Run: php artisan rehla:install', + 'missing_tables' => 'Stepwise tables are missing. Run: php artisan stepwise:install', 'confirm' => [ 'question' => 'Did you actually send it in WhatsApp?', 'actual_text' => 'The text you actually sent', @@ -86,7 +86,7 @@ 'encourage_start' => 'Encourage to start the step', ], 'validation' => [ - 'unknown_journey' => 'This journey is not defined in the rehla.journeys config.', + 'unknown_journey' => 'This journey is not defined in the stepwise.journeys config.', 'opted_out' => 'This user opted out of WhatsApp messages.', 'unknown_user' => 'This user does not exist.', 'unknown_step' => 'This step is not defined in the chosen journey.', @@ -119,7 +119,7 @@ 'empty' => 'No rules yet.', 'no_history' => 'No automatic messages yet.', 'confirm_delete' => 'Delete this rule?', - 'disabled_notice' => 'Automation is off (rehla.automation.enabled). Rules are kept but nothing will be sent.', + 'disabled_notice' => 'Automation is off (stepwise.automation.enabled). Rules are kept but nothing will be sent.', 'provider_hint' => 'Provider: :provider', 'any_step' => 'The step they are due on', 'after' => 'After', diff --git a/resources/views/automation/_form.blade.php b/resources/views/automation/_form.blade.php index 4ce2826..e9c8e38 100644 --- a/resources/views/automation/_form.blade.php +++ b/resources/views/automation/_form.blade.php @@ -1,5 +1,5 @@ -@php($registry = app(\Rehla\Services\JourneyRegistry::class)) -@php($templates = \Rehla\Models\RehlaTemplate::query()->orderBy('title')->get()) +@php($registry = app(\Stepwise\Services\JourneyRegistry::class)) +@php($templates = \Stepwise\Models\StepwiseTemplate::query()->orderBy('title')->get()) @php($rule = $rule ?? null) @php($hours = (int) ($rule->after_hours ?? 48)) @php($unit = $hours % 168 === 0 ? 'weeks' : ($hours % 24 === 0 ? 'days' : 'hours')) @@ -15,12 +15,12 @@ @endif
- +
- + - + @foreach($registry->keys() as $key) @foreach($registry->steps($key) as $stepKey => $stepLabel) @@ -41,26 +41,26 @@
- +
- +
- + - {{ __('rehla::rehla.automation.placeholders') }} + {{ __('stepwise::stepwise.automation.placeholders') }}
- +
- +
- + - {{ __('rehla::rehla.automation.meta_hint') }} + {{ __('stepwise::stepwise.automation.meta_hint') }}
- +
diff --git a/resources/views/automation/create.blade.php b/resources/views/automation/create.blade.php index c12cc8a..f86cc88 100644 --- a/resources/views/automation/create.blade.php +++ b/resources/views/automation/create.blade.php @@ -1,12 +1,12 @@ -@extends('rehla::layout') +@extends('stepwise::layout') -@section('title', __('rehla::rehla.automation.create')) +@section('title', __('stepwise::stepwise.automation.create')) @section('content') -

{{ __('rehla::rehla.automation.create') }}

-
+

{{ __('stepwise::stepwise.automation.create') }}

+ @csrf - @include('rehla::automation._form') - + @include('stepwise::automation._form') +
@endsection diff --git a/resources/views/automation/edit.blade.php b/resources/views/automation/edit.blade.php index 6cf71c1..f7dce3d 100644 --- a/resources/views/automation/edit.blade.php +++ b/resources/views/automation/edit.blade.php @@ -1,13 +1,13 @@ -@extends('rehla::layout') +@extends('stepwise::layout') -@section('title', __('rehla::rehla.automation.edit')) +@section('title', __('stepwise::stepwise.automation.edit')) @section('content') -

{{ __('rehla::rehla.automation.edit') }}

-
+

{{ __('stepwise::stepwise.automation.edit') }}

+ @method('PUT') @csrf - @include('rehla::automation._form') - + @include('stepwise::automation._form') +
@endsection diff --git a/resources/views/automation/index.blade.php b/resources/views/automation/index.blade.php index 4c0487d..67420fd 100644 --- a/resources/views/automation/index.blade.php +++ b/resources/views/automation/index.blade.php @@ -1,71 +1,71 @@ -@extends('rehla::layout') +@extends('stepwise::layout') -@section('title', __('rehla::rehla.automation.title')) +@section('title', __('stepwise::stepwise.automation.title')) @section('content') @unless($automationEnabled) -
{{ __('rehla::rehla.automation.disabled_notice') }}
+
{{ __('stepwise::stepwise.automation.disabled_notice') }}
@endunless
- {{ __('rehla::rehla.automation.new') }} - {{ __('rehla::rehla.automation.provider_hint', ['provider' => $provider]) }} + {{ __('stepwise::stepwise.automation.new') }} + {{ __('stepwise::stepwise.automation.provider_hint', ['provider' => $provider]) }}
-

{{ __('rehla::rehla.automation.rules') }}

+

{{ __('stepwise::stepwise.automation.rules') }}

- - - - + + + + @foreach($configRules as $rule) - - - - + + + + @endforeach @foreach($dbRules as $rule) - - + + @endforeach @if(count($configRules) + count($dbRules) === 0) - + @endif
{{ __('rehla::rehla.automation.name') }}{{ __('rehla::rehla.automation.condition') }}{{ __('rehla::rehla.automation.status') }}{{ __('rehla::rehla.templates.actions') }}{{ __('stepwise::stepwise.automation.name') }}{{ __('stepwise::stepwise.automation.condition') }}{{ __('stepwise::stepwise.automation.status') }}{{ __('stepwise::stepwise.templates.actions') }}
{{ $rule->name }} {{ __('rehla::rehla.automation.from_config') }}{{ __('rehla::rehla.automation.conditions.'.$rule->condition) }} · {{ $rule->journey }}{{ $rule->step ? ' / '.$rule->step : '' }} · {{ $rule->afterHours }}h{{ __('rehla::rehla.automation.on') }}{{ __('rehla::rehla.automation.preview') }}{{ $rule->name }} {{ __('stepwise::stepwise.automation.from_config') }}{{ __('stepwise::stepwise.automation.conditions.'.$rule->condition) }} · {{ $rule->journey }}{{ $rule->step ? ' / '.$rule->step : '' }} · {{ $rule->afterHours }}h{{ __('stepwise::stepwise.automation.on') }}{{ __('stepwise::stepwise.automation.preview') }}
{{ $rule->name }}{{ __('rehla::rehla.automation.conditions.'.$rule->condition) }} · {{ $rule->journey }}{{ $rule->step ? ' / '.$rule->step : '' }} · {{ $rule->after_hours }}h{{ $rule->enabled ? __('rehla::rehla.automation.on') : __('rehla::rehla.automation.off') }}{{ __('stepwise::stepwise.automation.conditions.'.$rule->condition) }} · {{ $rule->journey }}{{ $rule->step ? ' / '.$rule->step : '' }} · {{ $rule->after_hours }}h{{ $rule->enabled ? __('stepwise::stepwise.automation.on') : __('stepwise::stepwise.automation.off') }} - {{ __('rehla::rehla.automation.preview') }} - {{ __('rehla::rehla.automation.edit') }} -
+ {{ __('stepwise::stepwise.automation.preview') }} + {{ __('stepwise::stepwise.automation.edit') }} + @csrf - +
-
+ @csrf @method('DELETE') - +
{{ __('rehla::rehla.automation.empty') }}
{{ __('stepwise::stepwise.automation.empty') }}
-

{{ __('rehla::rehla.automation.history') }}

+

{{ __('stepwise::stepwise.automation.history') }}

- - - - + + + + @@ -77,7 +77,7 @@ @empty - + @endforelse
{{ __('rehla::rehla.automation.when') }}{{ __('rehla::rehla.automation.user') }}{{ __('rehla::rehla.automation.status') }}{{ __('rehla::rehla.automation.message') }}{{ __('stepwise::stepwise.automation.when') }}{{ __('stepwise::stepwise.automation.user') }}{{ __('stepwise::stepwise.automation.status') }}{{ __('stepwise::stepwise.automation.message') }}
{{ \Illuminate\Support\Str::limit($row->message, 120) }}
{{ __('rehla::rehla.automation.no_history') }}
{{ __('stepwise::stepwise.automation.no_history') }}
diff --git a/resources/views/automation/preview.blade.php b/resources/views/automation/preview.blade.php index d1c7ecc..81ae291 100644 --- a/resources/views/automation/preview.blade.php +++ b/resources/views/automation/preview.blade.php @@ -1,17 +1,17 @@ -@extends('rehla::layout') +@extends('stepwise::layout') -@section('title', __('rehla::rehla.automation.preview')) +@section('title', __('stepwise::stepwise.automation.preview')) @section('content') -

← {{ __('rehla::rehla.automation.title') }}

-

{{ __('rehla::rehla.automation.preview') }}: {{ $key }}

-

{{ __('rehla::rehla.automation.preview_hint') }}

+

← {{ __('stepwise::stepwise.automation.title') }}

+

{{ __('stepwise::stepwise.automation.preview') }}: {{ $key }}

+

{{ __('stepwise::stepwise.automation.preview_hint') }}

@if(isset($report->skipped['automation_disabled'])) -
{{ __('rehla::rehla.automation.disabled_notice') }}
+
{{ __('stepwise::stepwise.automation.disabled_notice') }}
@endif -

{{ __('rehla::rehla.automation.would_send', ['count' => count($report->sends)]) }}

+

{{ __('stepwise::stepwise.automation.would_send', ['count' => count($report->sends)]) }}

@forelse($shown as $send) @@ -21,13 +21,13 @@ @empty - + @endforelse
{{ $send['message'] }}
{{ __('rehla::rehla.automation.nobody') }}
{{ __('stepwise::stepwise.automation.nobody') }}
@if($report->skipped !== []) -

{{ __('rehla::rehla.automation.skipped') }}

+

{{ __('stepwise::stepwise.automation.skipped') }}

@foreach($report->skipped as $reason => $count) diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 696e776..c1d4394 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -1,39 +1,39 @@ -@extends('rehla::layout') +@extends('stepwise::layout') -@section('title', __('rehla::rehla.panel_title')) +@section('title', __('stepwise::stepwise.panel_title')) @section('content') @if($journeys->keys() !== [])
@foreach($journeys->keys() as $key) - {{ $journeys->label($key) }} @endforeach
@endif - + - + - {{ __('rehla::rehla.days_unit') }} - - {{ __('rehla::rehla.filter_hint') }} + {{ __('stepwise::stepwise.days_unit') }} + + {{ __('stepwise::stepwise.filter_hint') }}
- + @foreach($userColumns as $label) @endforeach - - - - - + + + + + @@ -61,17 +61,17 @@ class="{{ $key === $journey ? 'active' : '' }}">{{ $journeys->label($key) }}{{ $steps[$step] ?? $step }} @endforeach - + @empty - + @endforelse @@ -101,93 +101,93 @@ class="{{ $key === $journey ? 'active' : '' }}">{{ $journeys->label($key) }} {{ $users->links() }} -
#{{ __('rehla::rehla.name_column') }}{{ __('stepwise::stepwise.name_column') }}{{ $label }}{{ __('rehla::rehla.columns.completed') }}{{ __('rehla::rehla.columns.started') }}{{ __('rehla::rehla.columns.not_started') }}{{ __('rehla::rehla.last_visit') }}{{ __('rehla::rehla.last_followup') }}{{ __('stepwise::stepwise.columns.completed') }}{{ __('stepwise::stepwise.columns.started') }}{{ __('stepwise::stepwise.columns.not_started') }}{{ __('stepwise::stepwise.last_visit') }}{{ __('stepwise::stepwise.last_followup') }}
{{ $lastSeen[$user->getKey()] ?? null ? $lastSeen[$user->getKey()]->diffForHumans() : __('rehla::rehla.never_seen') }}{{ $lastSeen[$user->getKey()] ?? null ? $lastSeen[$user->getKey()]->diffForHumans() : __('stepwise::stepwise.never_seen') }} - {{ ($lastFollowUps[$user->getKey()] ?? null) !== null ? $lastFollowUps[$user->getKey()]->diffForHumans() : __('rehla::rehla.never_followup') }} - + title="{{ __('stepwise::stepwise.history.title') }}">i @if($phones[$user->getKey()] !== null) - @else - @endif
{{ __('rehla::rehla.empty_users') }}{{ __('stepwise::stepwise.empty_users') }}