Showing
4 changed files
with
102 additions
and
0 deletions
dialogflowFulfillment/README.md
0 → 100644
1 | +# Dialogflow: Webhook Template using Node.js and Cloud Functions for Firebase | ||
2 | + | ||
3 | +## Setup Instructions | ||
4 | + | ||
5 | +### Steps | ||
6 | +1. Deploy the fulfillment webhook provided in the functions folder using [Google Cloud Functions for Firebase](https://firebase.google.com/docs/functions/): | ||
7 | + 1. Follow the instructions to [set up and initialize Firebase SDK for Cloud Functions](https://firebase.google.com/docs/functions/get-started#set_up_and_initialize_functions_sdk). Make sure to select the project that you have previously generated in the Actions on Google Console and to reply `N` when asked to overwrite existing files by the Firebase CLI. | ||
8 | + 2. Navigate to the <code>firebase/functions</code> directory and run <code>npm install</code>. | ||
9 | + 3. Run `firebase deploy --only functions` and take note of the endpoint where the fulfillment webhook has been published. It should look like `Function URL (yourAction): https://${REGION}-${PROJECT}.cloudfunctions.net/yourAction` | ||
10 | +2. Go to the Dialogflow console and select *Fulfillment* from the left navigation menu. | ||
11 | +3. Enable *Webhook*, set the value of *URL* to the `Function URL` from the previous step, then click *Save*. | ||
12 | +4. Select *Intents* from the left navigation menu. Select the `Default Welcome Intent` intent, scroll down to the end of the page and click *Fulfillment*, check *Use webhook* and then click *Save*. This will allow you to have the welcome intent be a basic webhook intent to test. | ||
13 | +5. Build out your agent and business logic by adding function handlers for Dialogflow actions. | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
dialogflowFulfillment/firebase/firebase.json
0 → 100644
1 | +{} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs | ||
2 | +// for Dialogflow fulfillment library docs, samples, and to report issues | ||
3 | +'use strict'; | ||
4 | + | ||
5 | +const functions = require('firebase-functions'); | ||
6 | +const {WebhookClient} = require('dialogflow-fulfillment'); | ||
7 | +const {Card, Suggestion} = require('dialogflow-fulfillment'); | ||
8 | + | ||
9 | +process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements | ||
10 | + | ||
11 | +exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { | ||
12 | + const agent = new WebhookClient({ request, response }); | ||
13 | + console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers)); | ||
14 | + console.log('Dialogflow Request body: ' + JSON.stringify(request.body)); | ||
15 | + | ||
16 | + function welcome(agent) { | ||
17 | + agent.add(`안녕하세요 효율적인 수면패턴을 도와드릴 꿀잠봇 입니다!`); | ||
18 | + } | ||
19 | + | ||
20 | + function fallback(agent) { | ||
21 | + agent.add(`잘못된 입력값 입니다`); | ||
22 | + } | ||
23 | + | ||
24 | + function test1(agent){ | ||
25 | + const mytime = agent.parameters.hours; | ||
26 | + agent.setContext(); | ||
27 | + agent.add('수면 시간이 등록되었습니다'); | ||
28 | + } | ||
29 | + | ||
30 | + // // Uncomment and edit to make your own intent handler | ||
31 | + // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);` | ||
32 | + // // below to get this function to be run when a Dialogflow intent is matched | ||
33 | + // function yourFunctionHandler(agent) { | ||
34 | + // agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`); | ||
35 | + // agent.add(new Card({ | ||
36 | + // title: `Title: this is a card title`, | ||
37 | + // imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png', | ||
38 | + // text: `This is the body text of a card. You can even use line\n breaks and emoji! 💁`, | ||
39 | + // buttonText: 'This is a button', | ||
40 | + // buttonUrl: 'https://assistant.google.com/' | ||
41 | + // }) | ||
42 | + // ); | ||
43 | + // agent.add(new Suggestion(`Quick Reply`)); | ||
44 | + // agent.add(new Suggestion(`Suggestion`)); | ||
45 | + // agent.setContext({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }}); | ||
46 | + // } | ||
47 | + | ||
48 | + // // Uncomment and edit to make your own Google Assistant intent handler | ||
49 | + // // uncomment `intentMap.set('your intent name here', googleAssistantHandler);` | ||
50 | + // // below to get this function to be run when a Dialogflow intent is matched | ||
51 | + // function googleAssistantHandler(agent) { | ||
52 | + // let conv = agent.conv(); // Get Actions on Google library conv instance | ||
53 | + // conv.ask('Hello from the Actions on Google client library!') // Use Actions on Google library | ||
54 | + // agent.add(conv); // Add Actions on Google library responses to your agent's response | ||
55 | + // } | ||
56 | + // // See https://github.com/dialogflow/fulfillment-actions-library-nodejs | ||
57 | + // // for a complete Dialogflow fulfillment library Actions on Google client library v2 integration sample | ||
58 | + | ||
59 | + // Run the proper function handler based on the matched Dialogflow intent name | ||
60 | + let intentMap = new Map(); | ||
61 | + intentMap.set('Default Welcome Intent', welcome); | ||
62 | + intentMap.set('Default Fallback Intent', fallback); | ||
63 | + intentMap.set('test',test1); | ||
64 | + // intentMap.set('your intent name here', googleAssistantHandler); | ||
65 | + agent.handleRequest(intentMap); | ||
66 | +}); |
1 | +{ | ||
2 | + "name": "dialogflowFirebaseFulfillment", | ||
3 | + "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase", | ||
4 | + "version": "0.0.1", | ||
5 | + "private": true, | ||
6 | + "license": "Apache Version 2.0", | ||
7 | + "author": "Google Inc.", | ||
8 | + "engines": { | ||
9 | + "node": "8" | ||
10 | + }, | ||
11 | + "scripts": { | ||
12 | + "start": "firebase serve --only functions:dialogflowFirebaseFulfillment", | ||
13 | + "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment" | ||
14 | + }, | ||
15 | + "dependencies": { | ||
16 | + "actions-on-google": "^2.2.0", | ||
17 | + "firebase-admin": "^5.13.1", | ||
18 | + "firebase-functions": "^2.0.2", | ||
19 | + "dialogflow": "^0.6.0", | ||
20 | + "dialogflow-fulfillment": "^0.5.0" | ||
21 | + } | ||
22 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment