2017 © Pedro Peláez
 

library botman-driver-dialogflow

Dialogflow fulfillment driver for BotMan

image

eristemena/botman-driver-dialogflow

Dialogflow fulfillment driver for BotMan

  • Tuesday, May 15, 2018
  • by eristemena
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

BotMan Dialogflow Driver

BotMan driver to handle Dialogflow fulfillment with BotMan., (*1)

Build Status codecov StyleCI, (*2)

It uses eristemena/dialog-fulfillment-webhook-php library, so it supports v1 and v2 of Dialogflow request., (*3)

Installation & Setup

First you need to pull in the Driver., (*4)

composer require eristemena/botman-driver-dialogflow

If you're using BotMan Studio, that's pretty much it., (*5)

But if you don't, then load the driver before creating the BotMan instance:, (*6)

DriverManager::loadDriver(\BotMan\Drivers\Dialogflow\DialogflowDriver::class);

// Create BotMan instance
BotManFactory::create([]);

Usage

Hearing Messages

You can start receiving message using hears() based on the Intent of the message,, (*7)

$botman->hears('Intent Name', function ($botman) {
    // replies here
});

Single Message Reply

The simplest way to reply to an incoming message is using BotMan's own reply() method:, (*8)

$botman->hears('Default Welcome Intent', function ($botman) {
    $botman->reply('Hi, welcome!');
});

Multiple Message Replies

Normally when you want to send multiple replies, you use reply() multiple times. Unfortunately this doesn't work for Dialogflow driver, cause the messages should be in a single response payload., (*9)

For that, you have to use specific methods for this driver addMessage() and sendMessage() as follow,, (*10)

$botman->hears('Default Welcome Intent', function ($botman) {
    $botman->addMessage('Good morning');
    $botman->addMessage('How may i help you?');
    $botman->sendMessage();
});

Rich Messages

Text

Use Dialogflow\RichMessage\Text, (*11)

    $text = Text::create()
        ->text('Hello')
        ->ssml('
            <speak>
                Hello!
                <audio src="https://actions.google.com/sounds/v1/cartoon/clang_and_wobble.ogg"></audio>
            </speak>
        ')
    ;

    $botman->reply($text);

Image

Use Dialogflow\RichMessage\Image, (*12)

    $image = Image::create('https://picsum.photos/200/300');
    $botman
        ->addMessage('This is an image')
        ->addMessage($image)
        ->sendMessage()
    ;

Card

Use Dialogflow\RichMessage\Card, (*13)

    $card = Card::create()
        ->title('This is title')
        ->text('This is text body, you can put whatever here.')
        ->image('https://picsum.photos/200/300')
        ->button('This is a button', 'https://docs.dialogflow.com/')
    ;

    $botman
        ->addMessage('This is a card')
        ->addMessage($card)
        ->sendMessage()
    ;

Quick Replies

Use Dialogflow\RichMessage\Suggestion, (*14)

    $suggestion = Suggestion::create(['Tell me a joke', 'Tell me about yourself']);

    $botman
        ->addMessage('Hi, how can i help you with?')
        ->addMessage($suggestion)
        ->sendMessage()
    ;

Custom Payload

Use Dialogflow\RichMessage\Payload, (*15)

    $payload = Payload::create([
        'expectUserResponse' => false
    ]);

    $botman
        ->addMessage('Have a good day')
        ->addMessage($payload)
        ->sendMessage()
    ;

The Versions

15/05 2018

dev-analysis-XaGmyZ

dev-analysis-XaGmyZ http://github.com/eristemena/botman-driver-dialogflow

Dialogflow fulfillment driver for BotMan

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eris Ristemena

bot botman dialogflow