Skip to content

Commit

Permalink
new(default.gbui): New PDF player and log improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Apr 3, 2021
1 parent 22fca51 commit 84fb074
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 39 deletions.
5 changes: 5 additions & 0 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ export class GBConversationalService {

public async sendAudio(min: GBMinInstance, step: GBDialogStep, url: string): Promise<any> {
const mobile = step.context.activity.from.id;
GBLog.info(`Sending audio to ${mobile} in URL: ${url}.`);
await min.whatsAppDirectLine.sendAudioToDevice(mobile, url);
}

public async sendEvent(min: GBMinInstance, step: GBDialogStep, name: string, value: Object): Promise<any> {
if (step.context.activity.channelId === 'webchat') {
GBLog.info(`Sending event ${name}:${typeof value === 'object' ? JSON.stringify(value) : value} to client...`);
const msg = MessageFactory.text('');
msg.value = value;
msg.type = 'event';
Expand All @@ -256,6 +258,7 @@ export class GBConversationalService {

// tslint:disable:no-unsafe-any due to Nexmo.
public async sendSms(min: GBMinInstance, mobile: string, text: string): Promise<any> {
GBLog.info(`Sending SMS to ${mobile} with text: '${text}'.`);
return new Promise((resolve: any, reject: any): any => {
const nexmo = new Nexmo({
apiKey: min.instance.smsKey,
Expand Down Expand Up @@ -575,8 +578,10 @@ export class GBConversationalService {
}
if (currentText !== '') {
if (!mobile) {
GBLog.info(`Sending .MD file to Web.`);
await step.context.sendActivity(currentText);
} else {
GBLog.info(`Sending .MD file to mobile: ${mobile}.`);
await this.sendToMobile(min, mobile, currentText);
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,11 +795,11 @@ export class GBDeployer implements IGBDeployer {

// Clean up node_modules folder as it is only needed during compile time.

const nodeModules = urlJoin(root, 'node_modules');
if (Fs.existsSync(nodeModules)) {
rimraf.sync(nodeModules);
GBLog.info(`Cleaning default.gbui node_modules...`);
}
// const nodeModules = urlJoin(root, 'node_modules');
// if (Fs.existsSync(nodeModules)) {
// rimraf.sync(nodeModules);
// GBLog.info(`Cleaning default.gbui node_modules...`);
// }
}

/**
Expand Down
21 changes: 12 additions & 9 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export class GBMinService {
instance.marketplacePassword,
async (err, token) => {
if (err) {
const msg = `Error acquiring token: ${err}`;
const msg = `handleOAuthTokenRequests: Error acquiring token: ${err}`;
GBLog.error(msg);
res.send(msg);
} else {
Expand Down Expand Up @@ -476,6 +476,7 @@ export class GBMinService {
);
authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${min.instance.marketplaceId
}&redirect_uri=${urlJoin(min.instance.botEndpoint, min.instance.botId, 'token')}`;
GBLog.info(`HandleOAuthRequests: ${authorizationUrl}.`);
res.redirect(authorizationUrl);
});
}
Expand All @@ -487,16 +488,18 @@ export class GBMinService {

// Translates the requested botId.

let id = req.params.botId;
if (id === '[default]' || id === undefined) {
id = GBConfigService.get('BOT_ID');
let botId = req.params.botId;
if (botId === '[default]' || botId === undefined) {
botId = GBConfigService.get('BOT_ID');
}

GBLog.info(`Client requested instance for: ${botId}.`);

// Loads by the botId itself or by the activationCode field.

let instance = await this.core.loadInstanceByBotId(id);
let instance = await this.core.loadInstanceByBotId(botId);
if (instance === null) {
instance = await this.core.loadInstanceByActivationCode(id);
instance = await this.core.loadInstanceByActivationCode(botId);
}

if (instance !== null) {
Expand All @@ -515,7 +518,7 @@ export class GBMinService {
res.send(
JSON.stringify({
instanceId: instance.instanceId,
botId: id,
botId: botId,
theme: theme,
webchatToken: webchatTokenContainer.token,
speechToken: speechToken,
Expand All @@ -530,7 +533,7 @@ export class GBMinService {
})
);
} else {
const error = `Instance not found while retrieving from .gbui web client: ${id}.`;
const error = `Instance not found while retrieving from .gbui web client: ${botId}.`;
res.sendStatus(error);
GBLog.error(error);
}
Expand Down Expand Up @@ -668,7 +671,7 @@ export class GBMinService {
min.dialogs.add(
new OAuthPrompt('oAuthPrompt', {
connectionName: 'OAuth2',
text: 'Please sign in.',
text: 'Please sign in to General Bots.',
title: 'Sign in',
timeout: 300000
})
Expand Down
15 changes: 14 additions & 1 deletion packages/default.gbui/src/GBUIApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import React from 'react';
import GBMarkdownPlayer from './players/GBMarkdownPlayer.js';
import GBImagePlayer from './players/GBImagePlayer.js';
import GBVideoPlayer from './players/GBVideoPlayer.js';
import GBUrlPlayer from './players/GBUrlPlayer.js';
import GBLoginPlayer from './players/GBLoginPlayer.js';
import GBBulletPlayer from './players/GBBulletPlayer.js';
import SidebarMenu from './components/SidebarMenu.js';
Expand Down Expand Up @@ -261,6 +262,16 @@ class GBUIApp extends React.Component {
/>
);
break;
case 'url':
playerComponent = (
<GBUrlPlayer
app={this}
ref={player => {
this.player = player;
}}
/>
);
break;
case 'image':
playerComponent = (
<GBImagePlayer
Expand Down Expand Up @@ -299,6 +310,7 @@ class GBUIApp extends React.Component {

let chat = <div />;
let gbCss = <div />;
let seo= <div />;

let sideBar = (
<div className="sidebar">
Expand All @@ -308,6 +320,7 @@ class GBUIApp extends React.Component {

if (this.state.line && this.state.instance) {
gbCss = <GBCss instance={this.state.instance} />;
seo = <SEO instance={this.state.instance}/>;

// let speechOptions;
// let token = this.state.instanceClient.speechToken;
Expand Down Expand Up @@ -345,7 +358,7 @@ class GBUIApp extends React.Component {

return (
<StaticContent>
<SEO></SEO>
{seo}
<div>
{gbCss}
{sideBar}
Expand Down
57 changes: 34 additions & 23 deletions packages/default.gbui/src/components/SEO.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,37 @@
import React from "react"
import { SuperSEO } from 'react-super-seo';

const footer = () => (
<SuperSEO
title={this.props.instance.title}
description={this.props.instance.description}
lang="en"
openGraph={{
ogImage: {
ogImage: this.props.instance.paramLogoImageUrl,
ogImageAlt: this.props.instance.paramLogoImageAlt,
ogImageWidth: this.props.instance.paramLogoImageWidth,
ogImageHeight: this.props.instance.paramLogoImageHeight,
ogImageType: this.props.instance.paramLogoImageType,
},
}}
twitter={{
twitterSummaryCard: {
summaryCardImage: this.props.instance.paramLogoImageUrl,
summaryCardImageAlt: this.props.instance.paramLogoImageAlt,
summaryCardSiteUsername: this.props.instance.paramTwitterUsername,
},
}}
/>);
export default footer
class SEO extends React.Component {
render() {
let output = "";
if (this.props.instance) {
output = (
<SuperSEO
title={this.props.instance.title}
description={this.props.instance.description}
lang="en"
openGraph={{
ogImage: {
ogImage: this.props.instance.paramLogoImageUrl,
ogImageAlt: this.props.instance.paramLogoImageAlt,
ogImageWidth: this.props.instance.paramLogoImageWidth,
ogImageHeight: this.props.instance.paramLogoImageHeight,
ogImageType: this.props.instance.paramLogoImageType,
},
}}
twitter={{
twitterSummaryCard: {
summaryCardImage: this.props.instance.paramLogoImageUrl,
summaryCardImageAlt: this.props.instance.paramLogoImageAlt,
summaryCardSiteUsername: this.props.instance.paramTwitterUsername,
},
}}
/>);
} else {
output = <div />;
}
return output;
}
}

export default SEO
64 changes: 64 additions & 0 deletions packages/default.gbui/src/players/GBUrlPlayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' v `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| (˅) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| 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. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| 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. |
| |
\*****************************************************************************/

import React, { Component } from "react";

class GBUrlPlayer extends Component {
constructor() {
super();
this.state = {
src: ""
};
}

play(url) {
this.setState({ src: url });
}

stop() {
this.setState({ src: "" });
}
render() {
return (
<div className="gb-video-player-wrapper">
<iframe ref="video"
className="gb-video-react-player"
src={this.state.src}
width="100%"
height="100%"
/>
</div>
);
}
}

export default GBUrlPlayer;
22 changes: 21 additions & 1 deletion packages/kb.gbapp/services/KBService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ export class KBService implements IGBKBService {
public async sendAnswer(min: GBMinInstance, channel: string, step: GBDialogStep, answer: GuaribasAnswer) {
if (answer.content.endsWith('.mp4')) {
await this.playVideo(min, min.conversationalService, step, answer, channel);
} else if (answer.content.endsWith('.pdf')) {
await this.playUrl(min, min.conversationalService, step, answer, channel);
} else if (answer.format === '.md') {
await this.playMarkdown(min, answer, channel, step, min.conversationalService);
} else if (answer.content.endsWith('.ogg') && process.env.AUDIO_DISABLED !== 'true') {
Expand Down Expand Up @@ -715,6 +717,24 @@ export class KBService implements IGBKBService {
});
}

private async playUrl(
min,
conversationalService: IGBConversationalService,
step: GBDialogStep,
answer: GuaribasAnswer,
channel: string
) {
if (channel === 'whatsapp') {
await min.conversationalService.sendFile(min, step, null, answer.content, '');
} else {
await conversationalService.sendEvent(min, step, 'play', {
playerType: 'url',
data: urlJoin('kb',`${min.instance.botId}.gbai`,
`${min.instance.botId}.gbkb`, 'assets', answer.content)
});
}
}

private async playVideo(
min,
conversationalService: IGBConversationalService,
Expand All @@ -727,7 +747,7 @@ export class KBService implements IGBKBService {
} else {
await conversationalService.sendEvent(min, step, 'play', {
playerType: 'video',
data: answer.content
data: urlJoin(`${min.instance.botId}.gbai`, `${min.instance.botId}.gbkb`, 'videos', answer.content)
});
}
}
Expand Down

0 comments on commit 84fb074

Please sign in to comment.