fix(whatsapp.gblib): Fixing loop behaviour.
This commit is contained in:
parent
d61d2f86e8
commit
10d2a4afb9
5 changed files with 39 additions and 27 deletions
|
@ -305,11 +305,15 @@ STORAGE_SYNC=true
|
|||
const instance = instances[0];
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
GBLog.info(`Updating bot endpoint to local reverse proxy (ngrok)...`);
|
||||
await installationDeployer.updateBotProxy(
|
||||
instance.botId,
|
||||
instance.botId,
|
||||
`${proxyAddress}/api/messages/${instance.botId}`
|
||||
);
|
||||
try {
|
||||
await installationDeployer.updateBotProxy(
|
||||
instance.botId,
|
||||
instance.botId,
|
||||
`${proxyAddress}/api/messages/${instance.botId}`
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error(`Error updating bot proxy with proxy address${error.message}.`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.parent === undefined) {
|
||||
|
@ -356,7 +360,7 @@ STORAGE_SYNC=true
|
|||
// NOTE: if there is any code before this line a semicolon
|
||||
// will be necessary before this line.
|
||||
// Loads all system packages.
|
||||
|
||||
const sysPackages: IGBPackage[] = [];
|
||||
[
|
||||
GBAdminPackage,
|
||||
GBAnalyticsPackage,
|
||||
|
@ -367,9 +371,15 @@ STORAGE_SYNC=true
|
|||
GBWhatsappPackage
|
||||
].forEach(e => {
|
||||
GBLog.info(`Loading sys package: ${e.name}...`);
|
||||
|
||||
const p = Object.create(e.prototype) as IGBPackage;
|
||||
if (e.name === 'GBWhatsappPackage') {
|
||||
sysPackages.push(p);
|
||||
}
|
||||
p.loadPackage(core, core.sequelize);
|
||||
});
|
||||
|
||||
return sysPackages;
|
||||
}
|
||||
|
||||
public ensureAdminIsSecured() {
|
||||
|
|
|
@ -36,15 +36,12 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const { DialogSet, TextPrompt } = require('botbuilder-dialogs');
|
||||
import urlJoin = require('url-join');
|
||||
const { DialogSet, TextPrompt } = require('botbuilder-dialogs');
|
||||
const express = require('express');
|
||||
|
||||
const request = require('request-promise-native');
|
||||
const AuthenticationContext = require('adal-node').AuthenticationContext;
|
||||
|
||||
import { AutoSaveStateMiddleware, BotFrameworkAdapter, ConversationState, MemoryStorage, UserState } from 'botbuilder';
|
||||
|
||||
import { ConfirmPrompt, WaterfallDialog } from 'botbuilder-dialogs';
|
||||
import {
|
||||
GBDialogStep,
|
||||
|
@ -57,6 +54,8 @@ import {
|
|||
IGBPackage
|
||||
} from 'botlib';
|
||||
|
||||
import { MicrosoftAppCredentials } from 'botframework-connector';
|
||||
import { GBServer } from '../../../src/app';
|
||||
import { GBAnalyticsPackage } from '../../analytics.gblib';
|
||||
import { GBCorePackage } from '../../core.gbapp';
|
||||
import { GBCustomerSatisfactionPackage } from '../../customer-satisfaction.gbapp';
|
||||
|
@ -66,8 +65,8 @@ import { GBSecurityPackage } from '../../security.gblib';
|
|||
import { GBWhatsappPackage } from '../../whatsapp.gblib';
|
||||
import { Messages } from '../strings';
|
||||
import { GBAdminPackage } from './../../admin.gbapp/index';
|
||||
import { GBDeployer } from './GBDeployer';
|
||||
import { GBConfigService } from './GBConfigService';
|
||||
import { GBDeployer } from './GBDeployer';
|
||||
|
||||
/**
|
||||
* Minimal service layer for a bot.
|
||||
|
@ -319,12 +318,16 @@ export class GBMinService {
|
|||
appId: instance.marketplaceId,
|
||||
appPassword: instance.marketplacePassword
|
||||
});
|
||||
|
||||
const storage = new MemoryStorage();
|
||||
|
||||
const conversationState = new ConversationState(storage);
|
||||
const userState = new UserState(storage);
|
||||
adapter.use(new AutoSaveStateMiddleware(conversationState, userState));
|
||||
|
||||
MicrosoftAppCredentials.trustServiceUrl('https://directline.botframework.com',
|
||||
new Date(new Date().setFullYear(new Date().getFullYear() + 10)));
|
||||
|
||||
|
||||
// The minimal bot is built here.
|
||||
|
||||
const min = new GBMinInstance();
|
||||
|
@ -338,6 +341,7 @@ export class GBMinService {
|
|||
min.cbMap = {};
|
||||
min.scriptMap = {};
|
||||
min.sandBoxMap = {};
|
||||
min.packages = GBServer.globals.sysPackages[0]; // HACK: Whatsapp now.
|
||||
min.userProfile = conversationState.createProperty('userProfile');
|
||||
const dialogState = conversationState.createProperty('dialogState');
|
||||
|
||||
|
@ -401,6 +405,7 @@ export class GBMinService {
|
|||
step.context.activity.locale = 'pt-BR';
|
||||
|
||||
try {
|
||||
|
||||
const user = await min.userProfile.get(context, {});
|
||||
|
||||
if (!user.loaded) {
|
||||
|
@ -423,14 +428,11 @@ export class GBMinService {
|
|||
);
|
||||
if (context.activity.type === 'conversationUpdate' && context.activity.membersAdded.length > 0) {
|
||||
const member = context.activity.membersAdded[0];
|
||||
if (member.name === 'GeneralBots') {
|
||||
if (member.name === min.instance.title) {
|
||||
GBLog.info(`Bot added to conversation, starting chat...`);
|
||||
appPackages.forEach(e => {
|
||||
e.onNewSession(min, step);
|
||||
});
|
||||
// Processes the root dialog.
|
||||
|
||||
await step.beginDialog('/');
|
||||
} else {
|
||||
GBLog.info(`Member added to conversation: ${member.name}`);
|
||||
}
|
||||
|
|
|
@ -57,8 +57,7 @@ export class GBWhatsappPackage implements IGBPackage {
|
|||
min.instance.whatsappBotKey,
|
||||
min.instance.whatsappServiceKey,
|
||||
min.instance.whatsappServiceNumber,
|
||||
min.instance.whatsappServiceUrl,
|
||||
min.instance.botId
|
||||
min.instance.whatsappServiceUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
const result = request.post(options);
|
||||
GBLog.info(result);
|
||||
} catch (error) {
|
||||
GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error}`);
|
||||
GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
.then(response => {
|
||||
return response.obj.conversationId;
|
||||
}).catch(err => {
|
||||
GBLog.error(`Error calling Conversations_StartConversation on Whatsapp channel ${err}`);
|
||||
GBLog.error(`Error calling Conversations_StartConversation on Whatsapp channel ${err.data}`);
|
||||
})
|
||||
|
||||
.then(generatedConversationId => {
|
||||
|
@ -102,14 +102,14 @@ export class WhatsappDirectLine extends GBService {
|
|||
this.pollMessages(client, generatedConversationId, from, fromName);
|
||||
})
|
||||
.catch(err => {
|
||||
GBLog.error(`Error starting conversation ${err}`);
|
||||
GBLog.error(`Error starting conversation ${err.data}`);
|
||||
});
|
||||
} else {
|
||||
this.inputMessage(client, conversationId, text, from, fromName);
|
||||
}
|
||||
res.end();
|
||||
}).catch(err => {
|
||||
GBLog.error(`Error initializing DirectLine for Whatsapp channel ${err}`);
|
||||
GBLog.error(`Error initializing DirectLine for Whatsapp channel ${err.data}`);
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
replyToId: from
|
||||
}
|
||||
}).catch(err => {
|
||||
GBLog.error(`GBWhatsapp: Error receiving message: ${err}.`);
|
||||
GBLog.error(`GBWhatsapp: Error receiving message: ${err.data}.`);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -147,13 +147,13 @@ export class WhatsappDirectLine extends GBService {
|
|||
return response.obj.activities;
|
||||
})
|
||||
.catch(err => {
|
||||
GBLog.error(`Error calling Conversations_GetActivities on Whatsapp channel ${err}`);
|
||||
GBLog.error(`Error calling Conversations_GetActivities on Whatsapp channel ${err.data}`);
|
||||
})
|
||||
.then(activities => {
|
||||
this.printMessages(activities, conversationId, from, fromName);
|
||||
})
|
||||
.catch(err => {
|
||||
GBLog.error(`Error calling printMessages on Whatsapp channel ${err}`);
|
||||
GBLog.error(`Error calling printMessages on Whatsapp channel ${err.data}`);
|
||||
});
|
||||
|
||||
}, this.pollInterval);
|
||||
|
@ -225,7 +225,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
const result = request.post(options);
|
||||
GBLog.info(result);
|
||||
} catch (error) {
|
||||
GBLog.error(`Error sending message to Whatsapp provider ${error}`);
|
||||
GBLog.error(`Error sending message to Whatsapp provider ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ const appPackages: IGBPackage[] = [];
|
|||
export class RootData {
|
||||
public publicAddress: string;
|
||||
public server: any;
|
||||
sysPackages: any;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,7 +123,7 @@ export class GBServer {
|
|||
// Deploys system and user packages.
|
||||
|
||||
GBLog.info(`Deploying packages...`);
|
||||
core.loadSysPackages(core);
|
||||
GBServer.globals.sysPackages = core.loadSysPackages(core);
|
||||
await core.checkStorage(azureDeployer);
|
||||
await deployer.deployPackages(core, server, appPackages);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue