diff --git a/deploy/admin.gbapp/dialogs/AdminDialog.ts b/deploy/admin.gbapp/dialogs/AdminDialog.ts index 67b51854..8549c969 100644 --- a/deploy/admin.gbapp/dialogs/AdminDialog.ts +++ b/deploy/admin.gbapp/dialogs/AdminDialog.ts @@ -128,8 +128,12 @@ export class AdminDialog extends IGBDialog { await dc.endAll(); let service = new GBAdminService(); await service.saveValue("authenticatorToken", args.token) - await dc.context.sendActivity("Token has been updated."); - await dc.replace("/ask") + await dc.context.sendActivities([ + { type: 'typing' }, + { type: 'message', text: "Token has been updated." }, + { type: 'message', text: "Please, log out now from the administration work account on next screen." }, + { type: 'delay', value: 4000 }, + ]) } ]); diff --git a/deploy/core.gbapp/services/GBMinService.ts b/deploy/core.gbapp/services/GBMinService.ts index 2939ddc7..7086b7ef 100644 --- a/deploy/core.gbapp/services/GBMinService.ts +++ b/deploy/core.gbapp/services/GBMinService.ts @@ -332,7 +332,12 @@ export class GBMinService { // Otherwise, continue to the active dialog in the stack. } else { - await dc.continue() + + if (dc.activeDialog) { + await dc.continue() + } else { + await dc.begin("/answer", {query: context.activity.text}) + } } // Processes events. @@ -362,14 +367,14 @@ export class GBMinService { } else if (context.activity.name === "quality") { await dc.begin("/quality", { score: (context.activity as any).data }) } else if (context.activity.name === "updateToken") { - let token = (context.activity as any).data + let token = (context.activity as any).data await dc.begin("/adminUpdateToken", { token: token }) } else { await dc.continue() } } } catch (error) { - let msg = `Error in main activity: ${error}.` + let msg = `Error in main activity: ${error.message}.\n${error.stack}` logger.error(msg) } }) diff --git a/deploy/default.gbui/src/GBUIApp.js b/deploy/default.gbui/src/GBUIApp.js index dbb1c768..4787ee09 100644 --- a/deploy/default.gbui/src/GBUIApp.js +++ b/deploy/default.gbui/src/GBUIApp.js @@ -48,318 +48,320 @@ import GBPowerBIPlayer from "./players/GBPowerBIPlayer.js"; import { UserAgentApplication } from "msal"; class GBUIApp extends React.Component { - constructor() { - super(); + constructor() { + super(); - this.state = { - botConnection: null, - instance: null, - token: null, - instanceClient: null - }; - } - - sendToken(token) { - setTimeout(() => { - window.botConnection - .postActivity({ - type: "event", - name: "updateToken", - data: token, - locale: "en-us", - textFormat: "plain", - timestamp: new Date().toISOString(), - from: { id: "webUser", name: "You" } - }) - .subscribe(this.send("success")); - }, 400); - } - - send(command) { - window.botConnection - .postActivity({ - type: "event", - name: command, - locale: "en-us", - textFormat: "plain", - timestamp: new Date().toISOString(), - from: { id: "webUser", name: "You" } - }) - .subscribe(console.log("EVENT SENT TO Guaribas.")); - } - getUser() { - return { id: "webUser@gb", name: "You" }; - } - - postEvent(name, value) { - window.botConnection.postActivity({ - type: "event", - value: value, - from: this.getUser(), - name: name - }); - } - - postMessage(value) { - window.botConnection.postActivity({ - type: "message", - text: value, - from: this.getUser() - }); - } - - configureChat() { - var botId = window.location.href.split("/")[3]; - if (botId.indexOf('#') != -1) { - botId = botId.split("#")[0]; + this.state = { + botConnection: null, + instance: null, + token: null, + instanceClient: null + }; } - if (!botId || botId == "") { - botId = "[default]"; + sendToken(token) { + setTimeout(() => { + window.botConnection + .postActivity({ + type: "event", + name: "updateToken", + data: token, + locale: "en-us", + textFormat: "plain", + timestamp: new Date().toISOString(), + from: { id: "webUser", name: "You" } + }) + .subscribe(() => { + window.userAgentApplication.logout(); + console.log("updateToken done") + }); + }, 400); } - fetch("/instances/" + botId) - .then(res => res.json()) - .then( - result => { - this.setState({ instanceClient: result }); - this.setupBotConnection(); - }, - error => { - this.setState({ - isLoaded: false, - err: error - }); - } - ); - } - - authenticate() { - let _this_ = this; - let authority = - "https://login.microsoftonline.com/" + - this.state.instanceClient.authenticatorTenant; - - let graphScopes = ["Directory.AccessAsUser.All"]; - - let userAgentApplication = new UserAgentApplication( - this.state.instanceClient.authenticatorClientID, - authority, - function (errorDesc, token, error, tokenType) { - userAgentApplication.acquireTokenSilent(graphScopes).then(function (accessToken) { - _this_.sendToken(accessToken); - }, function (error) { - console.log(error); - }) - } - ); - - if (!userAgentApplication.isCallback(window.location.hash) && window.parent === window && !window.opener) { - var user = userAgentApplication.getUser(); - if (user) { - userAgentApplication.acquireTokenSilent(graphScopes).then(function (accessToken) { - _this_.sendToken(accessToken); - }, function (error) { - console.log(error); - }) - } + send(command) { + window.botConnection + .postActivity({ + type: "event", + name: command, + locale: "en-us", + textFormat: "plain", + timestamp: new Date().toISOString(), + from: { id: "webUser", name: "You" } + }) + .subscribe(console.log("EVENT SENT TO Guaribas.")); } - } - - setupBotConnection() { - let _this_ = this; - window["botchatDebug"] = true; - - const botConnection = new DirectLine({ - secret: this.state.instanceClient.secret - }); - - botConnection.connectionStatus$.subscribe(connectionStatus => { - if (connectionStatus === ConnectionStatus.Online) { - _this_.setState({ botConnection: botConnection }); - botConnection.postActivity({ - type: "event", - value: "startGB", - from: this.getUser(), - name: "startGB" - }); - } - }); - - window.botConnection = botConnection; - this.postEvent("startGB", true); - - botConnection.activity$ - .filter( - activity => - activity.type === "event" && activity.name === "loadInstance" - ) - .subscribe(activity => { - _this_.setState({ instance: activity.value }); - _this_.authenticate() - }); - - botConnection.activity$ - .filter(activity => activity.type === "event" && activity.name === "stop") - .subscribe(activity => { - if (_this_.player) { - _this_.player.stop(); - } - }); - - botConnection.activity$ - .filter(activity => activity.type === "event" && activity.name === "play") - .subscribe(activity => { - _this_.setState({ playerType: activity.value.playerType }); - _this_.player.play(activity.value.data); - }); - } - - componentDidMount() { - this.configureChat(); - } - - render() { - - - let playerComponent = ""; - - if (this.state.playerType) { - switch (this.state.playerType) { - case "markdown": - playerComponent = ( - { - this.player = player; - }} - /> - ); - break; - case "bullet": - playerComponent = ( - { - this.player = player; - }} - /> - ); - break; - case "video": - playerComponent = ( - { - this.player = player; - }} - /> - ); - break; - case "image": - playerComponent = ( - { - this.player = player; - }} - /> - ); - break; - case "pbi": - playerComponent = ( - { - this.player = player; - }} - /> - ); - break; - case "login": - playerComponent = ( - { - this.player = player; - }} - /> - ); - break; - default: - console.log( - "GBERROR: Unknow player type specified on message from server." - ); - break; - } - - + getUser() { + return { id: "webUser@gb", name: "You" }; } - let speechOptions; - let chat =
; - let gbCss =
; - - - let sideBar = ( -
- -
- ); - - if (this.state.botConnection && this.state.instance) { - let token = this.state.instanceClient.speechToken; - gbCss = ; - - function getToken() { - return new Promise((resolve, reject) => { - resolve(token); + postEvent(name, value) { + window.botConnection.postActivity({ + type: "event", + value: value, + from: this.getUser(), + name: name }); - } - - speechOptions = { - speechRecognizer: new SpeechRecognizer({ - locale: "pt-br", - fetchCallback: (authFetchEventId) => getToken(), - fetchOnExpiryCallback: (authFetchEventId) => getToken() - }), - speechSynthesizer: new SpeechSynthesizer({ - fetchCallback: (authFetchEventId) => getToken(), - fetchOnExpiryCallback: (authFetchEventId) => getToken(), - gender: SynthesisGender.Male, - voiceName: 'Microsoft Server Speech Text to Speech Voice (pt-BR, Daniel, Apollo)' - }) - }; - - chat = ( - { - this.chat = chat; - }} - locale={'pt-br'} - botConnection={this.state.botConnection} - user={this.getUser()} - bot={{ id: "bot@gb", name: "Bot" }} - speechOptions={speechOptions} - /> - ); - - } - if (!this.state.instance) { - sideBar = ""; + postMessage(value) { + window.botConnection.postActivity({ + type: "message", + text: value, + from: this.getUser() + }); } - return ( -
- {gbCss} - {sideBar} -
{playerComponent}
- {chat} -
- ); - } + configureChat() { + var botId = window.location.href.split("/")[3]; + if (botId.indexOf('#') != -1) { + botId = botId.split("#")[0]; + } + + if (!botId || botId == "") { + botId = "[default]"; + } + + fetch("/instances/" + botId) + .then(res => res.json()) + .then( + result => { + this.setState({ instanceClient: result }); + this.setupBotConnection(); + }, + error => { + this.setState({ + isLoaded: false, + err: error + }); + } + ); + } + + authenticate() { + let _this_ = this; + let authority = + "https://login.microsoftonline.com/" + + this.state.instanceClient.authenticatorTenant; + + let graphScopes = ["Directory.AccessAsUser.All"]; + + let userAgentApplication = new UserAgentApplication( + this.state.instanceClient.authenticatorClientID, + authority, + function(errorDesc, token, error, tokenType) { + if (error) { + console.log(error); + } + } + ); + window.userAgentApplication = userAgentApplication; + + if (!userAgentApplication.isCallback(window.location.hash) && window.parent === window && !window.opener) { + var user = userAgentApplication.getUser(); + if (user) { + userAgentApplication.acquireTokenSilent(graphScopes).then(function(accessToken) { + _this_.sendToken(accessToken); + }, function(error) { + console.log(error); + }) + } + } + } + + setupBotConnection() { + let _this_ = this; + window["botchatDebug"] = true; + + const botConnection = new DirectLine({ + secret: this.state.instanceClient.secret + }); + + botConnection.connectionStatus$.subscribe(connectionStatus => { + if (connectionStatus === ConnectionStatus.Online) { + _this_.setState({ botConnection: botConnection }); + botConnection.postActivity({ + type: "event", + value: "startGB", + from: this.getUser(), + name: "startGB" + }); + } + }); + + window.botConnection = botConnection; + this.postEvent("startGB", true); + + botConnection.activity$ + .filter( + activity => + activity.type === "event" && activity.name === "loadInstance" + ) + .subscribe(activity => { + _this_.setState({ instance: activity.value }); + _this_.authenticate() + }); + + botConnection.activity$ + .filter(activity => activity.type === "event" && activity.name === "stop") + .subscribe(activity => { + if (_this_.player) { + _this_.player.stop(); + } + }); + + botConnection.activity$ + .filter(activity => activity.type === "event" && activity.name === "play") + .subscribe(activity => { + _this_.setState({ playerType: activity.value.playerType }); + _this_.player.play(activity.value.data); + }); + } + + componentDidMount() { + this.configureChat(); + } + + render() { + + + let playerComponent = ""; + + if (this.state.playerType) { + switch (this.state.playerType) { + case "markdown": + playerComponent = ( + { + this.player = player; + }} + /> + ); + break; + case "bullet": + playerComponent = ( + { + this.player = player; + }} + /> + ); + break; + case "video": + playerComponent = ( + { + this.player = player; + }} + /> + ); + break; + case "image": + playerComponent = ( + { + this.player = player; + }} + /> + ); + break; + case "pbi": + playerComponent = ( + { + this.player = player; + }} + /> + ); + break; + case "login": + playerComponent = ( + { + this.player = player; + }} + /> + ); + break; + default: + console.log( + "GBERROR: Unknow player type specified on message from server." + ); + break; + } + + + } + + let speechOptions; + let chat =
; + let gbCss =
; + + + let sideBar = ( +
+ +
+ ); + + if (this.state.botConnection && this.state.instance) { + let token = this.state.instanceClient.speechToken; + gbCss = ; + + function getToken() { + return new Promise((resolve, reject) => { + resolve(token); + }); + } + + speechOptions = { + speechRecognizer: new SpeechRecognizer({ + locale: "pt-br", + fetchCallback: (authFetchEventId) => getToken(), + fetchOnExpiryCallback: (authFetchEventId) => getToken() + }), + speechSynthesizer: new SpeechSynthesizer({ + fetchCallback: (authFetchEventId) => getToken(), + fetchOnExpiryCallback: (authFetchEventId) => getToken(), + gender: SynthesisGender.Male, + voiceName: 'Microsoft Server Speech Text to Speech Voice (pt-BR, Daniel, Apollo)' + }) + }; + + chat = ( + { + this.chat = chat; + }} + locale={'pt-br'} + botConnection={this.state.botConnection} + user={this.getUser()} + bot={{ id: "bot@gb", name: "Bot" }} + speechOptions={speechOptions} + /> + ); + + + } + + if (!this.state.instance) { + sideBar = ""; + } + + return ( +
+ {gbCss} + {sideBar} +
{playerComponent}
+ {chat} +
+ ); + } } export default GBUIApp; diff --git a/deploy/kb.gbapp/dialogs/AskDialog.ts b/deploy/kb.gbapp/dialogs/AskDialog.ts index d30e4e64..38751e1f 100644 --- a/deploy/kb.gbapp/dialogs/AskDialog.ts +++ b/deploy/kb.gbapp/dialogs/AskDialog.ts @@ -183,7 +183,7 @@ export class AskDialog extends IGBDialog { // Three forms of asking. - if (args.firstTime) { + if (args && args.firstTime) { text = Messages[locale].ask_first_time; } else if (args && args.isReturning) { text = Messages[locale].anything_else;