Skip to content

Instantly share code, notes, and snippets.

@huewu
Last active February 19, 2018 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huewu/35e28f80de42d4d4c69c6850e73aea70 to your computer and use it in GitHub Desktop.
Save huewu/35e28f80de42d4d4c69c6850e73aea70 to your computer and use it in GitHub Desktop.
// CODELAB: 아래 코드를 추가하세요
// '오늘 행사' action intent has been matched
'input.todayevent': () => {
// Firestore 접근을 위해 Firestore 클라이언트를 가져옵니다.
var db = admin.firestore();
var eventName;
// events 컬렉션에 접근해 DOCUMENT_ID의 문서 참조를 가져옵니다.
var docRef = db.collection('events').doc(DOCUMENT_ID)
// 문서 참조를 기반으로 실제 문서 데이타를 가져옵니다.
// 해당 작업은 비동기로 수행됩니다.
docRef.get().then(doc => {
if (!doc.exists) {
// 문서 데이터가 없는 경우 행사가 없다는 메세지를 출력합니다.
console.log('No such document!');
sendResponse('오늘은 행사가 없습니다. from webhook with firestore');
} else {
// 문서 데이터에서 name property 값을 가져와 eventName에 저장합니다.
eventName = doc.data().name;
console.log('Document data:', doc.data().name);
// eventName을 사용해 사용자 요청에 응답합니다.
if (requestSource === googleAssistantRequest) {
sendGoogleResponse('오늘은 ' + eventName + '가 있습니다. from webhook with firestore');
} else {
sendResponse('오늘은 ' + eventName + '가 있습니다. from webhook with firestore');
}
}
})
.catch(err => {
console.log('Error getting document', err);
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment