"Hello World" sample for the Multivocal library
The code is roughly broken into three parts:
-
Load the Multivocal library.
-
Build our configuration.
We'll use a simple configuration object that takes the JSON for the configuration.
We need to define the Action.multivocal.welcome response, and we'll define it for the undefined locale. This response says that for any incoming request that is for the Action with the name
multivocal.welcome
, format the Template with this text to use as our message. Furthermore, after we send this message, we should close the conversation.The
multivocal.welcome
Action is one that is provided by the standard Intents, and is called when the conversation begins.Building the configuration automatically adds it to Multivocal's configuration.
We also have two lines commented out that read additional configuration from a Firebase db or a Firestore db.
-
Register the function to be called when a request comes in from Dialogflow and have multivocal process it.
In this case, we're using the Firebase webhook processor to process from Firebase Cloud Functions, but there are also processors for Google Cloud Functions (which are slightly different), an Express function, or if you're using AWS Lambda.
These instructions seem long, but they're pretty much the same steps that you would do for any Actions-on-Google / Dialogflow project, no matter if you were using Multivocal or not.
-
Clone or otherwise download this package with a command line such as
git clone https://github.com/afirstenberg/multivocal-hello.git
-
Install libraries from the command line
cd multivocal-hello/functions; npm install
-
Create the Google Project you'll run this under. This will include the Firebase Project for Firebase Cloud Functions, the Actions on Google Project, and the Dialogflow Project. Google has directions for doing this, but in general the steps will be something like:
-
Go to https://console.firebase.google.com/ and create a new Firebase project.
-
Go to https://console.actions.google.com/ and import the same project you just created in the Firebase console.
-
Select a Dialogflow app to build, which will open the Dialogflow console for this project. Enter the basic configuration info for the project and create it.
-
-
Configure your copy of this package to use your Firebase project with something like this on your command line
firebase use your-project-name
-
Deploy the function to Firebase
firebase deploy --only functions
You should see the URL for your function. Make note of this for later or you'll be able to find it again on the Firebase console.
-
Load the Intents into Dialogflow.
-
In the Dialogflow console, select the gear next to the name of the project in the left navigation menu.
-
Select the "Export and Import" tab and then the "Import from Zip" button.
-
Load the
standard.zip
file from themultivocal-hello/functions/node_modules/multivocal/dialogflow
folder. Enter "IMPORT" into the confirmation field to import the files. -
There are no other configurations to load. If there were, you would load each using similar steps. (Other example projects may require additional Intents. This one just uses the standard Intents.)
-
Go back to the list of Intents and delete the "Default Fallback Intent" and "Default Welcome Intent".
-
-
Configure Dialogflow to use your Firebase Cloud Function webhook.
-
Select "Fulfillment" from the left navigation.
-
Turn the switch to "Enabled" for the Webhook.
-
Enter the URL for your function that was given to you on the command line when you did the deploy. If it is missing, you can also find it in the Firebase Console by selecting the "Functions" left navigation.
-
-
Deploy and test to the Assistant.
-
Select "Integrations" from the left navigation.
-
Select the "Google Assistant".
-
Click "Test" to open a new tab with the Actions Simulator.
-
Enter "talk to my test app" and it should work. You can see the invocation in the Firebase Cloud Functions log. You can also invoke it from your phone or smart speaker by talking to the Google Assistant and asking to talk to "my test app".
-
If you make changes to the phrase that the agent say, or when you add more Intents and the phrases to handle them, you would just repeat step 5.