PHP code example of bootdesk / chat-sdk-botman-compat

1. Go to this page and download the library: Download bootdesk/chat-sdk-botman-compat 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-botman-compat example snippets


use BotMan\BotMan\BotManFactory;
use BootDesk\ChatSDK\Core\Chat;

$bot = BotManFactory::createForChat($chat);

$bot->hears('hello', function ($message, $bot) {
    $bot->reply('Hello!');
});

$bot->hears('my name is {name}', function ($message, $bot, $params) {
    $bot->reply("Hi {$params['name']}!");
});

$bot->fallback(function ($message, $bot) {
    $bot->reply("I don't understand.");
});

use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Button;

$question = Question::create('Continue?')
    ->fallback('Choose yes or no')
    ->callbackId('continue')
    ->addButton(Button::create('Yes')->value('yes'))
    ->addButton(Button::create('No')->value('no'));

$bot->ask($question, function ($answer) use ($bot) {
    if ($answer->isInteractiveMessageReply()) {
        $bot->reply("You chose: {$answer->getValue()}");
    }
});

use BotMan\BotMan\Conversations\Conversation;

class OnboardingConversation extends Conversation
{
    public function run(): void
    {
        $this->ask('What is your name?', function ($answer) {
            $name = $answer->getText();
            $this->say("Welcome, {$name}!");
        });
    }
}

$bot->startConversation(new OnboardingConversation);

use BotMan\BotMan\Messages\Outgoing\OutgoingMessage;
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Attachments\Video;
use BotMan\BotMan\Messages\Attachments\Audio;
use BotMan\BotMan\Messages\Attachments\File;
use BotMan\BotMan\Messages\Attachments\Location;

// Image
$message = OutgoingMessage::create('Here is a photo')
    ->withAttachment(new Image('https://example.com/photo.jpg'));

// Video
$message = OutgoingMessage::create('Check this out')
    ->withAttachment(new Video('https://example.com/video.mp4'));

// Audio
$message = OutgoingMessage::create('Listen to this')
    ->withAttachment(new Audio('https://example.com/audio.mp3'));

// File
$message = OutgoingMessage::create('Document attached')
    ->withAttachment(new File('https://example.com/doc.pdf'));

// Location
$message = OutgoingMessage::create('We are here')
    ->withAttachment(new Location(40.7128, -74.0060));

$bot->reply($message);