PHP code example of emanate / beem

1. Go to this page and download the library: Download emanate/beem library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

emanate / beem example snippets


BeemSms::accessToken('your-access-token')->content('Hello')->getRecipients(['255700000000'])->send();

BeemSms::apiKey('other-key')->secretKey('other-secret')->content('Hello')->getRecipients(['255700000000'])->send();

use Emanate\BeemSms\Facades\BeemSms;

BeemSms::content('Your message here')->loadRecipients(User::all())->send();

beem()->content('Your message here')->loadRecipients(User::all())->send();

// A collection of models. The phone column defaults to 'phone_number'.
BeemSms::content('Hello')->loadRecipients(User::all(), 'mobile')->send();

// An array
BeemSms::content('Hello')->getRecipients(['255700000000', '255711111111'])->send();

// Variadic arguments
BeemSms::content('Hello')->unpackRecipients('255700000000', '255711111111')->send();

BeemSms::content('Ujumbe wako hapa 😀')
    ->getRecipients(['255700000000'])
    ->senderName('SHOP')                   // registered, active sender ID, max 11 characters
    ->unicode()                            // for characters outside the GSM alphabet
    ->scheduleTime(now()->addHours(2))     // or a 'Y-m-d H:i' string in GMT+0
    ->jobName('welcome-sms')               // dashboard tracking
    ->campaignTitle('January onboarding')  // dashboard tracking
    ->send();

use Emanate\BeemSms\Exceptions\BeemApiException;

try {
    $response = BeemSms::content('Hello')->getRecipients(['255700000000'])->sendAndParse();

    // $response['request_id'], $response['valid'], $response['invalid'], $response['duplicates'], ...
} catch (BeemApiException $e) {
    // $e->getCode() is Beem's response code, for example 102 for insufficient balance
    report($e->description());
}

$report = BeemSms::deliveryReport('255700000000', $response['request_id']);

// [['dest_addr' => '255700000000', 'status' => 'DELIVERED', 'request_id' => '31951']]

BeemSms::balance();

BeemSms::senderNames();

BeemSms::senderNames(['page' => 1, 'limit' => 20, 'status' => 'active', 'q' => 'SHOP']);

BeemSms::templates(['page' => 1, 'limit' => 20]);

$template = BeemSms::createTemplate('Welcome', 'Welcome to our service!');

BeemSms::updateTemplate($template['data']['id'], 'Welcome', 'Welcome aboard!');

BeemSms::deleteTemplate($template['data']['id']);

use Emanate\BeemSms\Events\InboundSmsReceived;

class HandleInboundSms
{
    public function handle(InboundSmsReceived $event): void
    {
        $message = $event->message;

        $message->from();            // '255701000000'
        $message->to();              // your short code or long number
        $message->text();            // 'STOP please'
        $message->keyword();         // 'STOP'
        $message->transactionId();   // use this to stay idempotent
        $message->timeUtc();
        $message->channel();         // 'sms'
        $message->custom();          // []
        $message->currency();        // 'TZS'
        $message->subscriberPrice(); // '100.00'
        $message->billingPrice();    // '100.00'
        $message->toArray();         // the raw payload
    }
}

use Emanate\BeemSms\Facades\Otp;

$response = Otp::request('255700000000');

$pinId = $response['data']['pinId'];
// $response['data']['pinExpiryTimeInMinutes'], $response['data']['expiresInSeconds']

Otp::verify($pinId, '1234');

if (Otp::check($pinId, $request->input('pin'))) {
    // verified
}

Otp::appId(4321)->accessToken('your-access-token')->request('255700000000');

> Otp::parameter('channel', 'whatsapp')->request('255700000000');
> 

use Emanate\BeemSms\Facades\MulticountrySms;

MulticountrySms::from('MyApp')->to('255650000001')->content('Hello World')->send();

beem_multicountry()->to('255650000001')->content('Hello World')->send();

MulticountrySms::from('MyApp')
    ->to('255650000001')
    ->content('414243')                // hex body
    ->binary()
    ->userDataHeader('0605040B8423F0')
    ->ports(9200, 2948)
    ->concatenated(reference: 42, sequence: 1, total: 3)
    ->validityPeriod(3600)
    ->send();

MulticountrySms::to('255650000001')->content('Hi')->parameter('SOURCEADDRNPI', 1)->send();

MulticountrySms::to('255650000001')
    ->content('Hello World')
    ->deliveryReport(route('beem.multicountry.callback', ['token' => config('beem.multicountry.callback.token')]))
    ->send();

use Emanate\BeemSms\Events\MulticountryInboundSmsReceived;

public function handle(MulticountryInboundSmsReceived $event): void
{
    $event->message->from();     // SOURCEADDR
    $event->message->to();       // DESTADDR, your short code or long number
    $event->message->text();     // MESSAGE
    $event->message->keyword();  // KEYWORD, or the first word of the message
    $event->message->id();       // ID of the message being replied to, if any
}

use Emanate\BeemSms\Events\MulticountryDeliveryReportReceived;

public function handle(MulticountryDeliveryReportReceived $event): void
{
    $report = $event->report;

    $report->messageId();        // the msgid returned when you sent the message
    $report->to();               // DESTADDR
    $report->status();           // 1–11, see MulticountryDeliveryReport::STATUS_*
    $report->statusText();       // 'Delivered', 'Failed', 'Expired', ...
    $report->isDelivered();
    $report->isUndeliverable();  // failed, deleted, expired, rejected or canceled
    $report->isFinal();
}

MulticountrySms::balance(); // ['account' => 'test', 'balance' => '1234.567']
bash
php artisan vendor:publish --tag="beem"