今天我們則要討論到setting、fullfillment webhhok及integration
首先,點擊左上方齒輪
提供許多選項
常用的有export import 幫助你導入倒出你的劇本為zip
而點擊到左側fullfillment就可以轉入他的介面,在url可以貼上你部屬的function,inline editor則可以讓你直接編譯。
Integration就可以與google assistant 整合
回過頭來我們來設置webhook,這邊我的webhook包含
index.js
建立onrequest function,建立message格式轉為dialogflowMessage並用switch case分配action的種類
import * as functions from 'firebase-functions'
import * as firebaseAdmin from "firebase-admin"
import * as workflow from "./workFlow"
import { Message, MessageInterface } from "./model"
import * as cors from 'cors'
const corsHandler = cors({ origin: true })
firebaseAdmin.initializeApp(functions.config().firebase)
export const fulfillmentWebhook = functions.https.onRequest(async (req: functions.https.Request, res: functions.Response<any>) => {
corsHandler(req, res, async () => {
console.log('Fulfillment Request headers: ' + JSON.stringify(req.headers))
console.log('Fulfillment Request body: ' + JSON.stringify(req.body));
console.log("fulfillmentWebhook start !!")
const session = req.body.seesion
const queryResult = req.body.queryResult
const queryText = queryResult.queryText
const action = queryResult.action
const parameters = queryResult.parameters
const time = new Date().getTime()
console.log('parameters:', parameters)
console.log('action:', action)
const message: MessageInterface = {
session: session,
queryText: queryText,
action: action,
parameters: parameters,
// idToken: idToken,
time: time,
res: res
}
const dialogflowMessage = new Message(message)
await actionDispatcher(dialogflowMessage)
})
})
export const actionDispatcher = async (dialogflowMessage: MessageInterface): Promise<any> => {
const action = dialogflowMessage.action
console.log("action:", action)
switch (action) {
////下面是格式 可參考
case "parameter":
await workflow.function(dialogflowMessage)
default:
dialogflowMessage.res.status(200)
break;
}
}
明天,我們再繼續講解