Skip to content

Commit 935c468

Browse files
committed
docs: update readme
1 parent 4a891fd commit 935c468

2 files changed

Lines changed: 52 additions & 27 deletions

File tree

firestore-dialogflow-fulfillment/POSTINSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This will create a new DialogFlow agent named `${param:AGENT_NAME}` for you. You
1010

1111
## Setting up DialogFlow Fulfillment
1212

13-
First, copy this URL `https://${param:LOCATION}-${param:PROJECT_ID}.cloudfunctions.net/ext-firestore-dialogflow-fulfillment-dialogflowFulfillment`, which is the URL of the DialogFlow webhook.
13+
First, copy this URL, which is the URL of the DialogFlow webhook: `https://${param:LOCATION}-${param:PROJECT_ID}.cloudfunctions.net/ext-firestore-dialogflow-fulfillment-dialogflowFulfillment`
1414

1515
Next, go to the DialogFlow console [here](https://dialogflow.cloud.google.com/#/agent/${param:PROJECT_ID}/fulfillment), enable the Webhook and add this URL as the Fulfillment webhook URL.
1616

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
# Firestore DialogFlow Fulfillment
22

3-
This extension integrates with DialogFlow through Firestore.
3+
This extension integrates with DialogFlow through Firestore, it can book meetings on your calendar from a DialogFlow conversation.
4+
5+
You don't need to interact with DialogFlow in your app as the extension do it for you and provide the conversation replies from DialogFlow in a Firestore collection.
46

57
## Install The Extension
68

7-
### Pre-requisites
9+
Make sure `firebase-tools` is installed: `npm i -g firebase-tools`.
810

9-
1. Make sure `firebase-tools` is installed: `npm i -g firebase-tools`.
10-
2. You are using Node 14 (`nvm use 14`).
11+
To install the extension, run:
1112

12-
#### Install
13+
```bash
14+
firebase ext:install path/to/extension --project=extensions-testing
15+
```
1316

14-
To install the extension, run:
17+
### DialogFlow agent setup
18+
19+
Before you can use the extension, you need to have a DialogFlow agent. The extension provides you with a HTTP function that you can call to create an agent for you, so you don't to do it manually.
20+
21+
To create and agent, you can call the `ext-firestore-dialogflow-fulfillment-createDialogflowAgent` function through the [Google Cloud CLI](https://cloud.google.com/sdk/gcloud):
1522

1623
```bash
17-
firebase ext:install . --project=extensions-testing
24+
gcloud config set project PROJECT_ID
25+
gcloud config set functions/region LOCATION
26+
gcloud functions call ext-firestore-dialogflow-fulfillment-createDialogflowAgent --data '{"data":""}'
1827
```
1928

29+
This will create a new DialogFlow agent for you. You can find the agent in the DialogFlow console [here](https://dialogflow.cloud.google.com/#/agents).
30+
31+
### Setting up DialogFlow Fulfillment
32+
2033
The extension will deploy a HTTP function that will be used as a Fullfilment webhook for DialogFlow. The function will look like this, with the `PROJECT_ID` replaced with your project ID, and the `LOCATION` replaced with your project's default Cloud Functions location:
2134

2235
```bash
@@ -25,32 +38,44 @@ https://{LOCATION}-{PROJECT_ID}.cloudfunctions.net/ext-firestore-dialogflow-fulf
2538

2639
Provide the URL to DialogFlow as the Fulfillment webhook URL.
2740

28-
### Development
41+
### Give the extension access to your calendar
2942

30-
1. `cd firestore-dialogflow-fulfillment/functions` && `npm run build`
31-
2. `cd firestore-dialogflow-fulfillment/demo` && `npm run dev`
32-
3. `cd _emulator` && `firebase emulators:start`
43+
To allow the extension to create events, you need to give it access to the calendar `${param:CALENDAR_ID}`. To do this, copy the extension service account principal email address from the [Service Accounts page](https://console.cloud.google.com/iam-admin/serviceaccounts) in the Google Cloud Console, which starts with `ext-firestore-dialogflow`. Then, go to your calendar Sharing settings, and add the email with **Make changes to events** permission.
3344

34-
## DialogFlow
45+
## Using the extension
3546

36-
https://dialogflow.cloud.google.com/#/agent/extensions-testing/editIntent/334a55e8-3280-4651-b1d8-109ceb78cfd4/
47+
Call `newConversation` with a `message` to start a new conversation, which will return a `conversationId` that you can use to send messages to the same conversation.
3748

38-
- Agent = Overall agent who will handle the conversation
39-
- Intent = Based on user input, dialogflow will match to an intent based on the settings in that intent
40-
- We are trying to get a DATE & TIME from the user (to do something with, e.g. add something to Google calendar)
41-
- If DialogFlow doesn't have both parameters, it will ask the user for them (based on ML and the data in the intent config)
49+
```ts
50+
export async function newConversation(message: string): Promise<string> {
51+
const result = await httpsCallable<{ message: string }, string>(
52+
functions,
53+
"ext-firestore-dialogflow-fulfillment-newConversation"
54+
)({ message });
55+
return result.data;
56+
}
57+
```
4258

43-
- Each time DialogFlow gets a message, it'll send it through the webhook (https://dialogflow.cloud.google.com/#/agent/extensions-testing/fulfillment)
44-
- In our webhook logic, if the intent matches one we care about AND we have both DATE & TIME parameters, we'll send a message to the user, otherwise just let DialogFlow handle it.
45-
- At this point we'll go and do some API task and respond to the user (e.g. "I've added that to our calendar, see you on X at Y")
59+
To add new messages to the conversation, call `newMessage` with the `conversationId` and `message`.
60+
61+
```ts
62+
export async function newMessage(
63+
conversationId: string,
64+
message: string
65+
): Promise<void> {
66+
await httpsCallable<{ conversationId: string; message: string }, void>(
67+
functions,
68+
"ext-firestore-dialogflow-fulfillment-newMessage"
69+
)({ conversationId, message });
70+
}
71+
```
4672

47-
(Note: Been using https://ngrok.com/ to pipe the webhook messages to the emulator - just needs installing and setting up on the port functions are running on).
73+
## Development
4874

49-
The current general flow for the extension is:
75+
1. `cd firestore-dialogflow-fulfillment/functions` && `npm run build`
76+
2. `cd firestore-dialogflow-fulfillment/demo` && `npm run dev`
77+
3. `cd _emulator` && `firebase emulators:start`
5078

51-
- `newConversation` - Callable Function. Takes a message, creates a new conversation and adds a doc to a subcollection, and returns the ID (which the user can use to listen to new messages).
52-
- `newMessage` - adds a new user message to the conversation
53-
- `onNewMessage` - a firestore trigger that listens for new messages. If it's from the user, we'll send a message to dialog flow and wait for a response. Once we have that, add a message to the conversation.
54-
- `dialogflowFulfillment` - HTTP function (ignores auth for now), which DialogFlow calls - here we can respond with our own messages to the user if we want.
79+
(Note: Been using https://ngrok.com/ to pipe the webhook messages to the emulator - just needs installing and setting up on the port functions are running on).
5580

5681
Use `lsof -t -i:4001 -i:8080 -i:9000 -i:9099 -i:9199 -i:8085 | xargs kill -9` to kill emulators.

0 commit comments

Comments
 (0)