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',
]);