Download the PHP package emanate/beem without Composer
On this page you can find all versions of the php package emanate/beem. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package beem
Short Description Refactoring way of sending SMS
License MIT
Homepage https://github.com/wao1ook/beem
Informations about the package beem
Beem Africa SMS for Laravel
A Laravel package for the Beem Africa messaging APIs. It covers:
- SMS: send to one or many recipients, schedule, unicode, delivery reports, balance, sender names and templates
- Two-Way SMS: receive inbound messages as Laravel events
- OTP: request and verify one-time PINs
- Multicountry SMS: send international SMS, and receive inbound messages and delivery reports as Laravel events
This is a community package. It is not affiliated with Beem Africa.
Contents
- Requirements
- Installation
- Configuration
- SMS
- Two-Way SMS
- OTP
- Multicountry SMS
- Phone number validation
- Testing
Requirements
- PHP 8.2 or later
- Laravel 12 or 13
- A Beem account with API credentials
Installation
Publish the config file:
When upgrading, compare your published
config/beem.phpwith the package's copy. New options are added over time.
Configuration
Every option can be set from .env. Only the first three are needed to send SMS:
See config/beem.php for the full list, with comments.
Authentication
By default every request uses HTTP Basic auth, with your API key as the username and your secret as the password.
Beem also accepts an access token, sent in the Authorization header without a Bearer prefix. Set BEEM_ACCESS_TOKEN and the token replaces the key and secret everywhere. The key and secret can then be left empty.
You can also set credentials at runtime:
Call withoutAccessToken() to fall back to key and secret auth for a single call.
SMS
Sending
Use the facade or the beem() helper:
There are three ways to add recipients:
Numbers are in international format without the +, for example 255700000000.
Message options
scheduleTime()converts anyDateTimeInterfaceto UTC for you.encoding(BeemSms::ENCODING_UNICODE)sets the raw encoding value. The default comes from theencodingconfig option.
Reading the response
send() returns the raw PSR-7 response. sendAndParse() returns the decoded body, and throws when Beem answers with an error code:
Delivery reports
Beem does not push delivery reports for local SMS. You poll for them using the request_id returned by a send. Wait at least five minutes after sending, so the mobile operator has time to report back:
status is one of PENDING, DELIVERED or UNDELIVERED.
Balance
Sender names
Supported filters: page, limit, sortBy, sortOrder, q, status. Sender IDs are registered in the Beem dashboard; the API only lists them.
Templates
Error handling
Every method that returns a decoded array throws Emanate\BeemSms\Exceptions\BeemApiException when Beem answers with an error. That covers balance, deliveryReport, senderNames, the template methods and sendAndParse. The exception code is Beem's response code, and BeemApiException::RESPONSE_CODES maps every documented code to its meaning.
Two-Way SMS
Beem POSTs mobile-originated messages to a callback URL that you register on your Two-Way number in the Beem dashboard. Enable the route:
Register this URL with Beem:
Then listen for the event:
The route answers with the acknowledgement Beem expects, {"transaction_id": "...", "successful": true}, as soon as the event is dispatched. Do slow work in a queued listener. Beem may retry, so use transactionId() to skip messages you have already processed.
Securing the callback
Every callback is authenticated before the payload is read. Beem's docs do not say which credentials, if any, it sends with the callback, so several are accepted:
?token=on the callback URL, or anAuthorizationheader, equal toBEEM_TWO_WAY_TOKEN(recommended)- an
Authorizationheader equal to youraccess_token - HTTP Basic auth carrying your API key and secret
Comparisons are constant-time, and a Bearer or Token prefix is tolerated. Unauthenticated requests get a 401 and dispatch no event. Your API secret and access token are never accepted in the query string, so they cannot leak into access logs.
If you authenticate the callback elsewhere, for example at an API gateway, set two_way.verify_credentials to false. Leave it on otherwise. With it off, anyone who learns the URL can inject fake messages.
Extra middleware for the route goes in two_way.middleware. The credential check always applies on top.
OTP
The OTP API uses your SMS API key and secret, but runs on its own host. Create an OTP application in the Beem dashboard and set its ID:
verify() throws Emanate\BeemSms\Exceptions\OtpException when the PIN is wrong, expired, already used, or out of attempts. Use check() if you want a boolean instead:
OtpException::RESPONSE_CODES maps codes 100–118 to their meanings. The app ID and credentials can be set per call:
The channel, SMS or WhatsApp, is set on the OTP application in the dashboard.
Request field names. Beem's OTP reference documents the responses and codes, but not the request body. This package sends
appIdandmsisdnto request a PIN, andpinIdandpinto verify one. If Beem expects something else, add any field withparameter():
Multicountry SMS
Multicountry SMS is a separate Beem platform. It has its own host, authenticates with a username and password, and takes uppercase form parameters.
The platform takes one destination per request. Loop to send to many.
- Alphanumeric senders are limited to 11 GSM characters, and
SOURCEADDRTON=5is set for you. - A leading
+is stripped from the destination. - Unicode is detected by the platform, so no flag is needed.
Binary, UDH and concatenation
Any other platform parameter can be set directly. The name is uppercased for you:
Inbound messages and delivery reports
The platform POSTs inbound messages and delivery reports to one callback URL, as form fields. The platform sends no credentials, so the package protects the route with a secret token in the URL. Enable the route:
Your callback URL is:
- Inbound messages: Beem support registers the callback URL on your account. Email [email protected] with it.
- Delivery reports: request them per message:
Listen for the events. An inbound message listener:
A delivery report listener:
A request carrying a STATUS field is treated as a delivery report. Anything else is treated as an inbound message. The route answers with the empty HTTP 200 the platform expects. Requests with a missing or wrong token get a 401. If no token is configured, every request gets a 401, so the route is never left open by accident. Set multicountry.callback.verify_token to false only if you authenticate the route some other way.
Balance
Error handling
The platform answers HTTP 200 even when a send fails. send() checks the status in the body and throws Emanate\BeemSms\Exceptions\MulticountrySmsException for any non-zero status. The exception code is the platform status, and MulticountrySmsException::STATUS_CODES maps every documented code to its meaning.
Phone number validation
If a number is not in a format Beem accepts, the whole send fails. With validate_phone_addresses set to true (the default), numbers are checked before sending and an exception is thrown for invalid ones.
To use your own rules, point validator_class in the config at a class that implements Emanate\BeemSms\Contracts\Validator.
Testing
Changelog
See CHANGELOG.
Contributing
Issues and pull requests are welcome at wao1ook/beem. Please run composer test and composer pint before opening a pull request.
Security vulnerabilities
Please review our security policy to report a vulnerability.
Credits
- Emanate Software
- All contributors
License
The MIT License (MIT). See License File for details.
All versions of beem with dependencies
ext-curl Version *
ext-mbstring Version *
guzzlehttp/guzzle Version ^7.8|^8.0
illuminate/support Version ^12.0|^13.0