Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
eristemena authored Sep 3, 2018
1 parent ce58be3 commit 78d0a47
Showing 1 changed file with 294 additions and 6 deletions.
300 changes: 294 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Dialogflow Fulfillment PHP Library

[![Latest Version on Packagist](https://img.shields.io/packagist/v/eristemena/dialogflow-fulfillment-webhook-php.svg?style=flat-square)](https://packagist.org/packages/eristemena/dialogflow-fulfillment-webhook-php)
[![Build Status](https://travis-ci.org/eristemena/dialogflow-fulfillment-webhook-php.svg?branch=master)](https://travis-ci.org/eristemena/dialogflow-fulfillment-webhook-php)
[![codecov](https://codecov.io/gh/eristemena/dialogflow-fulfillment-webhook-php/branch/master/graph/badge.svg)](https://codecov.io/gh/eristemena/dialogflow-fulfillment-webhook-php)
[![StyleCI](https://styleci.io/repos/132703866/shield?branch=master)](https://styleci.io/repos/132703866)
[![Monthly Downloads](https://img.shields.io/packagist/dm/eristemena/dialogflow-fulfillment-webhook-php.svg?style=flat-square)](https://packagist.org/packages/eristemena/dialogflow-fulfillment-webhook-php)

This Library is inspired by [dialogflow/dialogflow-fulfillment-nodejs](https://github.com/dialogflow/dialogflow-fulfillment-nodejs).

Expand All @@ -28,6 +30,15 @@ For full class reference please refer to the [doc](https://github.com/eristemena
- [Image](#image-1)
- [Basic Card](#basic-card)
- [List](#list)
- [Carousel](#carousel)
- [Browsing Carousel](#browsing-carousel)
- [Suggestion Chip](#suggestion-chip)
- [Media Responses](#media-responses)
- [Helpers](#helpers)
- [User information](#user-information)
- [Date and Time](#date-and-time)
- [Place and Location](#place-and-location)
- [Confirmation](#confirmation)
- [Surface Capabilities](#surface-capabilities)

## Installation
Expand Down Expand Up @@ -275,10 +286,10 @@ $conv->close(BasicCard::create()

##### List

The single-select list presents the user with a vertical list of multiple items and allows the user to select a single one. Selecting an item from the list generates a user query (chat bubble) containing the title of the list item.

Please see the documentation [here](https://developers.google.com/actions/assistant/responses#list).

> The single-select list presents the user with a vertical list of multiple items and allows the user to select a single one. Selecting an item from the list generates a user query (chat bubble) containing the title of the list item.
```php
use Dialogflow\Action\Questions\ListCard;
use Dialogflow\Action\Questions\ListCard\Option;
Expand Down Expand Up @@ -327,6 +338,283 @@ if ('Get Option'==$agent->getIntent()) {
}
```

##### Carousel

Please see the documentation [here](https://developers.google.com/actions/assistant/responses#carousel).

> The carousel scrolls horizontally and allows for selecting one item. Compared to the list selector, it has large tiles-allowing for richer content. The tiles that make up a carousel are similar to the basic card with image. Selecting an item from the carousel will simply generate a chat bubble as the response just like with list selector.
```php
use Dialogflow\Action\Questions\Carousel;
use Dialogflow\Action\Questions\Carousel\Option;

$conv->ask('Please choose below');

$conv->ask(
Carousel::create()
->Option(
Option::create()
->key('OPTION_1')
->title('Option 1')
->synonyms(['option one', 'one'])
->description('Select option 1')
->image('https://picsum.photos/300/300')
)
->Option(
Option::create()
->key('OPTION_2')
->title('Option 2')
->synonyms(['option two', 'two'])
->description('Select option 2')
->image('https://picsum.photos/300/300')
)
->Option(
Option::create()
->key('OPTION_3')
->title('Option 3')
->synonyms(['option three', 'three'])
->description('Select option 3')
->image('https://picsum.photos/300/300')
)
->Option(
Option::create()
->key('OPTION_4')
->title('Option 4')
->synonyms(['option four', 'four'])
->description('Select option 4')
->image('https://picsum.photos/300/300')
)
);
```

To check if the user granted you the information and then access the data, create a Dialogflow intent with the `actions_intent_OPTION` event. Assuming you name the intent as `Get Option`, you can get the argument as follow,

```php
if ('Get Option'==$agent->getIntent()) {
$conv = $agent->getActionConversation();
$option = $conv->getArguments()->get('OPTION');

switch ($option) {
case 'OPTION_1':
$conv->close('You choose option 1');
break;

case 'OPTION_2':
$conv->close('You choose option 2');
break;

case 'OPTION_3':
$conv->close('You choose option 3');
break;

case 'OPTION_4':
$conv->close('You choose option 4');
break;

default:
$conv->close('Sorry, i do not understand');
break;
}
}
```

##### Browsing Carousel

Please see the documentation [here](https://developers.google.com/actions/assistant/responses#browsing_carousel).

> A browsing carousel is a rich response, similar to the carousel response as it scrolls horizontally and allows users to select a tile. Browsing carousels are designed specifically for web content by opening the selected tile in a web browser (or an AMP browser if all tiles are AMP-enabled). The browsing carousel will also persist on the user's Assistant surface for browsing later.
```php
use Dialogflow\Action\Responses\BrowseCarousel;
use Dialogflow\Action\Responses\BrowseCarousel\Option;

$conv->ask('Please choose below');

$conv->ask(
BrowseCarousel::create()
->imageDisplayOptions('CROPPED')
->addOption(
Option::create()
->title('Title of item 1')
->description('Description of item 1')
->footer('Item 1 footer')
->url('http://www.example.com')
->image('https://picsum.photos/300/300')
)
->addOption(
Option::create()
->title('Title of item 2')
->description('Description of item 2')
->footer('Item 2 footer')
->url('http://www.example.com')
->image('https://picsum.photos/300/300')
)
->addOption(
Option::create()
->title('Title of item 3')
->description('Description of item 3')
->footer('Item 3 footer')
->url('http://www.example.com')
->image('https://picsum.photos/300/300')
)
->addOption(
Option::create()
->title('Title of item 4')
->description('Description of item 4')
->footer('Item 4 footer')
->url('http://www.example.com')
->image('https://picsum.photos/300/300')
)
);
```

No follow-up fulfillment is necessary for user interactions with browse carousel items, since the carousel handles the browser handoff.

##### Suggestion Chip

Please see the documentation [here](https://developers.google.com/actions/assistant/responses#suggestion_chip).

```php
use Dialogflow\Action\Responses\LinkOutSuggestion;
use Dialogflow\Action\Responses\Suggestions;

$conv->ask('Please choose');
$conv->ask(new Suggestions(['Suggestion 1', 'Suggestion 2']));
$conv->ask(new Suggestions('Suggestion 3'));
$conv->ask(new LinkOutSuggestion('Website', 'http://www.example.com'));
```

##### Media Responses

Please see the documentation [here](https://developers.google.com/actions/assistant/responses#media_responses).

> Media responses let your Actions play audio content with a playback duration longer than the 120-second limit of SSML. The primary component of a media response is the single-track card.
```php
use Dialogflow\Action\Responses\MediaObject;
use Dialogflow\Action\Responses\MediaResponse;
use Dialogflow\Action\Responses\Suggestions;

$conv->ask('Here you go');
$conv->ask(
new MediaResponse(
MediaObject::create('http://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3')
->name('Jazz in Paris')
->description('A funky Jazz tune')
->icon('http://storage.googleapis.com/automotive-media/album_art.jpg')
->image('http://storage.googleapis.com/automotive-media/album_art.jpg')
)
);
$conv->ask(new Suggestions(['Pause', 'Stop', 'Start over']));
```

#### Helpers

##### User information

Please see the documentation [here](https://developers.google.com/actions/assistant/helpers#user_information).

```php
use Dialogflow\Action\Questions\Permission;

$conv->ask(Permission::create('To address you by name and know your location', ['NAME', 'DEVICE_PRECISE_LOCATION']));
```

To check if the user granted you the information and then access the data, create a Dialogflow intent with the `actions_intent_PERMISSION` event. Assuming you name the intent as `Get Permission`, you can get the information as follow,

```php
if ('Get Permission'==$agent->getIntent()) {
$conv = $agent->getActionConversation();
$approved = $conv->getArguments()->get('PERMISSION');

if ($approved) {
$name = $conv->getUser()->getName()->getDisplay();
$latlng = $conv->getDevice()->getLocation()->getCoordinates();
$lat = $latlng->getLatitude();
$lng = $latlng->getLongitude();

$conv->close('Got it, your name is ' . $name . ' and your coordinates are ' . $lat . ', ' . $lng);
} else {
$conv->close('Never mind then');
}
}
```

##### Date and Time

Please see the documentation [here](https://developers.google.com/actions/assistant/helpers#date_and_time).

```php
use Dialogflow\Action\Questions\DateTime;

$conv->ask(new DateTime('When do you want to come in?', 'What is the best date to schedule your appointment?', 'What time of day works best for you?'));
```

To check if the user granted access and then access the data, create a Dialogflow intent with the `actions_intent_DATETIME` event. Assuming you name the intent as `Get Date Time`, you can get the information as follow,

```php
if ('Get Date Time'==$agent->getIntent()) {
$conv = $agent->getActionConversation();
$date = $conv->getArguments()->get('DATETIME');

if ($date) {
$conv->close('Ok, got it, i will see you at ' . $date->format('r'));
} else {
$conv->close('Never mind then');
}
}
```

##### Place and Location

Please see the documentation [here](https://developers.google.com/actions/assistant/helpers#place_and_location).

```php
use Dialogflow\Action\Questions\Place;

$conv->ask(new Place('Where do you want to have lunch?', 'To find lunch locations'));
```

To check if the user granted access and then access the data, create a Dialogflow intent with the `actions_intent_PLACE` event. Assuming you name the intent as `Get Place`, you can get the information as follow,

```php
if ('Get Place'==$agent->getIntent()) {
$conv = $agent->getActionConversation();
$place = $conv->getArguments()->get('PLACE');

if ($place) {
$conv->close('Ok, got it, we\'ll meet at ' . $place->getFormattedAddress());
} else {
$conv->close('Never mind then');
}
}
```

##### Confirmation

Please see the documentation [here](https://developers.google.com/actions/assistant/helpers#confirmation).

```php
use Dialogflow\Action\Questions\Confirmation;

$conv->ask(new Confirmation('Can you confirm?'));
```

To check if the user confirmed or not, create a Dialogflow intent with the `actions_intent_CONFIRMATION` event. Assuming you name the intent as `Get Confirmation`, you can get the information as follow,

```php
if ('Get Confirmation'==$agent->getIntent()) {
$conv = $agent->getActionConversation();
$confirmed = $conv->getArguments()->get('CONFIRMATION');

if ($confirmed) {
$conv->close('Ok, it is confirmed');
} else {
$conv->close('Alright then, it is canceled');
}
}
```

#### Surface Capabilities

Google Assistant can be used on a variety of surfaces such as mobile devices that support audio and display experiences or a Google Home device that supports audio-only experiences.
Expand All @@ -337,12 +625,12 @@ To design and build conversations that work well on all surfaces, use [surface c
$surface = $conv->getSurface();

if ($surface->hasScreen()) {
// surface has screen
// surface has screen
} elseif ($surface->hasAudio()) {
// surface has audio
// surface has audio
} elseif ($surface->hasMediaPlayback()) {
// surface can play audio
// surface can play audio
} elseif ($surface->hasWebBrowser()) {
// user can interact with the content in a web browser
// user can interact with the content in a web browser
}
```

0 comments on commit 78d0a47

Please sign in to comment.