Created
December 3, 2019 18:32
-
-
Save PamornT/d21724bb7860ecf810ea6da1d34e9f7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const REGION = 'asia-northeast1' | |
const runtimeOpts = { | |
timeoutSeconds: 10, | |
memory: "2GB" | |
} | |
const functions = require('firebase-functions') | |
const {WebhookClient, Payload} = require("dialogflow-fulfillment") | |
const message = require('./message') | |
let parameters | |
exports.dialogflowFulfillment = functions.region(REGION).runWith(runtimeOpts).https.onRequest(async (request, response) => { | |
parameters = request.body.queryResult.parameters | |
agent = new WebhookClient({request,response}) | |
let intentMap = new Map() | |
intentMap.set('Order', orderSlotFilling) | |
agent.handleRequest(intentMap) | |
}) | |
const orderSlotFilling = async () => { | |
let {size, color, qty} = parameters | |
let filling_message = '' | |
if (!size) { | |
filling_message = message.size_filling() | |
} else if(!color) { | |
filling_message = message.color_filling() | |
} else if(!qty) { | |
filling_message = message.qty_filling() | |
} | |
if(filling_message !== '') { | |
let payload = new Payload(`LINE`, filling_message, {sendAsMessage: true}) | |
return agent.add(payload) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment