new(default.gbui): New PDF player and log improvements.
This commit is contained in:
parent
22fca51a77
commit
84fb0748d0
7 changed files with 155 additions and 39 deletions
|
@ -240,11 +240,13 @@ export class GBConversationalService {
|
||||||
|
|
||||||
public async sendAudio(min: GBMinInstance, step: GBDialogStep, url: string): Promise<any> {
|
public async sendAudio(min: GBMinInstance, step: GBDialogStep, url: string): Promise<any> {
|
||||||
const mobile = step.context.activity.from.id;
|
const mobile = step.context.activity.from.id;
|
||||||
|
GBLog.info(`Sending audio to ${mobile} in URL: ${url}.`);
|
||||||
await min.whatsAppDirectLine.sendAudioToDevice(mobile, url);
|
await min.whatsAppDirectLine.sendAudioToDevice(mobile, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendEvent(min: GBMinInstance, step: GBDialogStep, name: string, value: Object): Promise<any> {
|
public async sendEvent(min: GBMinInstance, step: GBDialogStep, name: string, value: Object): Promise<any> {
|
||||||
if (step.context.activity.channelId === 'webchat') {
|
if (step.context.activity.channelId === 'webchat') {
|
||||||
|
GBLog.info(`Sending event ${name}:${typeof value === 'object' ? JSON.stringify(value) : value} to client...`);
|
||||||
const msg = MessageFactory.text('');
|
const msg = MessageFactory.text('');
|
||||||
msg.value = value;
|
msg.value = value;
|
||||||
msg.type = 'event';
|
msg.type = 'event';
|
||||||
|
@ -256,6 +258,7 @@ export class GBConversationalService {
|
||||||
|
|
||||||
// tslint:disable:no-unsafe-any due to Nexmo.
|
// tslint:disable:no-unsafe-any due to Nexmo.
|
||||||
public async sendSms(min: GBMinInstance, mobile: string, text: string): Promise<any> {
|
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 => {
|
return new Promise((resolve: any, reject: any): any => {
|
||||||
const nexmo = new Nexmo({
|
const nexmo = new Nexmo({
|
||||||
apiKey: min.instance.smsKey,
|
apiKey: min.instance.smsKey,
|
||||||
|
@ -575,8 +578,10 @@ export class GBConversationalService {
|
||||||
}
|
}
|
||||||
if (currentText !== '') {
|
if (currentText !== '') {
|
||||||
if (!mobile) {
|
if (!mobile) {
|
||||||
|
GBLog.info(`Sending .MD file to Web.`);
|
||||||
await step.context.sendActivity(currentText);
|
await step.context.sendActivity(currentText);
|
||||||
} else {
|
} else {
|
||||||
|
GBLog.info(`Sending .MD file to mobile: ${mobile}.`);
|
||||||
await this.sendToMobile(min, mobile, currentText);
|
await this.sendToMobile(min, mobile, currentText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -795,11 +795,11 @@ export class GBDeployer implements IGBDeployer {
|
||||||
|
|
||||||
// Clean up node_modules folder as it is only needed during compile time.
|
// Clean up node_modules folder as it is only needed during compile time.
|
||||||
|
|
||||||
const nodeModules = urlJoin(root, 'node_modules');
|
// const nodeModules = urlJoin(root, 'node_modules');
|
||||||
if (Fs.existsSync(nodeModules)) {
|
// if (Fs.existsSync(nodeModules)) {
|
||||||
rimraf.sync(nodeModules);
|
// rimraf.sync(nodeModules);
|
||||||
GBLog.info(`Cleaning default.gbui node_modules...`);
|
// GBLog.info(`Cleaning default.gbui node_modules...`);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -442,7 +442,7 @@ export class GBMinService {
|
||||||
instance.marketplacePassword,
|
instance.marketplacePassword,
|
||||||
async (err, token) => {
|
async (err, token) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
const msg = `Error acquiring token: ${err}`;
|
const msg = `handleOAuthTokenRequests: Error acquiring token: ${err}`;
|
||||||
GBLog.error(msg);
|
GBLog.error(msg);
|
||||||
res.send(msg);
|
res.send(msg);
|
||||||
} else {
|
} else {
|
||||||
|
@ -476,6 +476,7 @@ export class GBMinService {
|
||||||
);
|
);
|
||||||
authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${min.instance.marketplaceId
|
authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${min.instance.marketplaceId
|
||||||
}&redirect_uri=${urlJoin(min.instance.botEndpoint, min.instance.botId, 'token')}`;
|
}&redirect_uri=${urlJoin(min.instance.botEndpoint, min.instance.botId, 'token')}`;
|
||||||
|
GBLog.info(`HandleOAuthRequests: ${authorizationUrl}.`);
|
||||||
res.redirect(authorizationUrl);
|
res.redirect(authorizationUrl);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -487,16 +488,18 @@ export class GBMinService {
|
||||||
|
|
||||||
// Translates the requested botId.
|
// Translates the requested botId.
|
||||||
|
|
||||||
let id = req.params.botId;
|
let botId = req.params.botId;
|
||||||
if (id === '[default]' || id === undefined) {
|
if (botId === '[default]' || botId === undefined) {
|
||||||
id = GBConfigService.get('BOT_ID');
|
botId = GBConfigService.get('BOT_ID');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GBLog.info(`Client requested instance for: ${botId}.`);
|
||||||
|
|
||||||
// Loads by the botId itself or by the activationCode field.
|
// 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) {
|
if (instance === null) {
|
||||||
instance = await this.core.loadInstanceByActivationCode(id);
|
instance = await this.core.loadInstanceByActivationCode(botId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance !== null) {
|
if (instance !== null) {
|
||||||
|
@ -515,7 +518,7 @@ export class GBMinService {
|
||||||
res.send(
|
res.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
instanceId: instance.instanceId,
|
instanceId: instance.instanceId,
|
||||||
botId: id,
|
botId: botId,
|
||||||
theme: theme,
|
theme: theme,
|
||||||
webchatToken: webchatTokenContainer.token,
|
webchatToken: webchatTokenContainer.token,
|
||||||
speechToken: speechToken,
|
speechToken: speechToken,
|
||||||
|
@ -530,7 +533,7 @@ export class GBMinService {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else {
|
} 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);
|
res.sendStatus(error);
|
||||||
GBLog.error(error);
|
GBLog.error(error);
|
||||||
}
|
}
|
||||||
|
@ -668,7 +671,7 @@ export class GBMinService {
|
||||||
min.dialogs.add(
|
min.dialogs.add(
|
||||||
new OAuthPrompt('oAuthPrompt', {
|
new OAuthPrompt('oAuthPrompt', {
|
||||||
connectionName: 'OAuth2',
|
connectionName: 'OAuth2',
|
||||||
text: 'Please sign in.',
|
text: 'Please sign in to General Bots.',
|
||||||
title: 'Sign in',
|
title: 'Sign in',
|
||||||
timeout: 300000
|
timeout: 300000
|
||||||
})
|
})
|
||||||
|
|
|
@ -34,6 +34,7 @@ import React from 'react';
|
||||||
import GBMarkdownPlayer from './players/GBMarkdownPlayer.js';
|
import GBMarkdownPlayer from './players/GBMarkdownPlayer.js';
|
||||||
import GBImagePlayer from './players/GBImagePlayer.js';
|
import GBImagePlayer from './players/GBImagePlayer.js';
|
||||||
import GBVideoPlayer from './players/GBVideoPlayer.js';
|
import GBVideoPlayer from './players/GBVideoPlayer.js';
|
||||||
|
import GBUrlPlayer from './players/GBUrlPlayer.js';
|
||||||
import GBLoginPlayer from './players/GBLoginPlayer.js';
|
import GBLoginPlayer from './players/GBLoginPlayer.js';
|
||||||
import GBBulletPlayer from './players/GBBulletPlayer.js';
|
import GBBulletPlayer from './players/GBBulletPlayer.js';
|
||||||
import SidebarMenu from './components/SidebarMenu.js';
|
import SidebarMenu from './components/SidebarMenu.js';
|
||||||
|
@ -261,6 +262,16 @@ class GBUIApp extends React.Component {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case 'url':
|
||||||
|
playerComponent = (
|
||||||
|
<GBUrlPlayer
|
||||||
|
app={this}
|
||||||
|
ref={player => {
|
||||||
|
this.player = player;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
case 'image':
|
case 'image':
|
||||||
playerComponent = (
|
playerComponent = (
|
||||||
<GBImagePlayer
|
<GBImagePlayer
|
||||||
|
@ -299,6 +310,7 @@ class GBUIApp extends React.Component {
|
||||||
|
|
||||||
let chat = <div />;
|
let chat = <div />;
|
||||||
let gbCss = <div />;
|
let gbCss = <div />;
|
||||||
|
let seo= <div />;
|
||||||
|
|
||||||
let sideBar = (
|
let sideBar = (
|
||||||
<div className="sidebar">
|
<div className="sidebar">
|
||||||
|
@ -308,6 +320,7 @@ class GBUIApp extends React.Component {
|
||||||
|
|
||||||
if (this.state.line && this.state.instance) {
|
if (this.state.line && this.state.instance) {
|
||||||
gbCss = <GBCss instance={this.state.instance} />;
|
gbCss = <GBCss instance={this.state.instance} />;
|
||||||
|
seo = <SEO instance={this.state.instance}/>;
|
||||||
|
|
||||||
// let speechOptions;
|
// let speechOptions;
|
||||||
// let token = this.state.instanceClient.speechToken;
|
// let token = this.state.instanceClient.speechToken;
|
||||||
|
@ -345,7 +358,7 @@ class GBUIApp extends React.Component {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StaticContent>
|
<StaticContent>
|
||||||
<SEO></SEO>
|
{seo}
|
||||||
<div>
|
<div>
|
||||||
{gbCss}
|
{gbCss}
|
||||||
{sideBar}
|
{sideBar}
|
||||||
|
|
|
@ -33,26 +33,37 @@
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { SuperSEO } from 'react-super-seo';
|
import { SuperSEO } from 'react-super-seo';
|
||||||
|
|
||||||
const footer = () => (
|
class SEO extends React.Component {
|
||||||
<SuperSEO
|
render() {
|
||||||
title={this.props.instance.title}
|
let output = "";
|
||||||
description={this.props.instance.description}
|
if (this.props.instance) {
|
||||||
lang="en"
|
output = (
|
||||||
openGraph={{
|
<SuperSEO
|
||||||
ogImage: {
|
title={this.props.instance.title}
|
||||||
ogImage: this.props.instance.paramLogoImageUrl,
|
description={this.props.instance.description}
|
||||||
ogImageAlt: this.props.instance.paramLogoImageAlt,
|
lang="en"
|
||||||
ogImageWidth: this.props.instance.paramLogoImageWidth,
|
openGraph={{
|
||||||
ogImageHeight: this.props.instance.paramLogoImageHeight,
|
ogImage: {
|
||||||
ogImageType: this.props.instance.paramLogoImageType,
|
ogImage: this.props.instance.paramLogoImageUrl,
|
||||||
},
|
ogImageAlt: this.props.instance.paramLogoImageAlt,
|
||||||
}}
|
ogImageWidth: this.props.instance.paramLogoImageWidth,
|
||||||
twitter={{
|
ogImageHeight: this.props.instance.paramLogoImageHeight,
|
||||||
twitterSummaryCard: {
|
ogImageType: this.props.instance.paramLogoImageType,
|
||||||
summaryCardImage: this.props.instance.paramLogoImageUrl,
|
},
|
||||||
summaryCardImageAlt: this.props.instance.paramLogoImageAlt,
|
}}
|
||||||
summaryCardSiteUsername: this.props.instance.paramTwitterUsername,
|
twitter={{
|
||||||
},
|
twitterSummaryCard: {
|
||||||
}}
|
summaryCardImage: this.props.instance.paramLogoImageUrl,
|
||||||
/>);
|
summaryCardImageAlt: this.props.instance.paramLogoImageAlt,
|
||||||
export default footer
|
summaryCardSiteUsername: this.props.instance.paramTwitterUsername,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>);
|
||||||
|
} else {
|
||||||
|
output = <div />;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SEO
|
64
packages/default.gbui/src/players/GBUrlPlayer.js
Normal file
64
packages/default.gbui/src/players/GBUrlPlayer.js
Normal file
|
@ -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;
|
|
@ -503,6 +503,8 @@ export class KBService implements IGBKBService {
|
||||||
public async sendAnswer(min: GBMinInstance, channel: string, step: GBDialogStep, answer: GuaribasAnswer) {
|
public async sendAnswer(min: GBMinInstance, channel: string, step: GBDialogStep, answer: GuaribasAnswer) {
|
||||||
if (answer.content.endsWith('.mp4')) {
|
if (answer.content.endsWith('.mp4')) {
|
||||||
await this.playVideo(min, min.conversationalService, step, answer, channel);
|
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') {
|
} else if (answer.format === '.md') {
|
||||||
await this.playMarkdown(min, answer, channel, step, min.conversationalService);
|
await this.playMarkdown(min, answer, channel, step, min.conversationalService);
|
||||||
} else if (answer.content.endsWith('.ogg') && process.env.AUDIO_DISABLED !== 'true') {
|
} else if (answer.content.endsWith('.ogg') && process.env.AUDIO_DISABLED !== 'true') {
|
||||||
|
@ -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(
|
private async playVideo(
|
||||||
min,
|
min,
|
||||||
conversationalService: IGBConversationalService,
|
conversationalService: IGBConversationalService,
|
||||||
|
@ -727,7 +747,7 @@ export class KBService implements IGBKBService {
|
||||||
} else {
|
} else {
|
||||||
await conversationalService.sendEvent(min, step, 'play', {
|
await conversationalService.sendEvent(min, step, 'play', {
|
||||||
playerType: 'video',
|
playerType: 'video',
|
||||||
data: answer.content
|
data: urlJoin(`${min.instance.botId}.gbai`, `${min.instance.botId}.gbkb`, 'videos', answer.content)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue