forked from wit-ai/wit-api-only-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-from-db.js
29 lines (27 loc) · 786 Bytes
/
2-from-db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*/
const {
FIREBASE_CONFIG,
queryWit,
interactive,
firstEntity,
} = require('../shared');
const firebase = require('firebase');
function handleMessage(question) {
return queryWit(question).then(({entities}) => {
const intent = firstEntity(entities, 'intent');
const dateTime = firstEntity(entities, 'datetime') || {};
const intentValue = (intent && intent.value) || 'unknown';
return firebase
.database()
.ref(`answers/${intentValue}`)
.once('value')
.then(snapshot => {
const val = snapshot.val();
console.log(`🤖 ${val || intentValue}`, dateTime);
});
});
}
firebase.initializeApp(FIREBASE_CONFIG);
interactive(handleMessage);