Google Assistant and Node JS (Miss Duck) V2
Integrate Google Assistant, Dialog Flow V2
with actions-on-google in NodeJS and Nexmo Stitch conversation platform
Continues Miss Duck V1
Find the updated Miss Duck project on GitHub
Presentation Video
The Google Dialog Flow project is constantly improving, and it really gets interesting to follow. This time while we are integrating Nexmo Stitch (The in app-conversation API from Nexmo) to allow Miss duck send events to a conversation platform. In the presentation above you can see about a use case regarding accessibility to a communication platform.
Updating Miss Duck
Update Dialog Flow V2
Navigate to your Dialog Flow agent and enable V2 that is officially released
![]() |
Dialog Flow agent settings |
NodeJS actions-on-google
Update your NodeJS library to ^2.3.0:
"actions-on-google": "^2.3.0",
Using the most recent version of the actions-on-google library will help you stay aligned with the latest Dialog Flow updates.
You will notice breaking changes from V1 but also how much simpler it is now to perform simple actions.
Install Nexmo-Stitch
Add to your project Nexmo-Stitch (nodejs browser and node library)
"nexmo-stitch": "^1.0.14",
Configure Nexmo Account
Create an account at Nexmo and follow the getting started guideTo keep out of git the Nexmo credentials we are using a config reader library, and use .gitignore to make sure we don't push them to git
![]() |
git ignore Nexmo / production sensitive information |
Remember, if you accidentally committed sensitive information, it is not easy to take it back. Best actions would be to invalidate your private key and use another one, and/or your account secret (using Nexmo dashboard). Git is sending out emails with changes to any user subscribed to your project.
Update your node project
The service is now simpler to start and use actions-on-google.
Starting the server on port 8000
Starting the server on port 8000
const express = require('express')
const bodyParser = require("body-parser");
const Duck = require('./duck');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
new Duck(app);
express().use(bodyParser.json(), app).listen(8000, () =>
console.log('Duck service! port:8000'));
Setup Nexmo-Stitch
Load the conversationClient that will help you create conversations and send Text events.
const ConversationClient = require('nexmo-stitch');
const conversationClient = new ConversationClient();
Load the Nexmo node library that will help you setup your user
const Nexmo = require('nexmo');
const nexmo = new Nexmo({
apiKey: API_KEY,
apiSecret: API_SECRET,
applicationId: APP_ID,
privateKey: PRIVATE_KEY_PATH,
});
Setup A Nexmo User
Using Nexmo node to create a user
nexmo.users.create({
name: "Ducky",
display_name: "Miss Duck",
diplay_url: "https://upload.wikimedia.org/wikipedia/commons/2/2a/Duck-293474_white_background.jpg"
});
return conv.ask(`welcome Ducky!, new user is ready`);
Set up A conversation
- Create a JWT token to access the conversationClient API
- Login using the token
- Create a new conversation and Join the user
const jwt = nexmo.generateJwt({
application_id: APP_ID,
sub: "Ducky",//Agent1
exp: (new Date().getTime() + 60 * 60 * 1000) / 1000,
acl: { "paths": { "/v1/users/**": {}, "/v1/conversations/**": {},
"/v1/sessions/**": {}, "/v1/devices/**": {}, "/v1/image/**": {},
"/v3/media/**": {}, "/v1/applications/**": {}, "/v1/push/**": {},
"/v1/knocking/**": {} } }
"/v1/sessions/**": {}, "/v1/devices/**": {}, "/v1/image/**": {},
"/v3/media/**": {}, "/v1/applications/**": {}, "/v1/push/**": {},
"/v1/knocking/**": {} } }
});
conversationClient.login(jwt)
.then((stitchApp) => {
console.log('logged in');
conv.ask(`logged in as Kostas!`);
return stitchApp.newConversationAndJoin({ display_name: "Stitch Duck" })
.then((conversation) => {
console.log('created conversation' + conversation.display_name);
});
}).catch(error => console.log(error));
Setup an Intent
Listen to intents with name "login" (configured in V1 using Dialog Flow)
app.intent('login', conv => {
console.log("intent was called");
});
Combine the above to drive the Conversation with Actions
Listen for the "login intent" and then create a new conversation and join your user in it
app.intent('login', conv => {
console.log("intent was called");
return conversationClient.login(jwt)
.then((stitchApp) => {
console.log('logged in');
conv.ask(`logged in as Kostas!`);
return stitchApp.newConversationAndJoin({ display_name: "Stitch Duck" })
.then((conversation) => {
console.log('created conversation' + conversation.display_name);
conv.ask(`Welcome to the conversation ${conversation.display_name}`);
this.conversation = conversation;
});
}).catch(error => console.log(error));
});
Next Steps
You can continue the above integration to play with a second user in Stitch where you can start sending text events.
Next step would be to join a second user using a web interface (Web app). When both users will be in the same conversation they can send/receive Text events. (you can join a conversation, no need to always create a new one).
Then you can use the intent to parse a payload from what the user said. Use that payload to send it as a Text event to the other user in the conversation.
HAVE FUN!
ENjOY
Best Play at Merit Casino - Curacao
ReplyDelete› gambling › merit-casino › gambling › merit-casino 메리트 카지노 도메인 Merit Casino: Best online casino! No deposit and bonus. Top 20 free slots & casino games. Play now!