Showing
1 changed file
with
78 additions
and
45 deletions
... | @@ -21,19 +21,8 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp | ... | @@ -21,19 +21,8 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp |
21 | agent.add(`잘못된 입력값 입니다`); | 21 | agent.add(`잘못된 입력값 입니다`); |
22 | } | 22 | } |
23 | 23 | ||
24 | - var mytime; | ||
25 | - function test1(agent){ | ||
26 | - agent.add(new Card({ | ||
27 | - title: `Title: this is a card title`, | ||
28 | - imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png', | ||
29 | - text: `This is the body text of a card. You can even use line\n breaks and emoji! 💁`, | ||
30 | - buttonText: 'This is a button', | ||
31 | - buttonUrl: 'https://assistant.google.com/' | ||
32 | - })); | ||
33 | - } | ||
34 | - | ||
35 | //기상시간 입력 및 추천 cycle 반환 | 24 | //기상시간 입력 및 추천 cycle 반환 |
36 | - function test2(agent) { | 25 | + function mytime1(agent) { |
37 | const hour = agent.parameters.hours; | 26 | const hour = agent.parameters.hours; |
38 | const min = agent.parameters.minutes; | 27 | const min = agent.parameters.minutes; |
39 | const gothour = hour.length > 0; | 28 | const gothour = hour.length > 0; |
... | @@ -97,7 +86,7 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp | ... | @@ -97,7 +86,7 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp |
97 | 86 | ||
98 | if(gothour && gotmin) { | 87 | if(gothour && gotmin) { |
99 | agent.add(`좋습니다. 당신의 기상시간은 ${hour}시 ${min}분 입니다.`); | 88 | agent.add(`좋습니다. 당신의 기상시간은 ${hour}시 ${min}분 입니다.`); |
100 | - agent.add(`기상시간을 참고한 결과 총 4개의 권장 취침 시간이 있습니다. ${myhour1}시 ${myhour1}분(6cycle) / ${myhour2}시 ${myhour2}분(5cycle) / ${myhour3}시 ${myhour3}분(4cycle) / ${myhour4}시 ${myhour4}(3cycle)분 중 원하는 시간에 주무시길 추천드립니다.'\n'`); | 89 | + agent.add(`한 번의 수면 cycle은 1시간 30분 (90분)입니다.\n 당신의 기상시간을 참고한 결과 총 4개의 권장 취침 시간(cycle)이 있습니다.\n 1. ${myhour1}시 ${myhour1}분(6cycle) \n 2. ${myhour2}시 ${myhour2}분(5cycle) \n 3. ${myhour3}시 ${myhour3}분(4cycle) \n 4. ${myhour4}시 ${myhour4}(3cycle)분 \n 원하는 시간에 주무시길 추천드립니다.`); |
101 | 90 | ||
102 | 91 | ||
103 | } else if (gothour && !gotmin) { | 92 | } else if (gothour && !gotmin) { |
... | @@ -108,40 +97,84 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp | ... | @@ -108,40 +97,84 @@ exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, resp |
108 | agent.add('기상시간을 입력해 주세요( 예시 - 6:26 21:40 ) '); | 97 | agent.add('기상시간을 입력해 주세요( 예시 - 6:26 21:40 ) '); |
109 | } | 98 | } |
110 | } | 99 | } |
111 | - // // Uncomment and edit to make your own intent handler | 100 | + |
112 | - // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);` | 101 | +function mytime2(agent) { |
113 | - // // below to get this function to be run when a Dialogflow intent is matched | 102 | + const hour = agent.parameters.hours; |
114 | - // function yourFunctionHandler(agent) { | 103 | + const min = agent.parameters.minutes; |
115 | - // agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`); | 104 | + const gothour = hour.length > 0; |
116 | - // agent.add(new Card({ | 105 | + const gotmin = min.length > 0; |
117 | - // title: `Title: this is a card title`, | 106 | + var myhour1,myhour2,myhour3,myhour4; |
118 | - // imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png', | 107 | + var mymin1,mymin2,mymin3,mymin4; |
119 | - // text: `This is the body text of a card. You can even use line\n breaks and emoji! 💁`, | 108 | + |
120 | - // buttonText: 'This is a button', | 109 | + if(Number(min)+30<60){ |
121 | - // buttonUrl: 'https://assistant.google.com/' | 110 | + const rehour1 = Number(hour)+1; |
122 | - // }) | 111 | + const remin1 = Number(min)+30; |
123 | - // ); | 112 | + |
124 | - // agent.add(new Suggestion(`Quick Reply`)); | 113 | + const rehour2 = Number(hour)+6; |
125 | - // agent.add(new Suggestion(`Suggestion`)); | 114 | + const remin2 = Number(min); |
126 | - // agent.setContext({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }}); | 115 | + |
127 | - // } | 116 | + const rehour3 = Number(hour)+7; |
128 | - | 117 | + const remin3 = Number(min)+30; |
129 | - // // Uncomment and edit to make your own Google Assistant intent handler | 118 | + |
130 | - // // uncomment `intentMap.set('your intent name here', googleAssistantHandler);` | 119 | + const rehour4 = Number(hour)+9; |
131 | - // // below to get this function to be run when a Dialogflow intent is matched | 120 | + const remin4 = Number(min); |
132 | - // function googleAssistantHandler(agent) { | 121 | + |
133 | - // let conv = agent.conv(); // Get Actions on Google library conv instance | 122 | + myhour1=rehour1; myhour2=rehour2; myhour3=rehour3; myhour4=rehour4; |
134 | - // conv.ask('Hello from the Actions on Google client library!') // Use Actions on Google library | 123 | + |
135 | - // agent.add(conv); // Add Actions on Google library responses to your agent's response | 124 | + //시간이 -값이 될때 값 설정 |
136 | - // } | 125 | + if(myhour1<0){myhour1=24+myhour1;} |
137 | - // // See https://github.com/dialogflow/fulfillment-actions-library-nodejs | 126 | + if(myhour2<0){myhour2=24+myhour2;} |
138 | - // // for a complete Dialogflow fulfillment library Actions on Google client library v2 integration sample | 127 | + if(myhour3<0){myhour3=24+myhour3;} |
139 | - | 128 | + if(myhour4<0){myhour4=24+myhour4;} |
140 | - // Run the proper function handler based on the matched Dialogflow intent name | 129 | + |
130 | + if(mymin1<0){mymin1=60+mymin1;} | ||
131 | + if(mymin2<0){mymin1=60+mymin2;} | ||
132 | + if(mymin3<0){mymin1=60+mymin3;} | ||
133 | + if(mymin4<0){mymin1=60+mymin4;} | ||
134 | + | ||
135 | + }else if(Number(min)+30>60){ | ||
136 | + const rehour1 = Number(hour)+2; | ||
137 | + const remin1 = Number(min)-30; | ||
138 | + | ||
139 | + const rehour2 = Number(hour)+6; | ||
140 | + const remin2 = Number(min); | ||
141 | + | ||
142 | + const rehour3 = Number(hour)+8; | ||
143 | + const remin3 = Number(min)-30; | ||
144 | + | ||
145 | + const rehour4 = Number(hour)+9; | ||
146 | + const remin4 = Number(min); | ||
147 | + | ||
148 | + myhour1=rehour1; myhour2=rehour2; myhour3=rehour3; myhour4=rehour4; | ||
149 | + | ||
150 | + //시간이 -값이 될때 값 설정 | ||
151 | + if(myhour1<0){myhour1=24+myhour1;} | ||
152 | + if(myhour2<0){myhour2=24+myhour2;} | ||
153 | + if(myhour3<0){myhour3=24+myhour3;} | ||
154 | + if(myhour4<0){myhour4=24+myhour4;} | ||
155 | + | ||
156 | + if(mymin1<0){mymin1=60+mymin1;} | ||
157 | + if(mymin2<0){mymin1=60+mymin2;} | ||
158 | + if(mymin3<0){mymin1=60+mymin3;} | ||
159 | + if(mymin4<0){mymin1=60+mymin4;} | ||
160 | + } | ||
161 | + | ||
162 | + if(gothour && gotmin) { | ||
163 | + agent.add(`좋습니다. 당신의 취침시간은 ${hour}시 ${min}분 입니다.`); | ||
164 | + agent.add(`한 번의 수면 cycle은 1시간 30분 (90분)입니다.\n 당신의 취침시간을 참고한 결과 총 4개의 권장 기상시간(cycle)이 있습니다.\n 1. ${myhour1}시 ${myhour1}분(6cycle) \n 2. ${myhour2}시 ${myhour2}분(5cycle) \n 3. ${myhour3}시 ${myhour3}분(4cycle) \n 4. ${myhour4}시 ${myhour4}(3cycle)분 \n 원하는 시간에 기상 하시길 추천드립니다.`); | ||
165 | + | ||
166 | + } else if (gothour && !gotmin) { | ||
167 | + agent.add('취침시간을 입력해 주세요( 예시 - 6:26 21:40 ) '); | ||
168 | + } else if (gothour && !gothour) { | ||
169 | + agent.add('취침시간을 입력해 주세요( 예시 - 6:26 21:40 ) '); | ||
170 | + } else { | ||
171 | + agent.add('취침시간을 입력해 주세요( 예시 - 6:26 21:40 ) '); | ||
172 | + } | ||
173 | + } | ||
141 | let intentMap = new Map(); | 174 | let intentMap = new Map(); |
142 | intentMap.set('Default Welcome Intent', welcome); | 175 | intentMap.set('Default Welcome Intent', welcome); |
143 | intentMap.set('Default Fallback Intent', fallback); | 176 | intentMap.set('Default Fallback Intent', fallback); |
144 | - intentMap.set('time',test2); | 177 | + intentMap.set('time',mytime1); |
145 | - intentMap.set('result',mytime); | 178 | + intentMap.set('time2',mytime2); |
146 | agent.handleRequest(intentMap); | 179 | agent.handleRequest(intentMap); |
147 | }); | 180 | }); | ... | ... |
-
Please register or login to post a comment