Showing
1 changed file
with
73 additions
and
14 deletions
... | @@ -23,31 +23,89 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp | ... | @@ -23,31 +23,89 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp |
23 | 23 | ||
24 | var mytime; | 24 | var mytime; |
25 | function test1(agent){ | 25 | function test1(agent){ |
26 | - agent.setContext(); | 26 | + agent.add(new Card({ |
27 | - const mytime = agent.parameters.hours; | 27 | + title: `Title: this is a card title`, |
28 | - const myresult = mytime+12; | 28 | + imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png', |
29 | - if(mytime>0){ | 29 | + text: `This is the body text of a card. You can even use line\n breaks and emoji! 💁`, |
30 | - agent.add(`Good. your sleep time is ${myresult}`); | 30 | + buttonText: 'This is a button', |
31 | - } | 31 | + buttonUrl: 'https://assistant.google.com/' |
32 | + })); | ||
32 | } | 33 | } |
33 | 34 | ||
35 | + //기상시간 입력 및 추천 cycle 반환 | ||
34 | function test2(agent) { | 36 | function test2(agent) { |
35 | const hour = agent.parameters.hours; | 37 | const hour = agent.parameters.hours; |
36 | const min = agent.parameters.minutes; | 38 | const min = agent.parameters.minutes; |
37 | const gothour = hour.length > 0; | 39 | const gothour = hour.length > 0; |
38 | const gotmin = min.length > 0; | 40 | const gotmin = min.length > 0; |
39 | - const rehour = Number(hour)+3; | 41 | + var myhour1,myhour2,myhour3,myhour4; |
40 | - const remin = Number(min)+10; | 42 | + var mymin1,mymin2,mymin3,mymin4; |
43 | + | ||
44 | + if(Number(min)-30>0){ | ||
45 | + const rehour1 = Number(hour)-9; | ||
46 | + const remin1 = Number(min); | ||
47 | + | ||
48 | + const rehour2 = Number(hour)-7; | ||
49 | + const remin2 = Number(min)-30; | ||
50 | + | ||
51 | + const rehour3 = Number(hour)-6; | ||
52 | + const remin3 = Number(min); | ||
53 | + | ||
54 | + const rehour4 = Number(hour)-4; | ||
55 | + const remin4 = Number(min)-30; | ||
56 | + | ||
57 | + myhour1=rehour1; myhour2=rehour2; myhour3=rehour3; myhour4=rehour4; | ||
58 | + | ||
59 | + //시간이 -값이 될때 값 설정 | ||
60 | + if(myhour1<0){myhour1=24+myhour1;} | ||
61 | + if(myhour2<0){myhour2=24+myhour2;} | ||
62 | + if(myhour3<0){myhour3=24+myhour3;} | ||
63 | + if(myhour4<0){myhour4=24+myhour4;} | ||
64 | + | ||
65 | + if(mymin1<0){mymin1=60+mymin1;} | ||
66 | + if(mymin2<0){mymin1=60+mymin2;} | ||
67 | + if(mymin3<0){mymin1=60+mymin3;} | ||
68 | + if(mymin4<0){mymin1=60+mymin4;} | ||
69 | + | ||
70 | + }else if(Number(min)-30<0){ | ||
71 | + const rehour1 = Number(hour)-9; | ||
72 | + const remin1 = Number(min); | ||
73 | + | ||
74 | + const rehour2 = Number(hour)-8; | ||
75 | + const remin2 = Number(min)+30; | ||
76 | + | ||
77 | + const rehour3 = Number(hour)-6; | ||
78 | + const remin3 = Number(min); | ||
79 | + | ||
80 | + const rehour4 = Number(hour)-5; | ||
81 | + const remin4 = Number(min)+30; | ||
82 | + | ||
83 | + myhour1=rehour1; myhour2=rehour2; myhour3=rehour3; myhour4=rehour4; | ||
84 | + | ||
85 | + //시간이 -값이 될때 값 설정 | ||
86 | + if(myhour1<0){myhour1=24+myhour1;} | ||
87 | + if(myhour2<0){myhour2=24+myhour2;} | ||
88 | + if(myhour3<0){myhour3=24+myhour3;} | ||
89 | + if(myhour4<0){myhour4=24+myhour4;} | ||
90 | + | ||
91 | + if(mymin1<0){mymin1=60+mymin1;} | ||
92 | + if(mymin2<0){mymin1=60+mymin2;} | ||
93 | + if(mymin3<0){mymin1=60+mymin3;} | ||
94 | + if(mymin4<0){mymin1=60+mymin4;} | ||
95 | + | ||
96 | + } | ||
41 | 97 | ||
42 | if(gothour && gotmin) { | 98 | if(gothour && gotmin) { |
43 | - agent.add(`좋습니다. 당신의 취침시간은 ${hour}시 ${min}분 입니다.`); | 99 | + agent.add(`좋습니다. 당신의 기상시간은 ${hour}시 ${min}분 입니다.`); |
44 | - agent.add(`${rehour}시 ${remin}분에 주무십시오`); | 100 | + agent.add(`기상시간을 참고한 결과 총 4개의 권장 취침 시간이 있습니다. ${myhour1}시 ${myhour1}분(6cycle) / ${myhour2}시 ${myhour2}분(5cycle) / ${myhour3}시 ${myhour3}분(4cycle) / ${myhour4}시 ${myhour4}(3cycle)분 중 원하는 시간에 주무시길 추천드립니다.'\n'`); |
101 | + | ||
102 | + | ||
45 | } else if (gothour && !gotmin) { | 103 | } else if (gothour && !gotmin) { |
46 | - agent.add('시간이 잘못 입력되었습니다.'); | 104 | + agent.add('기상시간을 입력해 주세요( 예시 - 6:26 21:40 ) '); |
47 | } else if (gothour && !gothour) { | 105 | } else if (gothour && !gothour) { |
48 | - agent.add('시간이 잘못 입력되었습니다.'); | 106 | + agent.add('기상시간을 입력해 주세요( 예시 - 6:26 21:40 ) '); |
49 | } else { | 107 | } else { |
50 | - agent.add('취침시간을 00:00 또는 00시00분 으로 입력해 주세요'); | 108 | + agent.add('기상시간을 입력해 주세요( 예시 - 6:26 21:40 ) '); |
51 | } | 109 | } |
52 | } | 110 | } |
53 | // // Uncomment and edit to make your own intent handler | 111 | // // Uncomment and edit to make your own intent handler |
... | @@ -83,6 +141,7 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp | ... | @@ -83,6 +141,7 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp |
83 | let intentMap = new Map(); | 141 | let intentMap = new Map(); |
84 | intentMap.set('Default Welcome Intent', welcome); | 142 | intentMap.set('Default Welcome Intent', welcome); |
85 | intentMap.set('Default Fallback Intent', fallback); | 143 | intentMap.set('Default Fallback Intent', fallback); |
86 | - intentMap.set('test',test2); | 144 | + intentMap.set('time',test2); |
145 | + intentMap.set('result',mytime); | ||
87 | agent.handleRequest(intentMap); | 146 | agent.handleRequest(intentMap); |
88 | }); | 147 | }); | ... | ... |
-
Please register or login to post a comment