PHP code example of henriquecacerez / whatsapp-apibrasil-php

1. Go to this page and download the library: Download henriquecacerez/whatsapp-apibrasil-php 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/ */

    

henriquecacerez / whatsapp-apibrasil-php example snippets




    piBrasil\WhatsApp;

    // https://plataforma.apibrasil.com.br/plataforma/myaccount/apicontrol
    $credentials = [ 
        'SecretKey:     YOUR_SECRET_KEY',
        'PublicToken:   YOUR_PUBLIC_TOKEN',
        'DeviceToken:   YOUR_DEVICE_TOKEN',
        'Authorization: Bearer YOUR_BEARER_TOKEN'
    ];

    $whatsApp = new WhatsApp($credentials);


    /**
      * número de WhatsApp que receberá a mensagem.
      * (obrigatório conter o código do país e o DDD).
    */
    $phoneNumber = "+55 (18) 99999-9999";

    // mensagem que será enviada.
    $message = "Testando API! šŸ˜ƒ"; 

    try {
        // envia a mensagem de texto.
        print_r($whatsApp->sendText($phoneNumber, $message));
    } catch (Exception $e) {
        // Caso dê erro, retornará o motivo.
        die("Error: " . $e->getMessage());
    }

  // caminho da imagem
  $image = "cat.jpg";

  // legenda da imagem (opcional)
  $caption = "Legenda da imagem";

  // envia a imagem
  $whatsApp->sendImage(5518999999999, $image, $caption);

  $whatsApp->sendVideo(5518999999999, "files/simplevideo.mp4");

    // titulo do arquivo (opcional)
    $title = "Aplicação";
    
    // envia o arquivo pdf
    $whatsApp->sendPDF(5518999999999, "https://www.africau.edu/images/default/sample.pdf", $title);

    $buttons = [
      [
        'id'   => 'resposta_01',
        'text' => 'Botão 1ļøāƒ£'
      ], 
      [
        'id'   => 'resposta_02',
        'text' => 'Botão 2ļøāƒ£'
      ],
      [
        'id'   => 'resposta_03',
        'text' => 'Botão 3ļøāƒ£'
      ]
    ];

    // envia a mensagem com botões.
    $whatsApp->sendButtonMessage(5518999999999, [
        'title'  => "Titulo da mensagem",
        'text'   => "Imagine um texto bem legal aqui.\n\nšŸ‘‹šŸ˜",
        'footer' => "Aqui vai o texto do rodapé da mensagem"
    ], $buttons);


    // cria o botão (id, texto)
    $whatsApp->createButton('resposta_01', "Botão 1ļøāƒ£");
    $whatsApp->createButton('resposta_02', "Botão 2ļøāƒ£");
    $whatsApp->createButton('resposta_03', "Botão 3ļøāƒ£");

    // envia a mensagem com botões.
    $whatsApp->sendButtonMessage(5518999999999, [
        'title'  => "Titulo da mensagem",
        'text'   => "Imagine um texto bem legal aqui.\n\nšŸ‘‹šŸ˜",
        'footer' => "Aqui vai o texto do rodapé da mensagem"
    ]);

composer 

// Exemplo:

// Exemplo: