PHP code example of dantepiazza / laravel-chatwoot

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

    

dantepiazza / laravel-chatwoot example snippets


namespace App\Services\Chatwoot;

use Dantepiazza\LaravelChatwoot\Services\ChatwootProvider;

class BotWorkflow extends ChatwootProvider
{
    public function __construct(array $payload)
    {
        $this->default_steps = ['welcome.start', 'finish'];

        $this->default_attributes = ['step' => 'welcome.start'];

        parent::__construct($payload);
    }

    public function run(): void
    {
        $method = 'step_' . str_replace('.', '_', $this->step);

        if (method_exists($this, $method)) {
            $this->$method();
        }
    }

    protected function step_welcome_start(): void
    {
        $this->send('Hello! How can I help you?')->stop();
    }

    protected function step_finish(): void
    {
        $this->send('Thanks! Goodbye 👋')->nextStep('welcome.start')->stop();
    }
}

$this->nextStep('some.step');   // saves the step to Chatwoot custom attributes
$this->stop();                  // halts execution (always call at the end of a step)

// Plain text
$this->send('Hello!');

// Interactive button list
$this->send('Choose an option:', [
    'Option A' => 'step.a',
    'Option B' => 'step.b',
]);

$this->step;   // "welcome.menu"
$this->action; // "confirm"

if ($this->attach('Please send your documents.', 'previous.step')) {
    // Files received
    $this->open(tags: ['support']);
}

$this->open(tags: ['billing'], team: 2, message: 'An agent will contact you shortly.');

$this->goodbye('Here is your info: ...', $this->buildGoodbyeButtons('welcome.menu'));
bash
php artisan vendor:publish --tag=chatwoot-config
bash
php artisan vendor:publish --tag=chatwoot-workflow

POST /v1/chatwoot/{flow}?token={CHATWOOT_WEBHOOK_SECRET}