Skip to content

Commit f79e2a2

Browse files
committed
Use the action field instead of the intent name to determine what should happen
1 parent 4acdc0c commit f79e2a2

5 files changed

+21
-6
lines changed

README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ After creating a new agent, you click the gear wheal in the top left, next to yo
2626
![Dialogflow settings](docs/dialogflow-settings.png)
2727

2828
After going to the settings, choose the Export and Import tab. Choose `Restore from zip` to clone the project from the zip file.
29-
Read [the dialogflow docs](https://dialogflow.com/docs/agents/export-import-restore) for more information.
30-
29+
Read [the dialogflow docs](https://dialogflow.com/docs/agents/export-import-restore) for more information.
3130

3231
### Webhook
3332
In order to deploy your webhook, you can use Heroku as a free and easy hosting service. This repository already contains
@@ -46,6 +45,23 @@ Ensure that you update your DialogFlow project with the correct fulfillment URL.
4645
its requests. You can change this by going to [the DialogFlow console](https://console.dialogflow.com), and going to the fulfillment page for your agent. The domain
4746
there should correspond with your own domain, or the one generated for your Heroku project.
4847

48+
## Usage
49+
Send requests from DialogFlow to the `/dialogflow/intent/handle` endpoint.
50+
Supported intents:
51+
- `next-departure` to get the next departures from a stop, with parameters:
52+
- `transportation-method`: bust, tram, train, metro, ferry
53+
- `location`: stop location name
54+
55+
- `plan-route` to plan a route from A to B, with parameters:
56+
- `origin`: Origin stop location name
57+
- `destination`: Destination stop location name
58+
59+
When using your own DialogFlow agen, ensure that both the intent action (for example `plan-route`) and parameters are
60+
correctly configured in your agent. If they are not correctly configured, the intent will not be recognized correctly.
61+
An example configuration can be seen in the image below.
62+
63+
![Dialogflow action and parameters](docs/dialogflow-action-parameters.png)
64+
4965
## Forking, reporting issues and creating pull requests
5066

5167
This project is meant as an example and base to create your own, better version of it.

app/Http/Controllers/DialogFlowController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static function buildDialogFlowResponse(string $responseText, bool $isEnd
8787
*/
8888
public function redirectIntentToController()
8989
{
90-
switch ($this->_dialogFlowPayload->getIntentDisplayName()) {
90+
switch ($this->_dialogFlowPayload->getAction()) {
9191
case 'next-departure':
9292
// There are likely nicer options to do this, and definitely a more efficient one,
9393
// but it ain't stupid if it works
@@ -100,7 +100,7 @@ public function redirectIntentToController()
100100
return $controller->getRoutePlanning();
101101
default:
102102
return self::createTextToSpeechResponse(
103-
"I can only tell you about the next departures or plan routes for you");
103+
"I can only tell you about the next departures or plan routes for you.");
104104
}
105105
}
106106

app/Http/Controllers/RoutePlanningController.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public function getRoutePlanning()
6161

6262
// In case no result was found, we tell this to user.
6363
if (count($response->getTrips()) == 0) {
64-
return $this->createTextToSpeechResponse("I could not find any route " . strtolower($this->getDialogFlowPayload()->getParameter("transportation-method")) .
65-
" from " . $origin->getName() . " to " . $destination->getName());
64+
return $this->createTextToSpeechResponse("I could not find any route from " . $origin->getName() . " to " . $destination->getName());
6665
}
6766

6867
// We will tell the user about the first found result

docs/dialogflow-action-parameters.png

19.6 KB
Loading
1.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)