PHP code example of infobip-community / infobip-api-php-sdk

1. Go to this page and download the library: Download infobip-community/infobip-api-php-sdk 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/ */

    

infobip-community / infobip-api-php-sdk example snippets


$infobipClient = new Infobip\InfobipClient(
    'apiKey',
    'baseUrl',
    3 // timeout in seconds, optional parameter
);

// example 1
$resource = new \Infobip\Resources\WhatsApp\WhatsAppTextMessageResource(
    '441134960000',
    '441134960001',
    new \Infobip\Resources\WhatsApp\Models\TextContent('text message')
);

$response = $infobipClient
    ->whatsApp()
    ->sendWhatsAppTextMessage($resource);

try {
    $resource = new WhatsAppTextMessageResource();
    
    $response = $infobipClient
        ->whatsApp()
        ->sendWhatsAppTextMessage($resource);
} catch (InfobipException $exception) {
    $exception->getMessage(); // error message
    $exception->getCode(); // http status code
    $exception->getValidationErrors(); // array of validation errors, only available on 400 Bad request and 422 Unprocessable entity exceptions
}

'providers' => [
    // Application Service Providers...
    // ...

    // Other Service Providers...
    Infobip\Support\Laravel\InfobipServiceProvider::class,
    // ...
],



namespace App\Http\Controllers;

use Infobip\InfobipClient;
use Infobip\Resources\WhatsApp\WhatsAppTextMessageResource;
use Infobip\Resources\WhatsApp\Models\TextContent;

final class InfobipController
{
    public function sendTextMessage(Request $request, InfobipClient $infobipClient)
    {
        $resource = new WhatsAppTextMessageResource(
            $request->input('from'),
            $request->input('to'),
            new TextContent($request->input('message'))
        );
        
        $response = $infobipClient
            ->whatsApp()
            ->sendWhatsAppTextMessage($resource);
        
        return $response;
    }
}
json
""infobip-community/infobip-api-php-sdk": "1.*"
}
shell
php artisan vendor:publish --provider="Infobip\Support\Laravel\InfobipServiceProvider"
sh
vendor/bin/php-cs-fixer fix src
vendor/bin/php-cs-fixer fix tests
vendor/bin/phplint
vendor/bin/phpstan