PHP code example of bootdesk / chat-sdk-adapter-instagram

1. Go to this page and download the library: Download bootdesk/chat-sdk-adapter-instagram 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/ */

    

bootdesk / chat-sdk-adapter-instagram example snippets


use BootDesk\ChatSDK\Instagram\InstagramAdapter;

$adapter = new InstagramAdapter(
    pageAccessToken: env('INSTAGRAM_PAGE_ACCESS_TOKEN'),
    httpClient: new \GuzzleHttp\Client,
    appSecret: env('INSTAGRAM_APP_SECRET'),
    verifyToken: env('INSTAGRAM_VERIFY_TOKEN'),
);

'instagram' => [
    'page_access_token' => env('INSTAGRAM_PAGE_ACCESS_TOKEN'),
    'app_secret'        => env('INSTAGRAM_APP_SECRET'),
    'verify_token'      => env('INSTAGRAM_VERIFY_TOKEN'),
],

// Send a message to a user
$adapter->postMessage('instagram:1234567890', 'Hello from laravel-bootdesk!');

use BootDesk\ChatSDK\Instagram\InstagramTemplate;

// Button template
$adapter->postMessage('instagram:1234567890', PostableMessage::template(
    InstagramTemplate::create('options')
        ->buttonTemplate('Choose an option', [
            ['type' => 'postback', 'title' => 'Yes', 'payload' => 'YES'],
            ['type' => 'postback', 'title' => 'No', 'payload' => 'NO'],
        ])
));

// Generic template (carousel)
$adapter->postMessage('instagram:1234567890', PostableMessage::template(
    InstagramTemplate::create('catalog')
        ->genericTemplate([
            [
                'title' => 'Product A',
                'subtitle' => 'Best seller',
                'image_url' => 'https://example.com/a.jpg',
                'default_action' => ['type' => 'web_url', 'url' => 'https://example.com/a'],
                'buttons' => [['type' => 'web_url', 'title' => 'Buy', 'url' => 'https://example.com/a/buy']],
            ],
        ])
));

// Media template
$adapter->postMessage('instagram:1234567890', PostableMessage::template(
    InstagramTemplate::create('intro')
        ->mediaTemplate('https://example.com/video.mp4', 'video', [
            'type' => 'web_url', 'title' => 'Learn More', 'url' => 'https://example.com',
        ])
    )
);