diff --git a/deploy/core.gbapp/dialogs/WelcomeDialog.ts b/deploy/core.gbapp/dialogs/WelcomeDialog.ts index d70f2d60..e41666f7 100644 --- a/deploy/core.gbapp/dialogs/WelcomeDialog.ts +++ b/deploy/core.gbapp/dialogs/WelcomeDialog.ts @@ -32,12 +32,11 @@ "use strict" -const WaitUntil = require("wait-until") -import { GBCoreService } from "../services/GBCoreService" import { IGBDialog } from "botlib" -import { GBConversationalService } from "../services/GBConversationalService" import { GBMinInstance } from "botlib" import { BotAdapter } from "botbuilder" +const localize = require("localize")(__dirname) +const _T = localize.translate export class WelcomeDialog extends IGBDialog { /** @@ -53,13 +52,14 @@ export class WelcomeDialog extends IGBDialog { async (dc, args) => { const user = min.userState.get(dc.context) - + localize.setLocale(dc.context.activity.locale.split("-")[0]) + if (!user.once) { user.once = true var a = new Date() const date = a.getHours() var msg = - date < 12 ? "bom dia" : date < 18 ? "boa tarde" : "boa noite" + date < 12 ? _T("good morning") : date < 18 ? localize.translate("good evening") : _T("good night") let messages = [`Oi, ${msg}.`, `Oi!`, `Olá, ${msg}`, `Olá!`] await dc.context.sendActivity(messages[0]) diff --git a/deploy/core.gbapp/dialogs/WhoAmIDialog.ts b/deploy/core.gbapp/dialogs/WhoAmIDialog.ts index e12ed1e4..f51ddefe 100644 --- a/deploy/core.gbapp/dialogs/WhoAmIDialog.ts +++ b/deploy/core.gbapp/dialogs/WhoAmIDialog.ts @@ -32,8 +32,6 @@ "use strict" -import { GBConversationalService } from "./../services/GBConversationalService" -import { GBCoreService } from "../services/GBCoreService" import { IGBDialog } from "botlib" import { GBMinInstance } from "botlib" import { BotAdapter } from "botbuilder" @@ -54,7 +52,7 @@ export class WhoAmIDialog extends IGBDialog { await dc.context.sendActivity(`${min.instance.description}`) if (min.instance.whoAmIVideo) { - await dc.context.sendActivity(`Vou te mostrar um vídeo. Por favor, aguarde...`) + await dc.context.sendActivity("show_video") await min.conversationalService.sendEvent(dc, "play", { playerType: "video", data: min.instance.whoAmIVideo.trim() diff --git a/deploy/core.gbapp/dialogs/translations.json b/deploy/core.gbapp/dialogs/translations.json new file mode 100644 index 00000000..ddc8a37e --- /dev/null +++ b/deploy/core.gbapp/dialogs/translations.json @@ -0,0 +1,14 @@ +{ + "I will show you a video, please wait...": { + "pt": "Vou te mostrar um vídeo. Por favor, aguarde..." + }, + "good morning": { + "pt": "bom dia" + }, + "good evening": { + "pt": "boa tarde" + }, + "good night": { + "pt": "boa noite" + } +} \ No newline at end of file diff --git a/deploy/core.gbapp/services/GBDeployer.ts b/deploy/core.gbapp/services/GBDeployer.ts index c20bb1a1..0e0c8555 100644 --- a/deploy/core.gbapp/services/GBDeployer.ts +++ b/deploy/core.gbapp/services/GBDeployer.ts @@ -1,4 +1,3 @@ -import { IGBPackage } from "botlib" /*****************************************************************************\ | ( )_ _ | | _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ | @@ -46,6 +45,7 @@ import { IGBCoreService, IGBInstance } from "botlib" import { GBConfigService } from "./GBConfigService" import { GBError } from "botlib" import { GuaribasPackage } from "../models/GBModel" +import { IGBPackage } from "botlib" /** Deployer service for bots, themes, ai and more. */ export class GBDeployer { diff --git a/deploy/core.gbapp/services/GBMinService.ts b/deploy/core.gbapp/services/GBMinService.ts index ee1a7153..9f4fa5cf 100644 --- a/deploy/core.gbapp/services/GBMinService.ts +++ b/deploy/core.gbapp/services/GBMinService.ts @@ -97,6 +97,7 @@ export class GBMinService { server: any, appPackages: Array ): Promise { + // Serves default UI on root address '/'. let uiPackage = "default.gbui" @@ -110,6 +111,7 @@ export class GBMinService { let instances = await this.core.loadInstances() Promise.all( instances.map(async instance => { + // Gets the authorization key for each instance from Bot Service. let webchatToken = await this.getWebchatToken(instance) @@ -119,6 +121,7 @@ export class GBMinService { server.get("/instances/:botId", (req, res) => { (async () => { + // Returns the instance object to clients requesting bot info. let botId = req.params.botId @@ -269,6 +272,7 @@ export class GBMinService { return adapter.processActivity(req, res, async context => { const state = conversationState.get(context) const dc = min.dialogs.createContext(context, state) + dc.context.activity.locale = "pt-BR" const user = min.userState.get(dc.context) if (!user.loaded) { @@ -291,26 +295,44 @@ export class GBMinService { context.activity.type === "conversationUpdate" && context.activity.membersAdded.length > 0 ) { + let member = context.activity.membersAdded[0] if (member.name === "GeneralBots") { logger.info(`Bot added to conversation, starting chat...`) appPackages.forEach(e => { e.onNewSession(min, dc) }) + + // Starts root dialog. + await dc.begin("/") + } else { logger.info(`Member added to conversation: ${member.name}`) } + + // Processes messages. + } else if (context.activity.type === "message") { - // Check to see if anyone replied. If not then start echo dialog + + // Checks for /admin request. if (context.activity.text === "admin") { await dc.begin("/admin") + + // Checks for /menu JSON signature. + } else if (context.activity.text.startsWith("{\"title\"")) { await dc.begin("/menu", {data:JSON.parse(context.activity.text)}) + + // Otherwise, continue to the active dialog in the stack. + } else { await dc.continue() } + + // Processes events. + } else if (context.activity.type === "event") { // Empties dialog stack before going to the target. diff --git a/deploy/core.gbapp/strings/en.ts b/deploy/core.gbapp/strings/en.ts new file mode 100644 index 00000000..9b74a3a0 --- /dev/null +++ b/deploy/core.gbapp/strings/en.ts @@ -0,0 +1,5 @@ +export const messages = + { + show_video: "I will show you a video, please wait..." + } +; diff --git a/deploy/core.gbapp/strings/pt.ts b/deploy/core.gbapp/strings/pt.ts new file mode 100644 index 00000000..7ed9d44a --- /dev/null +++ b/deploy/core.gbapp/strings/pt.ts @@ -0,0 +1,4 @@ +export const messages = + { + show_video: "Vou te mostrar um vídeo. Por favor, aguarde..." + } \ No newline at end of file diff --git a/package.json b/package.json index e106c5c3..beab1225 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "express-promise-router": "^3.0.3", "fs-extra": "^7.0.0", "fs-walk": "^0.0.2", + "localize": "^0.4.7", "marked": "^0.5.0", "pragmatismo-io-framework": "^1.0.15", "reflect-metadata": "^0.1.12",