fix(all): Packages updated and new DirectLine behaviour fixed.

This commit is contained in:
Rodrigo Rodriguez 2021-06-13 11:51:07 -03:00
parent 9ab73495fb
commit 517689fafe
12 changed files with 13033 additions and 11419 deletions

View file

@ -97,3 +97,11 @@ ALTER TABLE dbo.GuaribasQuestion ADD
skipIndex bit NULL
GO
# 2.0.116 >
ALTER TABLE dbo.GuaribasInstance ADD
googleBotKey nvarchar(255) NULL,
googleChatApiKey nvarchar(255) NULL,
googleChatSubscriptionName nvarchar(255) NULL,
GO

13
google-chat.json Normal file
View file

@ -0,0 +1,13 @@
{
"type": "service_account",
"project_id": "eastern-amp-316323",
"private_key_id": "4105f7f4cf2293adf2f561f7649449dedf9ab839",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCfIuztkRf8AZOr\ngOS8TDghQdme7eyvnT2Z+ly+9Q9D51frqsoKtbPJJSO9l3vX1qYGGEWHZlaPX5n6\nP1uTfYv9jjW9A2/oKZW/cV70O5wdFonn0sQblzC2+ZhlHuS6MQN0PqUvLNFGF57U\n5NCG3JUx1qhBHCPP5a/MXSXsvXTxngRtHfpKo2JbhsYXDHJl0+2DRJvx3+0WeIxW\ni7J2I0UXX4WlTORj9yaN4xVe/C2NPvQ+k9WGt1d2ql+F5w0ndnegOUOI8ZhQ3les\nw9KA0k1/ImC3q57+BIN5Xeg+NaY7r2gCEROqeDEs2v1TK9JsFhQJyvmLgjV64iLO\nogt677b5AgMBAAECggEAAymoCM6t6dnELA/rO9zN7sdGwnRbFGBtJX7G0hq/u2tB\nIZNq4Yyb7p74119H3FHNSei4lQjRJpdRUZppwQQpQJhPdBq54iTVb5EawILgxuk4\nQ226bQvzsWdDgpr7E8I+ndRS5x2eaSS2COglRtDifDOWc3jSM2MOu+KMCuj3BohD\n6NSnvewRqpaVQlpz5uqsPzZn77xyqW7xhpKPvU43RpBO1oSVWplX1nT65KpQjjC0\no+ry2bLRPtYq8SYWRXXTRaw4GkSZmam+QNxkDhGJzept38RcOQwjO5YOpfKDxcAp\nlgCPmq+DlhIHYWxgYEPyINXmU8UrUyD57LmSxKuUswKBgQDUKcXQHybOMyBjkAW+\nUh9zGaR0XegNgq3dpiN7cf9Z0ChghRVXTKuFP5GE08+5btcXbrCabmtZg1CM3BHL\nQ1Muj2xPHpMhE0+pjeFpSNljpyufyjActyfvbYH6CuaYnJKOrhce+FaMhIFRXsqI\no86tJxV3slglAj6bCY0WvSJ51wKBgQDABFbGT0uF+cUNJB9R1IBDZwpbom/iWi7t\nrbyR2J1FC1naxItN9tOm2Taq2iTX3UxIAM9Tu36dBgoq2ZZ6GAG6kiEFnaChDYho\nOnh9X1x9EJ8JnFyOFnDRB5OOSRfhDUn89/bjcx2Pgy4+r1eZQcdfqAjom6V52+7l\nFthSvYlbrwKBgFd89k5xWh4zpQqJbGTkFoXvMAqwYq2XkrzQ8tbH1oWhudS7bGZ4\nfk5PPWGpuoH7/AR0p6y3Fdtus/uyEEBifd24VPB3ajJ8dSA1GpvA56wZVnro9FgT\nCwvHe46xig+qmSDvFye1PnNpfK4iSaB49BQhBtA6IfD48PobwSt8SMg3AoGAIOod\nfczl40dXUdNZUwucGPG2wtJrX1+aH7/iTRXWj5lMg8WhI3ImAbnGNy9BlYcnpkgN\nQgsnvv7kC0hVFQS8dyDJbE8C09igA03SjZslHYMV3+3fp7ONDye/UWqSH0/J2QUg\nWwjGjm0sJi6kU28FIA6LyGO1z9e1caui1TwMKZ0CgYEAte4JER5zi/Gmb0Q/05XP\np7UHYjMbkpOW5FMp7aE5rd4LtCZrGDhZUhhKwHPNDIL5uirYQC4dkpGbbPRlmTy+\nXmvjSaqrlLWzvYK9o98a7f12AwxTEmULXd4U/eR4zbZuxpXrlD36YPONA7cbGQ4J\n/5RAByRbjc1dDtaI/m5BssQ=\n-----END PRIVATE KEY-----\n",
"client_email": "starting-account-otllxgcv9auu@eastern-amp-316323.iam.gserviceaccount.com",
"client_id": "103388169832798500398",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/starting-account-otllxgcv9auu%40eastern-amp-316323.iam.gserviceaccount.com"
}

7325
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -48,15 +48,15 @@
"commit": "git-cz"
},
"dependencies": {
"@azure/ms-rest-js": "2.1.0",
"@azure/ms-rest-js": "2.5.1",
"@google-cloud/pubsub": "^2.13.0",
"@microsoft/microsoft-graph-client": "2.1.1",
"@microsoft/microsoft-graph-client": "2.2.1",
"@semantic-release/changelog": "5.0.1",
"@semantic-release/exec": "5.0.0",
"@semantic-release/git": "9.0.0",
"@sendgrid/mail": "^7.4.2",
"@types/validator": "13.1.0",
"adal-node": "0.2.1",
"@sendgrid/mail": "^7.4.4",
"@types/validator": "13.1.4",
"adal-node": "0.2.2",
"any-shell-escape": "0.1.1",
"async-promises": "0.2.3",
"azure-arm-cognitiveservices": "3.0.0",
@ -67,34 +67,33 @@
"azure-search-client": "3.1.5",
"bluebird": "3.7.2",
"body-parser": "1.19.0",
"botbuilder": "4.11.0",
"botbuilder": "4.13.5",
"botbuilder-adapter-facebook": "^1.0.11",
"botbuilder-adapter-hangouts": "^1.0.8",
"botbuilder-ai": "4.11.0",
"botbuilder-dialogs": "4.11.0",
"botframework-connector": "4.11.0",
"botlib": "1.7.1",
"botbuilder-ai": "4.13.5",
"botbuilder-dialogs": "4.13.5",
"botframework-connector": "4.13.5",
"botlib": "1.8.1",
"cli-spinner": "0.2.10",
"core-js": "3.7.0",
"core-js": "3.14.0",
"dotenv-extended": "2.9.0",
"exceljs": "4.2.0",
"exceljs": "4.2.1",
"express": "4.17.1",
"express-remove-route": "1.0.0",
"ffmpeg-static": "4.2.7",
"google-libphonenumber": "3.2.15",
"ffmpeg-static": "4.3.0",
"google-libphonenumber": "3.2.21",
"googleapis": "^76.0.0",
"ibm-watson": "5.7.1",
"js-beautify": "1.13.0",
"marked": "1.2.5",
"microsoft-cognitiveservices-speech-sdk": "1.14.1",
"ibm-watson": "6.1.1",
"js-beautify": "1.13.13",
"marked": "2.0.7",
"microsoft-cognitiveservices-speech-sdk": "1.17.0",
"ms-rest-azure": "3.0.0",
"nexmo": "2.9.1",
"node-cron": "2.0.3",
"node-cron": "3.0.0",
"opn": "6.0.0",
"phone": "2.4.17",
"phone": "2.4.21",
"pragmatismo-io-framework": "1.0.20",
"prism-media": "1.2.2",
"public-ip": "4.0.2",
"prism-media": "1.3.1",
"public-ip": "4.0.4",
"readline": "1.3.0",
"reflect-metadata": "0.1.13",
"request-promise": "4.2.5",
@ -104,14 +103,14 @@
"scanf": "1.1.2",
"sequelize": "5.21.5",
"sequelize-typescript": "1.1.0",
"simple-git": "2.23.0",
"simple-git": "2.39.1",
"speakingurl": "^14.0.1",
"sppull": "2.6.7",
"sppull": "2.7.0",
"strict-password-generator": "1.1.2",
"swagger-client": "2.1.18",
"tedious": "9.2.1",
"textract": "2.5.0",
"typescript": "4.1.2",
"typescript": "4.3.2",
"url-join": "4.0.1",
"vbscript-to-typescript": "1.0.8",
"walk-promise": "0.2.0",
@ -120,22 +119,22 @@
"devDependencies": {
"@types/url-join": "4.0.0",
"@types/winston": "2.4.4",
"ban-sensitive-files": "1.9.14",
"commitizen": "4.2.2",
"ban-sensitive-files": "1.9.15",
"commitizen": "4.2.4",
"cz-conventional-changelog": "3.3.0",
"dependency-check": "4.1.0",
"git-issues": "1.3.1",
"license-checker": "25.0.1",
"ngrok": "3.3.0",
"ngrok": "4.0.1",
"nsp": "3.2.1",
"prettier-standard": "16.4.1",
"semantic-release": "17.2.4",
"simple-commit-message": "4.0.13",
"semantic-release": "17.4.3",
"simple-commit-message": "4.1.2",
"travis-deploy-once": "5.0.11",
"ts-node": "9.0.0",
"ts-node": "10.0.0",
"tslint": "6.1.2",
"tslint-microsoft-contrib": "^6.2.0",
"typedoc": "0.19.2"
"typedoc": "0.20.36"
},
"eslintConfig": {
"env": {

View file

@ -83,8 +83,7 @@ export class SystemKeywords {
method: 'GET',
encoding: 'binary'
};
const res = await request(options);
Buffer.from(res, 'binary').toString();
return await request(options); // TODO: Check this.
}
/**

View file

@ -133,6 +133,15 @@ export class GuaribasInstance extends Model<GuaribasInstance>
@Column
public cloudLocation: string;
@Column
public googleBotKey: string;
@Column
public googleChatApiKey: string;
@Column
public googleChatSubscriptionName: string;
@Column
public whatsappBotKey: string;

View file

@ -42,7 +42,6 @@ const removeRoute = require('express-remove-route');
const AuthenticationContext = require('adal-node').AuthenticationContext;
const wash = require('washyourmouthoutwithsoap');
const { FacebookAdapter } = require('botbuilder-adapter-facebook');
const { HangoutsAdapter } = require('botbuilder-adapter-hangouts');
import {
AutoSaveStateMiddleware,
BotFrameworkAdapter,
@ -652,14 +651,13 @@ export class GBMinService {
}
});
let GoogleChatSubscriptionName = '';
let GoogleWebChatKey = '';
min['googleDirectLine'] = new GoogleChatDirectLine(
min,
min.botId,
GoogleWebChatKey,
GoogleChatSubscriptionName
min.instance.googleBotKey,
min.instance.googleChatSubscriptionName,
min.instance.googleChatApiKey
);
await min['googleDirectLine'].setup(true);
@ -807,14 +805,6 @@ export class GBMinService {
firstTime = true;
// Sends loadInstance event to .gbui clients and loads FAQ.
await min.conversationalService.sendEvent(min, step, 'loadInstance', {
instanceId: instance.instanceId,
botId: instance.botId,
theme: instance.theme ? instance.theme : 'default.gbtheme',
secret: instance.webchatKey
});
const service = new KBService(min.core.sequelize);
const data = await service.getFaqBySubjectArray(instance.instanceId, 'faq', undefined);
await min.conversationalService.sendEvent(min, step, 'play', {

File diff suppressed because it is too large Load diff

View file

@ -8,22 +8,22 @@
"homepage": ".",
"dependencies": {
"@midudev/react-static-content": "^1.0.4",
"ajv": "^6.10.2",
"botframework-directlinejs": "0.11.6",
"botframework-webchat": "^4.7.1",
"ajv": "^8.6.0",
"botframework-directlinejs": "0.14.1",
"botframework-webchat": "^4.13.0",
"deep-extend": "0.6.0",
"fetch": "1.1.0",
"msal": "^1.2.0",
"powerbi-client": "2.10.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-helmet": "5.2.1",
"react-player": "^1.14.2",
"react-powerbi": "0.5.2",
"react-scripts": "^3.3.0",
"react-super-seo": "^1.0.5",
"react-transition-group": "^4.3.0",
"rxjs": "^6.5.4",
"msal": "^1.4.11",
"powerbi-client": "2.18.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-helmet": "6.1.0",
"react-player": "^2.9.0",
"react-powerbi": "0.9.1",
"react-scripts": "^4.0.3",
"react-super-seo": "^1.0.6",
"react-transition-group": "^4.4.2",
"rxjs": "^7.1.0",
"url-join": "4.0.1"
},
"scripts": {

View file

@ -52,7 +52,6 @@ class GBUIApp extends React.Component {
this.state = {
line: null,
instance: null,
token: null,
instanceClient: null
};
@ -132,8 +131,7 @@ class GBUIApp extends React.Component {
.then(res => res.json())
.then(
result => {
this.setState({ instanceClient: result });
this.setupBotConnection();
this.setupBotConnection(result);
},
error => {
this.setState({
@ -166,7 +164,8 @@ class GBUIApp extends React.Component {
);
window.userAgentApplication = userAgentApplication;
if (!userAgentApplication.isCallback(window.location.hash) && window.parent === window && !window.opener) {
if (!userAgentApplication.isCallback(window.location.hash) && window.parent === window
&& !window.opener && userAgentApplication.getUser) {
var user = userAgentApplication.getUser();
if (user) {
userAgentApplication.acquireTokenSilent(graphScopes).then(
@ -181,32 +180,32 @@ class GBUIApp extends React.Component {
}
}
setupBotConnection() {
setupBotConnection(instanceClient) {
let _this_ = this;
window['botchatDebug'] = true;
const line = new DirectLine({
token: this.state.instanceClient.webchatToken
token: instanceClient.webchatToken
});
_this_.setState({ line: line});
line.connectionStatus$.subscribe(connectionStatus => {
if (connectionStatus === ConnectionStatus.Online) {
_this_.setState({ line: line });
window['botConnection'] = line;
_this_.setState({ instanceClient: instanceClient});
window['botConnection'] = line;
}
});
window.line = line;
line.activity$
.filter(activity => activity.type === 'event' && activity.name === 'loadInstance')
.subscribe(activity => {
this.postEvent('startGB', true);
_this_.setState({ instance: activity.value });
_this_.authenticate();
});
.filter(activity => activity.type === 'event' && activity.name === 'loadInstance')
.subscribe(activity => {
this.postEvent('startGB', true);
_this_.authenticate();
});
line.activity$
line.activity$
.filter(activity => activity.type === 'event' && activity.name === 'stop')
.subscribe(activity => {
if (_this_.player) {
@ -313,16 +312,17 @@ class GBUIApp extends React.Component {
let sideBar = (
<div className="sidebar">
<SidebarMenu chat={this.chat} instance={this.state.instance} />
<SidebarMenu chat={this.chat} instance={this.state.instanceClient} />
</div>
);
if (this.state.line && this.state.instance) {
if (this.state.instanceClient) {
gbCss = <GBCss instance={this.state.instance} />;
seo = <SEO instance={this.state.instance} />;
// let speechOptions;
gbCss = <GBCss instance={this.state.instanceClient} />;
seo = <SEO instance={this.state.instanceClient} />;
}
if (this.state.line) {
// let speechOptions;
// let token = this.state.instanceClient.speechToken;
// speechOptions = {
@ -352,7 +352,7 @@ class GBUIApp extends React.Component {
);
}
if (!this.state.instance) {
if (!this.state.instanceClient) {
sideBar = '';
}

View file

@ -50,7 +50,7 @@ class GBUrlPlayer extends Component {
render() {
return (
<div className="gb-video-player-wrapper">
<iframe ref="video"
<iframe title="Video" ref="video"
className="gb-video-react-player"
src={this.state.src}
width="100%"

View file

@ -43,6 +43,9 @@ import { GBConversationalService } from '../../core.gbapp/services/GBConversatio
import { SecService } from '../../security.gbapp/services/SecService';
import { Messages } from '../strings';
const { google } = require('googleapis')
const chat = google.chat('v1');
const { promisify } = require('util');
chat.spaces.messages.createAsync = promisify(chat.spaces.messages.create);
const { PubSub } = require('@google-cloud/pubsub');
// Creates a client; cache this for further use
@ -64,12 +67,14 @@ export class GoogleChatDirectLine extends GBService {
public min: GBMinInstance;
private directLineSecret: string;
pubSubClient: any;
GoogleChatApiKey: any;
constructor(
min: GBMinInstance,
botId,
directLineSecret,
GoogleChatSubscriptionName
GoogleChatSubscriptionName,
GoogleChatApiKey,
) {
super();
@ -78,6 +83,7 @@ export class GoogleChatDirectLine extends GBService {
this.directLineSecret = directLineSecret;
this.GoogleChatSubscriptionName = GoogleChatSubscriptionName;
this.pubSubClient = new PubSub();
this.GoogleChatApiKey = GoogleChatApiKey;
}
@ -107,7 +113,7 @@ export class GoogleChatDirectLine extends GBService {
try {
const subscription = this.pubSubClient.subscription(this.GoogleChatSubscriptionName);
subscription.on('message', this.receiver);
subscription.on('message', this.receiver.bind(this));
} catch (error) {
GBLog.error(`Error initializing 3rd party GoogleChat provider(1) ${error.message}`);
@ -116,8 +122,8 @@ export class GoogleChatDirectLine extends GBService {
}
public async resetConversationId(number) {
GoogleChatDirectLine.conversationIds[number] = undefined;
public async resetConversationId(key) {
GoogleChatDirectLine.conversationIds[key] = undefined;
}
public async check() {
@ -127,30 +133,36 @@ export class GoogleChatDirectLine extends GBService {
public async receiver(message) {
GBLog.info(`Received message ${message.id}:`);
GBLog.info(`\tData: ${message.data}`);
GBLog.info(`\tAttributes: ${message.attributes}`);
const event = JSON.parse(Buffer.from(message.data, 'binary').toString());
let from = '';
let fromName='';
let text;
const threadName = event.message.thread.name;
if (event['type'] === 'ADDED_TO_SPACE' && event['space']['singleUserBotDm'])
{
}else if(event['type'] === 'MESSAGE')
{
text = event.message.text;
fromName = event.message.sender.displayName;
from = event.message.sender.email;
GBLog.info(`Received message from ${from} (${fromName}): ${text}.`);
}
message.ack();
let from = message.id; // TODO: update.
let text = message.data;
let fromName = 'GB';
GBLog.info(`GBGoogleChat: RCV ${from}: ${text})`);
await CollectionUtil.asyncForEach(this.min.appPackages, async (e: IGBPackage) => {
await e.onExchangeData(this.min, 'GoogleChatMessage', message);
});
const client = await this.directLineClient;
const conversationId = GoogleChatDirectLine.conversationIds[from];
const conversationId = GoogleChatDirectLine.conversationIds[threadName];
if (GoogleChatDirectLine.conversationIds[from] === undefined) {
if (GoogleChatDirectLine.conversationIds[threadName] === undefined) {
GBLog.info(`GBGoogleChat: Starting new conversation on Bot.`);
const response = await client.Conversations.Conversations_StartConversation();
const generatedConversationId = response.obj.conversationId;
GoogleChatDirectLine.conversationIds[from] = generatedConversationId;
GoogleChatDirectLine.conversationIds[threadName] = generatedConversationId;
this.pollMessages(client, generatedConversationId, from, fromName);
this.inputMessage(client, generatedConversationId, text, from, fromName);
@ -237,29 +249,26 @@ export class GoogleChatDirectLine extends GBService {
await this.sendToDevice(from, output);
}
public async sendToDevice(to: string, msg: string) {
const privatekey = require('./a.json')
const scopes = ['https://www.googleapis.com/auth/chat.bot'];
public async sendToDevice(threadName: string, msg: string) {
try {
const jwtClient = new google.auth.JWT(
privatekey.client_email,
null,
privatekey.private_key,
scopes,
'adminEmail@org.com'
);
await jwtClient.authorize();
const chat = google.chat({ version: 'v1', auth: jwtClient });
const res = await chat.spaces.messages.get({ name: 'spaces/XXX/messages/XX.XX' })
GBLog.info(res)
GBLog.info(`Message [${msg}] sent to ${to}: `);
let threadParts = threadName.split('/');
let spaces = threadParts[1];
let threadKey = threadParts[3];
const res = await chat.spaces.messages.createAsync({
auth: this.GoogleChatApiKey,
parent: `spaces/${spaces}`,
threadKey: threadKey,
body: {
text: msg
}
});
GBLog.info(res);
GBLog.info(`Message [${msg}] sent to ${threadName}: `);
} catch (error) {
GBLog.error(`Error sending message to GoogleChat provider ${error.message}`);
// TODO: Handle Error: socket hang up and retry.
}
}