최한솔

time value test

1 // See https://github.com/dialogflow/dialogflow-fulfillment-nodejs 1 // See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
2 // for Dialogflow fulfillment library docs, samples, and to report issues 2 // for Dialogflow fulfillment library docs, samples, and to report issues
3 'use strict'; 3 'use strict';
4 - 4 +
5 const functions = require('firebase-functions'); 5 const functions = require('firebase-functions');
6 const {WebhookClient} = require('dialogflow-fulfillment'); 6 const {WebhookClient} = require('dialogflow-fulfillment');
7 const {Card, Suggestion} = require('dialogflow-fulfillment'); 7 const {Card, Suggestion} = require('dialogflow-fulfillment');
8 - 8 +
9 process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements 9 process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
10 - 10 +
11 exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { 11 exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
12 const agent = new WebhookClient({ request, response }); 12 const agent = new WebhookClient({ request, response });
13 console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers)); 13 console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
14 console.log('Dialogflow Request body: ' + JSON.stringify(request.body)); 14 console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
15 - 15 +
16 function welcome(agent) { 16 function welcome(agent) {
17 agent.add(`안녕하세요 효율적인 수면패턴을 도와드릴 꿀잠봇 입니다!`); 17 agent.add(`안녕하세요 효율적인 수면패턴을 도와드릴 꿀잠봇 입니다!`);
18 } 18 }
19 - 19 +
20 function fallback(agent) { 20 function fallback(agent) {
21 agent.add(`잘못된 입력값 입니다`); 21 agent.add(`잘못된 입력값 입니다`);
22 } 22 }
23 - 23 +
24 + var mytime;
24 function test1(agent){ 25 function test1(agent){
25 - const mytime = agent.parameters.hours;
26 agent.setContext(); 26 agent.setContext();
27 - agent.add('수면 시간이 등록되었습니다'); 27 + const mytime = agent.parameters.hours;
28 + const myresult = mytime+12;
29 + if(mytime>0){
30 + agent.add(`Good. your sleep time is ${myresult}`);
31 + }
28 } 32 }
29 33
34 + function test2(agent) {
35 + const hour = agent.parameters.hours;
36 + const min = agent.parameters.minutes;
37 + const gothour = hour.length > 0;
38 + const gotmin = min.length > 0;
39 + const rehour = (hour)+3;
40 + const remin = min+10;
41 +
42 + if(gothour && gotmin) {
43 + agent.add(`좋습니다. 당신의 취침시간은 ${hour}${min}분 입니다.`);
44 + agent.add(`${rehour}${remin}분에 주무십시오`);
45 + } else if (gothour && !gotmin) {
46 + agent.add('시간이 잘못 입력되었습니다.');
47 + } else if (gothour && !gothour) {
48 + agent.add('시간이 잘못 입력되었습니다.');
49 + } else {
50 + agent.add('취침시간을 00:00 또는 00시00분 으로 입력해 주세요');
51 + }
52 + }
30 // // Uncomment and edit to make your own intent handler 53 // // Uncomment and edit to make your own intent handler
31 // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);` 54 // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);`
32 // // below to get this function to be run when a Dialogflow intent is matched 55 // // below to get this function to be run when a Dialogflow intent is matched
...@@ -60,7 +83,6 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp ...@@ -60,7 +83,6 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp
60 let intentMap = new Map(); 83 let intentMap = new Map();
61 intentMap.set('Default Welcome Intent', welcome); 84 intentMap.set('Default Welcome Intent', welcome);
62 intentMap.set('Default Fallback Intent', fallback); 85 intentMap.set('Default Fallback Intent', fallback);
63 - intentMap.set('test',test1); 86 + intentMap.set('test',test2);
64 - // intentMap.set('your intent name here', googleAssistantHandler);
65 agent.handleRequest(intentMap); 87 agent.handleRequest(intentMap);
66 }); 88 });
......