PHP code example of olusegun171 / laravel-termii

1. Go to this page and download the library: Download olusegun171/laravel-termii 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/ */

    

olusegun171 / laravel-termii example snippets


  use LaravelTermii\Termii;

  $messaging = Termii::messaging();

  $channel = 'generic';  //default is 'generic' or pass 'dnd' to send dnd message
  $response = $messaging->sendMessage(string $to, string $message, string $channel);
  $response->json();

  $channel = 'generic';  //default is 'generic' or pass 'dnd' to send dnd message
  $messaging->sendBulkMessage($to, string $mesage);

  //The url to the file resource and caption that should be added to the image,
  $media  = ['url' => '','caption' => '' ];
  $device_name = 'N-Alert'; // you can pass another approved device name.
  $response = $messaging->sendWhatapps(string $to, string $device_name, array $media);
  $response->json();


/* $data = [
         "product_name": "Termii",
         "otp" : 120435,
         "expiry_time": "10 minutes"
] */
  $response = $messaging->sendTemplate(string $to, string $template_id, string $device_id, array $data);
  $response->json();

//Fetch campaigns
$response = $messaging->campaigns();
$response->json();

//Fetch campaign history
$response = $messaging->campaignHistory(string $campaign_id);
$response->json();

//Send a campaign with default senderID 'N-Alert'
/* 
$channel = 'generic';
$schedule = [
    "schedule_sms_status" => "scheduled" // To send a scheduled campaign, pass scheduled as the value
    "schedule_time" => "30-06-2021 6:00", //The date time to send scheduled campaign
]; */

$response = $messaging->sendCampaign(string $phonebook_id, string $message, string $channel, array $schedule = []);
$response->json();

  $response = $messaging->requestSenderID(string $sender_id, string $usecase, string $company);
  $response->json();

  $response = $messaging->fetchSenderID();
  $response->json();

  $token = Termii::token(["pin_attempts" => 10,
                            "pin_time_to_live" => 30,
                            "pin_length" => 6,
                            "pin_placeholder" => '< 123 >',
                            'pin_type' => 'ALPHANUMERIC',
                            'message_type' => 'ALPHANUMERIC',
                        ]);

  $insight = Termii::insights();
 php
//Fetch contacts by phonebook ID
$response = $messaging->PhonebookContacts(string $phonebook_id);
$response->json();

//Add single contact to a phonebook
  /* $contact = [
        "phone_number" => "8123696237",
        "email_address" => "[email protected]",
        "first_name" =>  "test",
        "last_name" =>  "contact",
        "company" => "Termii",
        "country_code" => "234"
   ]; */
$response = $messaging->addContact(string $phonebook_id, array $contact);
$response->json();

//Add multiple contacts to a phonebook
  /* 
    file containing the list of contacts. Supported files 
 php
$response = $token->voiceToken(string $phone_number);
$response->json();
 php
$response = $token->voiceCall(string $phone_number,  string $code);
$response->json();
 php
$response = $token->emailToken(string $email,  string $code, $config_id);
$response->json();
 php
$response = $token->verifyToken(string $pin_id,  string $pin);
$response->json();
 php
$response = $token->inAppToken(string $phone_number);
$response->json();
 php
$response = $insight->balance();
$response->json();
 php
$response = $insight->search(string $phone_number);
$response->json();
 php
$response = $insight->status(string $phone_number, string $country_code = 'NG');
$response->json();
 php
$response = $insight->history();
$response->json();
 php
$response->body() : string;

$response->json($key = null, $default = null) : mixed;

$response->object() : object;

// Returns http status code
$response->status() : int;

// Determine if the status code is >= 200 and < 300...
$response->successful();
 
// Determine if the status code is >= 400...
$response->failed();
 
// Determine if the response has a 400 level status code...
$response->clientError();
 
// Determine if the response has a 500 level status code...
$response->serverError();