2018-04-21 02:59:30 -03:00
|
|
|
/*****************************************************************************\
|
2024-01-09 17:40:48 -03:00
|
|
|
| █████ █████ ██ █ █████ █████ ████ ██ ████ █████ █████ ███ ® |
|
|
|
|
| ██ █ ███ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ |
|
|
|
|
| ██ ███ ████ █ ██ █ ████ █████ ██████ ██ ████ █ █ █ ██ |
|
|
|
|
| ██ ██ █ █ ██ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ |
|
|
|
|
| █████ █████ █ ███ █████ ██ ██ ██ ██ █████ ████ █████ █ ███ |
|
2018-04-21 02:59:30 -03:00
|
|
|
| |
|
2024-01-10 15:01:02 -03:00
|
|
|
| General Bots Copyright (c) pragmatismo.com.br. All rights reserved. |
|
2018-04-21 02:59:30 -03:00
|
|
|
| Licensed under the AGPL-3.0. |
|
2019-03-09 16:59:31 -03:00
|
|
|
| |
|
2018-04-21 02:59:30 -03:00
|
|
|
| According to our dual licensing model, this program can be used either |
|
|
|
|
| under the terms of the GNU Affero General Public License, version 3, |
|
|
|
|
| or under a proprietary license. |
|
|
|
|
| |
|
|
|
|
| The texts of the GNU Affero General Public License with an additional |
|
|
|
|
| permission and of our proprietary license can be found at and |
|
|
|
|
| in the LICENSE file you have received along with this program. |
|
|
|
|
| |
|
|
|
|
| This program is distributed in the hope that it will be useful, |
|
|
|
|
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
| GNU Affero General Public License for more details. |
|
|
|
|
| |
|
2024-01-10 14:52:01 -03:00
|
|
|
| "General Bots" is a registered trademark of pragmatismo.com.br. |
|
2018-04-21 02:59:30 -03:00
|
|
|
| The licensing of the program under the AGPLv3 does not imply a |
|
|
|
|
| trademark license. Therefore any rights, title and interest in |
|
|
|
|
| our trademarks remain entirely with us. |
|
|
|
|
| |
|
|
|
|
\*****************************************************************************/
|
|
|
|
|
2018-12-18 13:50:35 -02:00
|
|
|
import React from 'react';
|
|
|
|
import GBMarkdownPlayer from './players/GBMarkdownPlayer.js';
|
|
|
|
import GBImagePlayer from './players/GBImagePlayer.js';
|
|
|
|
import GBVideoPlayer from './players/GBVideoPlayer.js';
|
2021-04-03 12:41:44 -03:00
|
|
|
import GBUrlPlayer from './players/GBUrlPlayer.js';
|
2024-04-14 23:17:37 -03:00
|
|
|
import GBMultiUrlPlayer from './players/GBMultiUrlPlayer.js';
|
2018-12-18 13:50:35 -02:00
|
|
|
import GBLoginPlayer from './players/GBLoginPlayer.js';
|
|
|
|
import GBBulletPlayer from './players/GBBulletPlayer.js';
|
|
|
|
import SidebarMenu from './components/SidebarMenu.js';
|
2021-01-20 18:23:42 -03:00
|
|
|
import SEO from './components/SEO.js';
|
2018-12-18 13:50:35 -02:00
|
|
|
import GBCss from './components/GBCss.js';
|
2023-07-09 16:29:30 -03:00
|
|
|
import { DirectLine} from 'botframework-directlinejs';
|
2018-12-18 13:50:35 -02:00
|
|
|
import { ConnectionStatus } from 'botframework-directlinejs';
|
|
|
|
import ReactWebChat from 'botframework-webchat';
|
|
|
|
import { UserAgentApplication } from 'msal';
|
2023-02-26 18:15:22 -03:00
|
|
|
import StaticContent from '@midudev/react-static-content';
|
2018-04-21 02:59:30 -03:00
|
|
|
|
|
|
|
class GBUIApp extends React.Component {
|
2018-12-18 13:50:35 -02:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
line: null,
|
|
|
|
token: null,
|
|
|
|
instanceClient: null
|
|
|
|
};
|
|
|
|
window.user = this.getUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
sendToken(token) {
|
|
|
|
setTimeout(() => {
|
|
|
|
window.line
|
|
|
|
.postActivity({
|
|
|
|
type: 'event',
|
|
|
|
name: 'updateToken',
|
|
|
|
data: token,
|
|
|
|
locale: 'en-us',
|
|
|
|
textFormat: 'plain',
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
from: this.getUser()
|
|
|
|
})
|
|
|
|
.subscribe(() => {
|
|
|
|
window.userAgentApplication.logout();
|
2018-09-16 18:17:28 -03:00
|
|
|
});
|
2018-12-18 13:50:35 -02:00
|
|
|
}, 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
send(command) {
|
2023-02-26 18:15:22 -03:00
|
|
|
window.line.postActivity({
|
|
|
|
type: 'event',
|
|
|
|
name: command,
|
|
|
|
locale: 'en-us',
|
|
|
|
textFormat: 'plain',
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
from: this.getUser()
|
|
|
|
});
|
2018-12-18 13:50:35 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
getUser() {
|
2020-01-27 16:19:09 -03:00
|
|
|
return { id: 'web@gb', name: 'You' };
|
2018-12-18 13:50:35 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
postMessage(value) {
|
|
|
|
window.line.postActivity({
|
|
|
|
type: 'message',
|
|
|
|
text: value,
|
|
|
|
from: this.getUser()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
configureChat() {
|
|
|
|
var botId = window.location.href.split('/')[3];
|
|
|
|
if (botId.indexOf('#') !== -1) {
|
|
|
|
botId = botId.split('#')[0];
|
2018-09-16 18:17:28 -03:00
|
|
|
}
|
2018-06-01 16:11:52 -03:00
|
|
|
|
2018-12-18 13:50:35 -02:00
|
|
|
if (!botId || botId === '') {
|
|
|
|
botId = '[default]';
|
2018-04-21 02:59:30 -03:00
|
|
|
}
|
|
|
|
|
2018-12-18 13:50:35 -02:00
|
|
|
fetch('/instances/' + botId)
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(
|
|
|
|
result => {
|
2021-06-13 11:51:07 -03:00
|
|
|
this.setupBotConnection(result);
|
2018-12-18 13:50:35 -02:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.setState({
|
|
|
|
isLoaded: false,
|
|
|
|
err: error
|
|
|
|
});
|
2018-09-16 18:17:28 -03:00
|
|
|
}
|
2018-12-18 13:50:35 -02:00
|
|
|
);
|
|
|
|
}
|
2018-09-16 18:17:28 -03:00
|
|
|
|
2018-12-18 13:50:35 -02:00
|
|
|
authenticate() {
|
2020-02-26 15:20:47 -03:00
|
|
|
if (this.state.instanceClient.authenticatorClientId === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-18 13:50:35 -02:00
|
|
|
let _this_ = this;
|
|
|
|
let authority = 'https://login.microsoftonline.com/' + this.state.instanceClient.authenticatorTenant;
|
2018-08-28 17:50:19 -03:00
|
|
|
|
2018-12-18 13:50:35 -02:00
|
|
|
let graphScopes = ['Directory.AccessAsUser.All'];
|
2018-06-01 16:11:52 -03:00
|
|
|
|
2018-12-18 13:50:35 -02:00
|
|
|
let userAgentApplication = new UserAgentApplication(
|
|
|
|
this.state.instanceClient.authenticatorClientId,
|
|
|
|
authority,
|
2021-06-13 12:20:44 -03:00
|
|
|
function (errorDesc, token, error) {
|
2018-12-18 13:50:35 -02:00
|
|
|
if (error) {
|
2021-06-13 12:20:44 -03:00
|
|
|
_this_.sendToken(error);
|
2018-09-16 18:17:28 -03:00
|
|
|
}
|
2018-12-18 13:50:35 -02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
window.userAgentApplication = userAgentApplication;
|
|
|
|
|
2023-02-26 18:15:22 -03:00
|
|
|
if (
|
|
|
|
!userAgentApplication.isCallback(window.location.hash) &&
|
|
|
|
window.parent === window &&
|
|
|
|
!window.opener &&
|
|
|
|
userAgentApplication.getUser
|
|
|
|
) {
|
2018-12-18 13:50:35 -02:00
|
|
|
var user = userAgentApplication.getUser();
|
|
|
|
if (user) {
|
|
|
|
userAgentApplication.acquireTokenSilent(graphScopes).then(
|
2020-01-27 16:19:09 -03:00
|
|
|
function (accessToken) {
|
2018-12-18 13:50:35 -02:00
|
|
|
_this_.sendToken(accessToken);
|
|
|
|
},
|
2020-01-27 16:19:09 -03:00
|
|
|
function (error) {
|
2021-06-13 12:20:44 -03:00
|
|
|
_this_.sendToken(error);
|
2018-12-18 13:50:35 -02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-09-16 18:17:28 -03:00
|
|
|
}
|
2018-12-18 13:50:35 -02:00
|
|
|
}
|
|
|
|
|
2021-06-13 11:51:07 -03:00
|
|
|
setupBotConnection(instanceClient) {
|
2018-12-18 13:50:35 -02:00
|
|
|
let _this_ = this;
|
|
|
|
window['botchatDebug'] = true;
|
|
|
|
|
|
|
|
const line = new DirectLine({
|
2021-06-13 11:51:07 -03:00
|
|
|
token: instanceClient.webchatToken
|
2018-12-18 13:50:35 -02:00
|
|
|
});
|
2021-08-21 09:19:07 -03:00
|
|
|
_this_.setState({ line: line });
|
2018-12-18 13:50:35 -02:00
|
|
|
|
|
|
|
line.connectionStatus$.subscribe(connectionStatus => {
|
|
|
|
if (connectionStatus === ConnectionStatus.Online) {
|
2023-02-26 18:15:22 -03:00
|
|
|
line.setUserId = null;
|
2021-08-21 09:19:07 -03:00
|
|
|
_this_.setState({ instanceClient: instanceClient });
|
|
|
|
window['botConnection'] = line;
|
2018-12-18 13:50:35 -02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
window.line = line;
|
|
|
|
|
|
|
|
line.activity$
|
2021-08-21 09:19:07 -03:00
|
|
|
.filter(activity => activity.type === 'event' && activity.name === 'loadInstance')
|
|
|
|
.subscribe(() => {
|
|
|
|
_this_.send('startGB');
|
|
|
|
_this_.authenticate();
|
|
|
|
});
|
2018-12-18 13:50:35 -02:00
|
|
|
|
2021-08-21 09:19:07 -03:00
|
|
|
line.activity$
|
2018-12-18 13:50:35 -02:00
|
|
|
.filter(activity => activity.type === 'event' && activity.name === 'stop')
|
2021-06-13 12:20:44 -03:00
|
|
|
.subscribe(() => {
|
2018-12-18 13:50:35 -02:00
|
|
|
if (_this_.player) {
|
|
|
|
_this_.player.stop();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
line.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();
|
|
|
|
}
|
|
|
|
|
2023-02-26 18:15:22 -03:00
|
|
|
webSpeechPonyfillFactory = 0;
|
2018-12-18 13:50:35 -02:00
|
|
|
render() {
|
|
|
|
let playerComponent = '';
|
|
|
|
|
|
|
|
if (this.state.playerType) {
|
|
|
|
switch (this.state.playerType) {
|
|
|
|
case 'markdown':
|
|
|
|
playerComponent = (
|
|
|
|
<GBMarkdownPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'bullet':
|
|
|
|
playerComponent = (
|
|
|
|
<GBBulletPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'video':
|
|
|
|
playerComponent = (
|
|
|
|
<GBVideoPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
2021-04-03 12:41:44 -03:00
|
|
|
case 'url':
|
|
|
|
playerComponent = (
|
|
|
|
<GBUrlPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
2024-04-14 23:17:37 -03:00
|
|
|
case 'multiurl':
|
|
|
|
playerComponent = (
|
|
|
|
<GBMultiUrlPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'image':
|
2018-12-18 13:50:35 -02:00
|
|
|
playerComponent = (
|
|
|
|
<GBImagePlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
2020-01-27 16:19:09 -03:00
|
|
|
/* case 'pbi':
|
|
|
|
playerComponent = (
|
|
|
|
<GBPowerBIPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break; */
|
2018-12-18 13:50:35 -02:00
|
|
|
case 'login':
|
|
|
|
playerComponent = (
|
|
|
|
<GBLoginPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
2021-06-13 12:20:44 -03:00
|
|
|
playerComponent = <div>GBERROR: Unknow player type specified on message from server.</div>;
|
2018-12-18 13:50:35 -02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-21 02:59:30 -03:00
|
|
|
}
|
|
|
|
|
2018-12-18 13:50:35 -02:00
|
|
|
let chat = <div />;
|
|
|
|
let gbCss = <div />;
|
2021-06-04 11:55:07 -03:00
|
|
|
let seo = <div />;
|
2018-12-18 13:50:35 -02:00
|
|
|
|
|
|
|
let sideBar = (
|
|
|
|
<div className="sidebar">
|
2021-06-13 11:51:07 -03:00
|
|
|
<SidebarMenu chat={this.chat} instance={this.state.instanceClient} />
|
2018-12-18 13:50:35 -02:00
|
|
|
</div>
|
|
|
|
);
|
2021-06-21 08:07:19 -03:00
|
|
|
|
2023-02-26 18:15:22 -03:00
|
|
|
if (this.state.line) {
|
2021-06-21 08:07:19 -03:00
|
|
|
if (this.state.instanceClient) {
|
|
|
|
gbCss = <GBCss instance={this.state.instanceClient} />;
|
|
|
|
seo = <SEO instance={this.state.instanceClient} />;
|
2023-02-26 18:15:22 -03:00
|
|
|
const token = this.state.instanceClient.speechToken;
|
|
|
|
chat = (
|
|
|
|
<ReactWebChat
|
|
|
|
ref={chat => {
|
|
|
|
this.chat = chat;
|
|
|
|
}}
|
2023-04-09 19:20:15 -03:00
|
|
|
locale={'en-us'}
|
2023-02-26 18:15:22 -03:00
|
|
|
directLine={this.state.line}
|
|
|
|
webSpeechPonyfillFactory={window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({
|
|
|
|
credentials: { authorizationToken: token, region: 'westus' }
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2021-06-21 08:07:19 -03:00
|
|
|
}
|
2018-04-21 02:59:30 -03:00
|
|
|
}
|
|
|
|
|
2021-06-13 11:51:07 -03:00
|
|
|
if (!this.state.instanceClient) {
|
2018-12-18 13:50:35 -02:00
|
|
|
sideBar = '';
|
2018-09-16 18:17:28 -03:00
|
|
|
}
|
2020-01-08 17:52:46 -03:00
|
|
|
|
2018-12-18 13:50:35 -02:00
|
|
|
return (
|
2021-01-20 18:23:42 -03:00
|
|
|
<StaticContent>
|
2021-04-03 12:41:44 -03:00
|
|
|
{seo}
|
2021-01-20 18:23:42 -03:00
|
|
|
<div>
|
|
|
|
{gbCss}
|
|
|
|
{sideBar}
|
|
|
|
<div className="player">{playerComponent}</div>
|
2023-02-26 18:15:22 -03:00
|
|
|
<div className="webchat">{chat}</div>
|
2018-12-18 14:12:38 -02:00
|
|
|
</div>
|
2021-01-20 18:23:42 -03:00
|
|
|
</StaticContent>
|
2020-01-27 16:19:09 -03:00
|
|
|
);
|
2018-12-18 13:50:35 -02:00
|
|
|
}
|
2018-04-21 02:59:30 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default GBUIApp;
|