Skip to content

Commit

Permalink
Integration with firestore
Browse files Browse the repository at this point in the history
Info querying features
  • Loading branch information
gustapp committed Jan 22, 2019
1 parent 7b5b058 commit c1c1c89
Show file tree
Hide file tree
Showing 14 changed files with 388 additions and 60 deletions.
11 changes: 10 additions & 1 deletion functions/package.json
Expand Up @@ -7,7 +7,8 @@
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
"logs": "firebase functions:log",
"test": "jest"
},
"main": "lib/index.js",
"dependencies": {
Expand All @@ -18,6 +19,14 @@
"firebase-functions": "^2.1.0"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/jest": "^23.3.13",
"@types/sinon": "^7.0.4",
"chai": "^4.2.0",
"jest": "^23.6.0",
"sinon": "^7.2.3",
"ts-jest": "^23.10.5",
"ts-sinon": "^1.0.12",
"tslint": "~5.8.0",
"typescript": "~2.8.3"
},
Expand Down
20 changes: 0 additions & 20 deletions functions/src/entity-factory.ts

This file was deleted.

38 changes: 20 additions & 18 deletions functions/src/handler-facade.ts
@@ -1,18 +1,20 @@
import { WebhookClient, Card, Suggestion } from 'dialogflow-fulfillment';
import { EntityFactory } from './entity-factory';
import { CursoInfo } from './model/curso-info';
/**
* @class
* Facade for all handlers
*/
export class HandlerFacade {

private entityFactory: EntityFactory;
// private refFactory: ReferenceFactory;
private cursoInfo: CursoInfo;
/**
* @constructor
* @param db firestore manager
*/
constructor(db: FirebaseFirestore.Firestore){
this.entityFactory = new EntityFactory(db);
// this.refFactory = new ReferenceFactory(db);
this.cursoInfo = new CursoInfo(db);
}
/**
* @function welcome
Expand Down Expand Up @@ -52,104 +54,104 @@ export class HandlerFacade {
* @param agent
*/
public getCourse(agent: WebhookClient) {

return this.cursoInfo.getCourse(agent);
}
/**
* @function getCourseInfo
* @param agent
*/
public getCourseInfo(agent: WebhookClient) {

return this.cursoInfo.getCourseInfo(agent);
}
/**
* @function getCourseRequirements
* @param agent
*/
public getCourseRequirements(agent: WebhookClient) {

return this.cursoInfo.getCourseRequirements(agent);
}
/**
* @function getCourseWorkload
* @param agent
*/
public getCourseWorkload(agent: WebhookClient) {

return this.cursoInfo.getCourseWorkload(agent);
}
/**
* @function getCourseTeacher
* @param agent
*/
public getCourseTeacher(agent: WebhookClient) {

return this.cursoInfo.getCourseTeacher(agent);
}
/**
* @function getCourseSchedule
* @param agent
*/
public getCourseSchedule(agent: WebhookClient) {

return this.cursoInfo.getCourseSchedule(agent);
}
/**
* @function getCourseCredit
* @param agent
*/
public getCourseCredit(agent: WebhookClient) {

return this.cursoInfo.getCourseCredit(agent);
}
/**
* @function getCourseFromScheduleDay
* @param agent
*/
public getCourseFromScheduleDay(agent: WebhookClient) {

this.cursoInfo.getCourseFromScheduleDay(agent);
}
/**
* @function getCourseFromScheduleDayHour
* @param agent
*/
public getCourseFromScheduleDayHour(agent: WebhookClient) {

this.cursoInfo.getCourseFromScheduleDayHour(agent);
}
/**
* @function fallbackGetCourseId2
* @param agent
*/
public fallbackGetCourseId2(agent: WebhookClient) {

this.cursoInfo.fallbackGetCourseId2(agent);
}
/**
* @function getCourseSuggestion
* @param agent
*/
public getCourseSuggestion(agent: WebhookClient) {

agent.add(`getCourseSuggestion 🔥`);
}
/**
* @function getCourseSuggestionBefore
* @param agent
*/
public getCourseSuggestionBefore(agent: WebhookClient) {

agent.add(`getCourseSuggestionBefore 🔥`);
}
/**
* @function getCourseSuggestionAfter
* @param agent
*/
public getCourseSuggestionAfter(agent: WebhookClient) {

agent.add(`getCourseSuggestionAfter 🔥`);
}
/**
* @function getCourseSuggestionBetween
* @param agent
*/
public getCourseSuggestionBetween(agent: WebhookClient) {

agent.add(`getCourseSuggestionBetween 🔥`);
}
/**
* @function getCourseSuggestionDays
* @param agent
*/
public getCourseSuggestionDays(agent: WebhookClient) {

agent.add(`getCourseSuggestionDays 🔥`);
}
}
44 changes: 24 additions & 20 deletions functions/src/index.ts
Expand Up @@ -7,9 +7,6 @@ import { HandlerFacade } from './handler-facade';
process.env.DEBUG = 'dialogflow:debug';

admin.initializeApp(functions.config().firebase);
const db = admin.firestore();

const facade = new HandlerFacade(db);

/**
* @function helloWorld
Expand All @@ -28,30 +25,37 @@ export const dialogflowFirebaseFulfillment = functions.https.onRequest((request,
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

// Retrieve firestore
const db = admin.firestore();
// const settings = { timestampsInSnapshots: true };
// db.settings(settings);

const facade = new HandlerFacade(db);

// Run the proper function handler based on the matched Dialogflow intent name
const intentMap = new Map();

// Test intents
intentMap.set('Welcome', facade.welcome);
intentMap.set('Fallback', fallback);
intentMap.set('Test', yourFunction);
intentMap.set('Fallback', facade.fallback);
intentMap.set('Test', facade.yourFunction);

// Jupiter intents
intentMap.set('fallbackGetCourseId2', fallbackGetCourseId2);
intentMap.set('getCourse', getCourse);
intentMap.set('GetCourseInfo', getCourseInfo); //ok
intentMap.set('GetCourseRequirements', getCourseRequirements); //ok
intentMap.set('GetCourseWorkload', getCourseWorkload); //ok
intentMap.set('GetCourseTeacher', getCourseTeacher); //ok
intentMap.set('GetCourseSchedule', getCourseSchedule); //ok
intentMap.set('GetCourseCredit', getCourseCredit); //ok
intentMap.set('getCourseFromScheduleDay', getCourseFromScheduleDay);
intentMap.set('getCourseFromScheduleDayHour', getCourseFromScheduleDayHour);
intentMap.set('getCourseSuggestion', getCourseSuggestion);
intentMap.set('getCourseSuggestionBefore', getCourseSuggestionBefore);
intentMap.set('getCourseSuggestionAfter', getCourseSuggestionAfter);
intentMap.set('getCourseSuggestionBetween', getCourseSuggestionBetween);
intentMap.set('getCourseSuggestionDays', getCourseSuggestionDays);
intentMap.set('fallbackGetCourseId2', facade.fallbackGetCourseId2);
intentMap.set('getCourse', (client) => facade.getCourse(client));
intentMap.set('GetCourseInfo', (client) => facade.getCourseInfo(client)); //ok
intentMap.set('GetCourseRequirements', (client) => facade.getCourseRequirements(client)); //ok
intentMap.set('GetCourseWorkload', (client) => facade.getCourseWorkload(client)); //ok
intentMap.set('GetCourseTeacher', (client) => facade.getCourseTeacher(client)); //ok
intentMap.set('GetCourseSchedule', (client) => facade.getCourseSchedule(client)); //ok
intentMap.set('GetCourseCredit', (client) => facade.getCourseCredit(client)); //ok
intentMap.set('getCourseFromScheduleDay', facade.getCourseFromScheduleDay);
intentMap.set('getCourseFromScheduleDayHour', facade.getCourseFromScheduleDayHour);
intentMap.set('getCourseSuggestion', facade.getCourseSuggestion);
intentMap.set('getCourseSuggestionBefore', facade.getCourseSuggestionBefore);
intentMap.set('getCourseSuggestionAfter', facade.getCourseSuggestionAfter);
intentMap.set('getCourseSuggestionBetween', facade.getCourseSuggestionBetween);
intentMap.set('getCourseSuggestionDays', facade.getCourseSuggestionDays);

agent.handleRequest(intentMap);
});
2 changes: 1 addition & 1 deletion functions/src/interfaces/curso.ts
Expand Up @@ -4,7 +4,7 @@ import { IAvaliacao as Avaliacao } from './avaliacao';
import { IRequisito as Requisito } from './requisito';
import { IOferecimento as Oferecimento } from './oferecimento';

interface ICurso {
export interface ICurso {
sigla: String,
name: String,
creditos: Credito,
Expand Down
4 changes: 4 additions & 0 deletions functions/src/interfaces/entity.ts
@@ -0,0 +1,4 @@
export interface Entity {
key: string;
data: any;
}
5 changes: 5 additions & 0 deletions functions/src/interfaces/index.ts
@@ -0,0 +1,5 @@
export { ICurso } from './curso';
export { IDocente } from './docente';
export { ICredito } from './credito';
export { IRequisito } from './requisito';
export { IOferecimento } from './oferecimento';

0 comments on commit c1c1c89

Please sign in to comment.