This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0378d00
commit b848ff7
Showing
8 changed files
with
458 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Dialogflow\Action\Arguments | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
## Methods | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
|[__construct](#arguments__construct)|| | ||
|[get](#argumentsget)|Get argument by name.| | ||
|
||
|
||
|
||
|
||
### Arguments::__construct | ||
|
||
**Description** | ||
|
||
```php | ||
public __construct (array $data) | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
**Parameters** | ||
|
||
* `(array) $data` | ||
: request array | ||
|
||
**Return Values** | ||
|
||
|
||
|
||
|
||
### Arguments::get | ||
|
||
**Description** | ||
|
||
```php | ||
public get (string $name) | ||
``` | ||
|
||
Get argument by name. | ||
|
||
|
||
|
||
**Parameters** | ||
|
||
* `(string) $name` | ||
|
||
**Return Values** | ||
|
||
`null|array|bool` | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Dialogflow\Action\Questions\DateTime | ||
|
||
|
||
|
||
## Implements: | ||
Dialogflow\Action\Interfaces\QuestionInterface | ||
|
||
|
||
|
||
## Methods | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
|[__construct](#datetime__construct)|Constructor for DateTime object.| | ||
|[renderRichResponseItem](#datetimerenderrichresponseitem)|Render a single Rich Response item as array.| | ||
|[renderSystemIntent](#datetimerendersystemintent)|Render System Intent as array.| | ||
|
||
|
||
|
||
|
||
### DateTime::__construct | ||
|
||
**Description** | ||
|
||
```php | ||
public __construct (string $requestDateTimeText, string $requestDateText, string $requestTimeText) | ||
``` | ||
|
||
Constructor for DateTime object. | ||
|
||
|
||
|
||
**Parameters** | ||
|
||
* `(string) $requestDateTimeText` | ||
: initial question | ||
* `(string) $requestDateText` | ||
: follow up question about the exact date | ||
* `(string) $requestTimeText` | ||
: follow up question about the exact time | ||
|
||
**Return Values** | ||
|
||
`\Dialogflow\Action\Questions\DateTime` | ||
|
||
|
||
|
||
|
||
|
||
### DateTime::renderRichResponseItem | ||
|
||
**Description** | ||
|
||
```php | ||
public renderRichResponseItem (void) | ||
``` | ||
|
||
Render a single Rich Response item as array. | ||
|
||
|
||
|
||
**Parameters** | ||
|
||
`This function has no parameters.` | ||
|
||
**Return Values** | ||
|
||
`null|array` | ||
|
||
|
||
|
||
|
||
|
||
### DateTime::renderSystemIntent | ||
|
||
**Description** | ||
|
||
```php | ||
public renderSystemIntent (void) | ||
``` | ||
|
||
Render System Intent as array. | ||
|
||
|
||
|
||
**Parameters** | ||
|
||
`This function has no parameters.` | ||
|
||
**Return Values** | ||
|
||
`null|array` | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Dialogflow\Action\Questions; | ||
|
||
use Dialogflow\Action\Interfaces\QuestionInterface; | ||
|
||
class DateTime implements QuestionInterface | ||
{ | ||
/** @var string */ | ||
protected $requestDateTimeText; | ||
|
||
/** @var string */ | ||
protected $requestDateText; | ||
|
||
/** @var string */ | ||
protected $requestTimeText; | ||
|
||
/** | ||
* Constructor for DateTime object. | ||
* | ||
* @param string $requestDateTimeText initial question | ||
* @param string $requestDateText follow up question about the exact date | ||
* @param string $requestTimeText follow up question about the exact time | ||
* | ||
* @return Dialogflow\Action\Questions\DateTime | ||
*/ | ||
public function __construct($requestDateTimeText, $requestDateText, $requestTimeText) | ||
{ | ||
$this->requestDateTimeText = $requestDateTimeText; | ||
$this->requestDateText = $requestDateText; | ||
$this->requestTimeText = $requestTimeText; | ||
} | ||
|
||
/** | ||
* Render a single Rich Response item as array. | ||
* | ||
* @return null|array | ||
*/ | ||
public function renderRichResponseItem() | ||
{ | ||
$out = []; | ||
|
||
$out['simpleResponse'] = ['textToSpeech' => 'PLACEHOLDER']; | ||
|
||
return $out; | ||
} | ||
|
||
/** | ||
* Render System Intent as array. | ||
* | ||
* @return null|array | ||
*/ | ||
public function renderSystemIntent() | ||
{ | ||
$out = []; | ||
|
||
$out['intent'] = 'actions.intent.DATETIME'; | ||
$out['data'] = [ | ||
'@type' => 'type.googleapis.com/google.actions.v2.DateTimeValueSpec', | ||
'dialogSpec' => [ | ||
'requestDatetimeText' => $this->requestDateTimeText, | ||
'requestDateText' => $this->requestDateText, | ||
'requestTimeText' => $this->requestTimeText, | ||
], | ||
]; | ||
|
||
return $out; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Dialogflow\tests\Action; | ||
|
||
use Dialogflow\Action\Questions\DateTime; | ||
use Dialogflow\WebhookClient; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DateTimeTest extends TestCase | ||
{ | ||
private function getConversation() | ||
{ | ||
$data = json_decode(file_get_contents(__DIR__.'/../../stubs/request-v2-google.json'), true); | ||
|
||
$agent = new WebhookClient($data); | ||
|
||
return $agent->getActionConversation(); | ||
} | ||
|
||
private function getConversationResponse() | ||
{ | ||
$data = json_decode(file_get_contents(__DIR__.'/../../stubs/request-v2-google-datetime.json'), true); | ||
|
||
$agent = new WebhookClient($data); | ||
|
||
return $agent->getActionConversation(); | ||
} | ||
|
||
public function testCreate() | ||
{ | ||
$conv = $this->getConversation(); | ||
|
||
$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?')); | ||
|
||
$this->assertEquals([ | ||
'expectUserResponse' => true, | ||
'richResponse' => [ | ||
'items' => [ | ||
0 => [ | ||
'simpleResponse' => [ | ||
'textToSpeech' => 'PLACEHOLDER', | ||
], | ||
], | ||
], | ||
], | ||
'systemIntent' => [ | ||
'intent' => 'actions.intent.DATETIME', | ||
'data' => [ | ||
'@type' => 'type.googleapis.com/google.actions.v2.DateTimeValueSpec', | ||
'dialogSpec' => [ | ||
'requestDatetimeText' => 'When do you want to come in?', | ||
'requestDateText' => 'What is the best date to schedule your appointment?', | ||
'requestTimeText' => 'What time of day works best for you?', | ||
], | ||
], | ||
], | ||
], $conv->render()); | ||
} | ||
|
||
public function testResponse() | ||
{ | ||
$conv = $this->getConversationResponse(); | ||
|
||
$date = $conv->getArguments()->get('DATETIME'); | ||
|
||
$this->assertInstanceOf('Carbon\Carbon', $date); | ||
} | ||
} |
Oops, something went wrong.