PHP code example of rumahweb / whatsapp-sdk

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

    

rumahweb / whatsapp-sdk example snippets


use Rumahweb\WhatsApp;

$whatsApp = WhatsApp::init($token);

$message = $whatsApp->message($wabaId); 

# Text message
$message->sendText("6285747277xxx", "Hello World");

$params["to"] = "xxxx";
$params["header"] = [
  [
    "type" => "text",
    "text" => "pesan nya apa"
  ]
]
$params["body"] = [
  [
    "type" => "text",
    "text" => "pesan nya apa"
  ]
]

$template = $whatsApp->template($wabaId);
$template->send("nama_template", $params);

Array
(
    [messaging_product] => whatsapp
    [contacts] => Array
        (
            [0] => Array
                (
                    [input] => +6285747277xxx
                    [wa_id] => 6285747277xxx
                )

        )

    [messages] => Array
        (
            [0] => Array
                (
                    [id] => wamid.HBgNNjI4NTc0NzI3NzQ2NhU
                    [message_status] => accepted
                )

        )

)


$hook = ['array', 'data', 'from', 'facebook'];
$webhook = new Rumahweb\Webhook($hook);
print_r($hook);

Array
(
    [error] => Array
        (
            [message] => Invalid OAuth access token - Cannot parse access token
            [type] => OAuthException
            [code] => 190
            [fbtrace_id] => AtYQl3mJPwLPhH-m_buoHAI
        )

)

Array
(
    [error] => Array
        (
            [message] => (#132001) Template name does not exist in the translation
            [type] => OAuthException
            [code] => 132001
            [error_data] => Array
                (
                    [messaging_product] => whatsapp
                    [details] => template name (event_reminder3) does not exist in id_ID
                )

            [fbtrace_id] => AGSJexhOhNweWMeFsVy4y05
        )

)