Promises revised.
This commit is contained in:
Rodrigo Rodriguez 2018-09-11 12:04:50 -03:00
parent c31671f3b4
commit bd03cfbc6c
6 changed files with 48 additions and 65 deletions

View file

@ -34,13 +34,13 @@
import { GBConversationalService } from "./../services/GBConversationalService";
import { GBCoreService } from "../services/GBCoreService";
import { IGBDialog } from "botlib";
import { IGBDialog } from "botlib";
import { GBMinInstance } from "botlib";
import { BotAdapter } from "botbuilder";
export class WhoAmIDialog extends IGBDialog {
/**
* Setup dialogs flows and define services call.
*
@ -48,20 +48,20 @@ export class WhoAmIDialog extends IGBDialog {
* @param min The minimal bot instance data.
*/
static setup(bot: BotAdapter, min: GBMinInstance) {
min.dialogs.add("/whoAmI", [
async (dc, args) => {
dc.context.sendActivity(`${min.instance.description}`);
await dc.context.sendActivity(`${min.instance.description}`);
if (min.instance.whoAmIVideo){
dc.context.sendActivity(`Vou te mostrar um vídeo. Por favor, aguarde...`);
min.conversationalService.sendEvent(dc, "play", {
playerType: "video",
data: min.instance.whoAmIVideo.trim()
});
}
if (min.instance.whoAmIVideo) {
await dc.context.sendActivity(`Vou te mostrar um vídeo. Por favor, aguarde...`);
await min.conversationalService.sendEvent(dc, "play", {
playerType: "video",
data: min.instance.whoAmIVideo.trim()
});
}
dc.replace('/ask', {isReturning: true});
await dc.replace('/ask', { isReturning: true });
}
]);
}

View file

@ -236,8 +236,14 @@ export class GBMinService {
}, this);
}
private receiver(adapter: BotFrameworkAdapter, req: any, res: any, conversationState: ConversationState, min: any, instance: any, appPackages: any[]) {
/**
* Bot Service hook method.
*/
private receiver(adapter: BotFrameworkAdapter, req: any, res: any, conversationState
: ConversationState, min: any, instance: any, appPackages: any[]) {
return adapter.processActivity(req, res, async (context) => {
const state = conversationState.get(context);
const dc = min.dialogs.createContext(context, state);
const user = min.userState.get(dc.context);

View file

@ -76,7 +76,7 @@ export class FeedbackDialog extends IGBDialog {
"Sugestões melhoram muito minha qualidade...",
"Obrigado pela sua iniciativa de sugestão."
];
dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
await dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
}
let messages = [
@ -89,13 +89,13 @@ export class FeedbackDialog extends IGBDialog {
async (dc, value) => {
let rate = await AzureText.getSentiment(min.instance.textAnalyticsKey, "pt-br", value);
if (rate > 0) {
dc.context.sendActivity("Bom saber que você gostou. Conte comigo.");
await dc.context.sendActivity("Bom saber que você gostou. Conte comigo.");
} else {
dc.context.sendActivity(
await dc.context.sendActivity(
"Vamos registrar sua questão, obrigado pela sinceridade."
);
}
dc.replace('/ask', { isReturning: true });
await dc.replace('/ask', { isReturning: true });
}]);
}
}

View file

@ -5,12 +5,12 @@
"homepage": ".",
"dependencies": {
"ajv": "^6.5.3",
"botframework-webchat": "^0.14.2",
"botframework-webchat": "^0.12.0",
"deep-extend": "^0.6.0",
"fetch": "^1.1.0",
"msal": "^0.2.2",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react": "^15.5.0",
"react-dom": "^15.5.0",
"react-helmet": "^5.2.0",
"react-player": "^1.6.4",
"react-powerbi": "^0.2.1",

View file

@ -126,7 +126,7 @@ export class AskDialog extends IGBDialog {
// Goes to ask loop, again.
dc.replace("/ask", { isReturning: true });
await dc.replace("/ask", { isReturning: true });
} else {
@ -176,8 +176,8 @@ export class AskDialog extends IGBDialog {
"Desculpe-me, não achei nada parecido. Poderia tentar escrever de outra forma?"
];
dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
dc.replace("/ask", { isReturning: true });
await dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
await dc.replace("/ask", { isReturning: true });
}
}
}
@ -212,8 +212,8 @@ export class AskDialog extends IGBDialog {
}
},
async (dc, value) => {
dc.endAll();
dc.begin("/answer", { query: value });
await dc.endAll();
await dc.begin("/answer", { query: value });
}
]);
}

View file

@ -32,24 +32,14 @@
"use strict";
import { Length } from "sequelize-typescript";
import {
CardAction,
HeroCard,
CardImage,
BotAdapter,
CardFactory,
MessageFactory
} from "botbuilder";
const UrlJoin = require("url-join");
import { BotAdapter, CardFactory, MessageFactory } from "botbuilder";
import { IGBDialog } from "botlib";
import { GBMinInstance } from "botlib";
import { AzureText } from "pragmatismo-io-framework";
import { GuaribasSubject } from '../models';
import { KBService } from "../services/KBService";
const UrlJoin = require("url-join");
const WaitUntil = require("wait-until");
export class MenuDialog extends IGBDialog {
/**
@ -66,21 +56,21 @@ export class MenuDialog extends IGBDialog {
min.dialogs.add("/menu", [
async (dc, args) => {
var rootSubjectId = null;
var botId = min.botId;
// var msg = dc.message; TODO: message from Where in V4?
// if (msg.attachments && msg.attachments.length > 0) {
// var attachment = msg.attachments[0];
// }
if (args && args.data) {
var subject = JSON.parse(args.data); // ?
// If there is a shortcut specified as subject destination, go there.
if (subject.to) {
let dialog = subject.to.split(":")[1];
dc.replace("/" + dialog);
dc.end();
await dc.replace("/" + dialog);
await dc.end();
return;
}
const user = min.userState.get(dc.context);
@ -88,7 +78,6 @@ export class MenuDialog extends IGBDialog {
rootSubjectId = subject.subjectId;
if (user.subjects.length > 0) {
let data = await service.getFaqBySubjectArray("menu", user.subjects);
await min.conversationalService.sendEvent(dc, "play", {
playerType: "bullet",
@ -100,39 +89,27 @@ export class MenuDialog extends IGBDialog {
const user = min.userState.get(dc.context);
user.subjects = [];
WaitUntil()
.interval(2000)
.times(1)
.condition(function (cb) {
return false;
})
.done(function (result) {
let messages = [
"Aqui estão algumas categorias de assuntos...",
"Selecionando o assunto você pode me ajudar a encontrar a resposta certa...",
"Você pode selecionar algum dos assuntos abaixo e perguntar algo..."
];
dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
});
let messages = [
"Aqui estão algumas categorias de assuntos...",
"Selecionando o assunto você pode me ajudar a encontrar a resposta certa...",
"Você pode selecionar algum dos assuntos abaixo e perguntar algo..."
];
await dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
user.isAsking = false;
}
const msg = MessageFactory.text('Greetings from example message');
const msg = MessageFactory.text('');
var attachments = [];
let data = await service.getSubjectItems(
min.instance.instanceId,
rootSubjectId);
msg.attachmentLayout = 'carousel';
data.forEach(function (item: GuaribasSubject) {
var subject = item;
var card = CardFactory.heroCard(
subject.title,
CardFactory.images([UrlJoin(
@ -177,10 +154,10 @@ export class MenuDialog extends IGBDialog {
},
async (dc, value) => {
var text = value;
if (text==="no"||text==="n") { // TODO: Migrate to a common.
dc.replace("/feedback");
if (text === "no" || text === "n") { // TODO: Migrate to a common.
await dc.replace("/feedback");
} else {
dc.replace("/ask");
await dc.replace("/ask");
}
}
]);