PHP code example of positus / positus-api-php-client

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

    

positus / positus-api-php-client example snippets


use Positus\Client;

$client = new Client();

$client = new Client();

$client->setToken('you-api-token');

$number = $client->number('your-number-id');

$number = $client->number('sandbox-number-id', true);

$response = $number->sendData([
    'to' => '+5511999999999',
    'type' => 'text',
    'text' => [
        'body' => 'Hi!'
    ]
]);

$response = $number->sendText('+5511999999999', 'Your message');

$response = $number->sendTemplate('+5511999999999', 'namespace', 'name', 'languageCode', [
    "type" => "body",
    "parameters" => [
        [
            "type" => "text",
            "text" => "Param 1"
        ],
        ...
    ]
]);

$response = $number->sendContacts('+5511999999999', [
    [
        'name' => [
            "formatted_name" => "John Doe"
        ],
        'phones' => [
            'phone' => '+5511888888888',
            'type' => 'CELL'
        ]
    ]
]);

$response = $number->sendLocation('+5511999999999', '-23.553885', '-46.662819', 'Robbu - Atendimento digital inteligente', 'Av. Angélica, 2530 - Bela Vista, São Paulo - SP, 01228-200');

$response = $number->sendImage('+5511999999999', 'https://example.com/image.jpg', 'Random Image');

$response = $number->sendDocument('+5511999999999', 'https://example.com/document.pdf', 'Random Document');

$response = $number->sendVideo('+5511999999999', 'https://example.com/video.mp4', 'Random Video');

$response = $number->sendAudio('+5511999999999', 'https://example.com/audio.mp3');

$response = $number->getMedia('media-id');

if ($response->success()) {
    echo 'Message with Id ' . $response->json()->messages[0]->id . ' sent successfully';
}

if ($response->error()) {
    echo 'Something went wrong';
}

$response->status();

$response->body();

$response->json();

$response->object();

$response->header('Content-Type');

$response->headers();