選定了第一種架構圖和開發語言Node.js,那就開始寫codig。
1.下載Node.js https://nodejs.org/en/ (後面是用Mac示範)
2.下載Visual Studio Code https://code.visualstudio.com/?wt.mc_id=vscom_downloads
Firebase Functions:
const functions = require('firebase-functions')
// ... app code here
exports.fulfillment = functions.https.onRequest(app)
Actions Console Inline Editor:
const functions = require('firebase-functions')
// ... app code here
// name has to be `ActionsOnGoogleFulfillment`
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app)
Self Hosted Express Server:
const express = require('express')
const bodyParser = require('body-parser')
// ... app code here
const expressApp = express().use(bodyParser.json())
expressApp.post('/fulfillment', app)
expressApp.listen(8080)
// ... app code start here
//build an app instance in your fulfillment webhook, follow these steps:
//step1:Call the require() function
// Import the service function and various response classes
const {
dialogflow,
actionssdk,
Image,
Table,
Carousel,
Payload,
Permission
} = require('actions-on-google');
//step2:configure the app instance
const app = dialogflow({
debug: true
});
//intent process
app.intent('intent_name', (conv) => {
conv.ask('How are you?'); //回覆文字
});
// ... app code end here
//external API start
//external API end
使用心得:
利用上面的方法,就可以輕鬆專注的開發意圖處理(intent_process)。
參考:
https://github.com/actions-on-google/assistant-conversation-nodejs
https://github.com/googleapis/nodejs-dialogflow
https://developers.google.com/assistant/conversational/df-asdk/reference/nodejsv2/overview