Last active
April 2, 2020 11:28
-
-
Save sirateek/f2cf0bcd64454cac2e2bb827974b5812 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
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { | |
const agent = new WebhookClient({ request, response }); | |
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers)); | |
console.log('Dialogflow Request body: ' + JSON.stringify(request.body)); | |
function welcome(agent) { | |
agent.add(`Welcome to my agent!`); | |
} | |
function fallback(agent) { | |
agent.add(`I didn't understand`); | |
agent.add(`I'm sorry, can you try again?`); | |
} | |
function productList(agent){ | |
var productListPayload = { | |
"type": "flex", | |
"altText": "Our Products list", | |
"contents": { | |
"type": "carousel", | |
"contents": [ | |
{ | |
"type": "bubble", | |
"hero": { | |
"type": "image", | |
"size": "full", | |
"aspectRatio": "20:13", | |
"aspectMode": "cover", | |
"url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_5_carousel.png" | |
}, | |
"body": { | |
"type": "box", | |
"layout": "vertical", | |
"spacing": "sm", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "Arm Chair, White", | |
"wrap": true, | |
"weight": "bold", | |
"size": "xl" | |
}, | |
{ | |
"type": "box", | |
"layout": "baseline", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "$49", | |
"wrap": true, | |
"weight": "bold", | |
"size": "xl", | |
"flex": 0 | |
}, | |
{ | |
"type": "text", | |
"text": ".99", | |
"wrap": true, | |
"weight": "bold", | |
"size": "sm", | |
"flex": 0 | |
} | |
] | |
} | |
] | |
}, | |
"footer": { | |
"type": "box", | |
"layout": "vertical", | |
"spacing": "sm", | |
"contents": [ | |
{ | |
"type": "button", | |
"style": "primary", | |
"action": { | |
"type": "uri", | |
"label": "Add to Cart", | |
"uri": "https://linecorp.com" | |
} | |
}, | |
{ | |
"type": "button", | |
"action": { | |
"type": "uri", | |
"label": "Add to wishlist", | |
"uri": "https://linecorp.com" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"type": "bubble", | |
"hero": { | |
"type": "image", | |
"size": "full", | |
"aspectRatio": "20:13", | |
"aspectMode": "cover", | |
"url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_6_carousel.png" | |
}, | |
"body": { | |
"type": "box", | |
"layout": "vertical", | |
"spacing": "sm", | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "Metal Desk Lamp", | |
"wrap": true, | |
"weight": "bold", | |
"size": "xl" | |
}, | |
{ | |
"type": "box", | |
"layout": "baseline", | |
"flex": 1, | |
"contents": [ | |
{ | |
"type": "text", | |
"text": "$11", | |
"wrap": true, | |
"weight": "bold", | |
"size": "xl", | |
"flex": 0 | |
}, | |
{ | |
"type": "text", | |
"text": ".99", | |
"wrap": true, | |
"weight": "bold", | |
"size": "sm", | |
"flex": 0 | |
} | |
] | |
}, | |
{ | |
"type": "text", | |
"text": "Temporarily out of stock", | |
"wrap": true, | |
"size": "xxs", | |
"margin": "md", | |
"color": "#ff5551", | |
"flex": 0 | |
} | |
] | |
}, | |
"footer": { | |
"type": "box", | |
"layout": "vertical", | |
"spacing": "sm", | |
"contents": [ | |
{ | |
"type": "button", | |
"flex": 2, | |
"style": "primary", | |
"color": "#aaaaaa", | |
"action": { | |
"type": "uri", | |
"label": "Add to Cart", | |
"uri": "https://linecorp.com" | |
} | |
}, | |
{ | |
"type": "button", | |
"action": { | |
"type": "uri", | |
"label": "Add to wish list", | |
"uri": "https://linecorp.com" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"type": "bubble", | |
"body": { | |
"type": "box", | |
"layout": "vertical", | |
"spacing": "sm", | |
"contents": [ | |
{ | |
"type": "button", | |
"flex": 1, | |
"gravity": "center", | |
"action": { | |
"type": "uri", | |
"label": "See more", | |
"uri": "https://linecorp.com" | |
} | |
} | |
] | |
} | |
} | |
] | |
} | |
} | |
var payload = new Payload("LINE", ) | |
} | |
let intentMap = new Map(); | |
intentMap.set('Default Welcome Intent', welcome); | |
intentMap.set('Default Fallback Intent', fallback); | |
intentMap.set('Product', productList); | |
agent.handleRequest(intentMap); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment