# BulkSMSBD adapter notes

`Services\Provider\Adapters\BulkSmsBdProvider`. Originally built 2026-08-18 from public documentation and research **without a live sandbox account** — ABM Soft chose to build the adapter first and supply real credentials later. Real credentials (a live account, real balance) arrived the same day; this file now reflects what's been confirmed by actually calling the API, and what's still outstanding.

**A real, live, real-money account key is used for verification.** Every probe below was deliberately constructed to fail safely (invalid recipient numbers, missing required fields) so nothing was ever actually sent or charged — see "Still not confirmed" for the one thing that genuinely requires a real send to nail down.

## Confirmed against the live API

Endpoints (base `https://bulksmsbd.net` — `http://` also works identically, but the adapter always uses `https://`):

| Purpose | Method | Path | Status |
|---|---|---|---|
| Single-recipient | GET/POST | `/api/smsapi` | **In use.** Behaves exactly as documented. |
| Personalized batch | POST | `/api/smsapimany` | Exists and is reachable, but returns a server-side error (`Undefined variable $smsarray`) for every payload shape tried — **not used**. See "The `smsapimany` investigation" below. |
| Balance | GET/POST | `/api/getBalanceApi` | **In use.** |

`smsapi` params (all sent as POST form fields by this adapter): `api_key`, `type=text`, `number` (single `8801XXXXXXXXX`), `senderid`, `message`.

`getBalanceApi` params: `api_key`. Confirmed real response: `{"response_code":202,"balance":784.75}` — the `balance` field name the adapter always tried first was correct; `checkBalance()` needs no further guessing.

Confirmed response envelope shape, from real (safe) probes against `/api/smsapi`:

```json
{"response_code":1003,"success_message":"","error_message":"Please Required all fields, or Contact Your System Administrator"}
{"response_code":1001,"success_message":"","error_message":"Invalid Number!"}
```

`response_code`, `success_message`, `error_message` are all real, confirmed field names. `error_message` is used verbatim when present (falls back to the static table below only when it's empty).

**The success shape is now confirmed too** — one real test-send (2026-08-18, to a number ABM Soft explicitly provided for this purpose, `01715182133` → `8801715182133`) returned:

```json
{"response_code":202,"message_id":8837442,"success_message":"SMS Submitted Successfully 1","error_message":""}
```

This matches the adapter's `message_id` assumption exactly — `interpretSingleResponse()` needed no changes.

Full error code table (from BulkSMSBD's own account-portal API docs, supplied directly by ABM Soft — this supersedes the earlier partial list pieced together from third-party packages):

| Code | Meaning |
|---|---|
| 202 | Success |
| 1001 | Invalid phone number |
| 1002 | Sender ID is not correct, or is disabled |
| 1003 | A required field was missing from the request |
| 1005 | Internal error on the BulkSMSBD side |
| 1006 | Balance validity is not available on this account |
| 1007 | Insufficient balance on the BulkSMSBD account |
| 1011 | User ID not found |
| 1012 | Masking SMS must be sent in Bengali |
| 1013 | Sender ID has no gateway configured for this API key |
| 1014 | Sender type not found for this sender ID/API key |
| 1015 | Sender ID has no valid gateway for this API key |
| 1016 | No active price info for this sender type/sender ID |
| 1017 | No price info configured for this sender type/sender ID |
| 1018 | The owner account of this API key is disabled |
| 1019 | The price plan for this account is disabled |
| 1020 | This account's parent account was not found |
| 1021 | This account's parent active price info was not found |
| 1031 | Account not verified — contact BulkSMSBD support |
| 1032 | Calling server's IP address is not whitelisted for this account |

`BulkSmsBdProvider::KNOWN_ERROR_CODES` now has every one of these; anything outside this list still falls back to a generic "rejected (response_code N)" message that surfaces the real code.

## The `smsapimany` investigation (why the adapter no longer uses it)

The original build guessed `smsapimany` was the right endpoint for a personalized batch send — `messages` as a JSON-encoded array of `{"to": ..., "message": ...}` objects, sent as a normal POST form field. With real credentials in hand, live (safe — deliberately invalid recipient numbers throughout) probing found:

- The endpoint exists and responds (ruling out "wrong URL").
- A request missing required fields gets the expected, clean `{"response_code":1003,...}` — so the endpoint itself is alive and validates input.
- Every payload shape tried for `messages` — the originally-guessed `[{"to":...,"message":...}]`, a `{"number":...}` variant, wrapping the array in `{"smsarray":[...]}`, and PHP-native nested form fields (`messages[0][to]=...&messages[0][message]=...`) — produced a **PHP runtime notice leaking straight through from BulkSMSBD's own backend** (`Undefined variable $smsarray`, `Undefined array key "to"`, `Undefined array key 0`, depending on the shape), not a clean "wrong format" rejection.

That pattern (a real PHP notice, not a validation error) means this is most likely a genuine bug or an unprovisioned feature on BulkSMSBD's side for this specific account/endpoint, not a wrong guess about the wire format on ours — no format that was tried made the server-side variable actually get set. Continuing to guess against someone else's production API wasn't worth it once the single-recipient endpoint was confirmed to work perfectly.

**Decision: the adapter sends each message in a batch as its own `/api/smsapi` call** (one HTTP round trip per recipient) instead of relying on `smsapimany`. This trades N round trips for 1 round trip per dispatch chunk — `maxBatchSize()` was lowered from the original 100 to 20 to bound how long one `sms:dispatch` cycle can take waiting on sequential HTTP calls. Revisit if BulkSMSBD support ever confirms the real `smsapimany` contract, or this account gets whatever's missing provisioned — a true bulk call would still be strictly better once it actually works.

## Production incident: empty senderid rejected every non-masking send (fixed 2026-08-19)

The first real tenant (onboarded 2026-08-18) had 3 sends rejected in a row, all `{"response_code":1003,"error_message":"Please Required all fields, or Contact Your System Administrator"}`. Root cause: the platform's "non-masking, no sender ID needed" abstraction (`MessageBuilder::resolveSenderId()`, SPEC §2.3 - non-masking is "always available") resolves to an **empty** sender_id when the tenant doesn't specify one - correct for `NullProvider`, but BulkSMSBD's `smsapi` endpoint requires a non-empty `senderid` on every call and rejects an empty one with exactly this 1003. No money was lost - the credit ledger's reserve/refund pair caught all 3 correctly - but the tenant's messages never actually went out.

**Fix:** `BulkSmsBdProvider::senderIdFor()` now falls back to a configured `credentials.default_sender_id` whenever a message's own `senderId` is empty. Production is configured with `8809617614220` - the exact value already confirmed working by the real successful test-send in this file (`message_id: 8837442`, 2026-08-18).

## Still not confirmed

- **DLR (delivery report) push format and mechanism.** Nothing in the docs supplied so far covers DLRs at all — the account-portal page that finally confirmed send/balance/error-codes was silent on it. `BulkSmsBdProvider::parseDlr()` is still a best-effort guess at common SMPP-style status tokens (`DELIVRD`/`UNDELIV`/etc.), unconfirmed. Not a data-loss risk either way — SPEC §6 already logs the raw DLR payload before attempting to parse it — but ask BulkSMSBD support directly, or wait for a real push and inspect it, before trusting `parseDlr()`'s output for anything beyond logging.
- **Special-character encoding in `message`.** Docs mention URL-encoding `& $ @` etc. for the GET-style call; this adapter always POSTs form fields (handled by the HTTP client's own form encoding), which should already cover this, but it's untested against a real multi-symbol message.

## Going live in production (remaining step)

Everything needed to trust this adapter is now confirmed except the DLR format. What's left is purely operational:

1. Configure the real credentials into production: `ProviderModel::saveCredentials()` with `{"api_key": "m0M7zps57NwitK0j31mZ", "base_url": "https://bulksmsbd.net"}` (never store the plaintext key anywhere else).
2. Flip the `sms_providers` row to `active` and give it a lower `priority` number than `NullProvider`'s (100) if BulkSMSBD should be preferred once both are active — `ProviderRouteModel::candidateProvidersFor()` orders by `pr.priority ASC` then `p.priority ASC`.
3. Add a `sms_provider_routes` entry (see `NullProviderSeeder` for the pattern) so tenants actually route through it — masking and non-masking, or narrower if only one is wanted at first.
4. Decide whether `NullProvider` stays active alongside it (e.g. as a lower-priority fallback) or gets disabled now that a real provider is live — disabling it means every tenant send from this point on is a real, billed SMS.
5. Confirm the DLR mechanism with BulkSMSBD support (push vs poll) before relying on `parseDlr()` for anything beyond raw-payload logging.

## Sources

- BulkSMSBD's own account-portal API documentation, supplied directly by ABM Soft (2026-08-18) — the source for the endpoint list, full parameter tables, and complete error code table above.
- Live API probes against the real account (2026-08-18) — the source for every "confirmed against the live API" claim above; all safe (non-sending) by construction.
- [`rihabrahman/bulksmsbd-laravel` on Packagist](https://packagist.org/packages/rihabrahman/bulksmsbd-laravel) and [`Deveripon/package-bulk-sms-bd` on GitHub](https://github.com/Deveripon/package-bulk-sms-bd) — earlier, pre-credentials research sources; superseded by the above wherever they conflict.
