fix(app.ts): Preparing to use 4 or more SSL certificates.
This commit is contained in:
parent
a969abbcc4
commit
72b645fd2a
19 changed files with 142 additions and 98 deletions
|
@ -60,7 +60,7 @@ import QrScanner from 'qr-scanner';
|
||||||
import pkg from 'whatsapp-web.js';
|
import pkg from 'whatsapp-web.js';
|
||||||
import { ActivityTypes } from 'botbuilder';
|
import { ActivityTypes } from 'botbuilder';
|
||||||
const { List, Buttons } = pkg;
|
const { List, Buttons } = pkg;
|
||||||
import mime from 'mime';
|
import mime from 'mime-types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default check interval for user replay
|
* Default check interval for user replay
|
||||||
|
|
|
@ -45,26 +45,26 @@ import { Sequelize } from 'sequelize-typescript';
|
||||||
export class GBHubSpotPackage implements IGBPackage {
|
export class GBHubSpotPackage implements IGBPackage {
|
||||||
public sysPackages: IGBPackage[];
|
public sysPackages: IGBPackage[];
|
||||||
|
|
||||||
public async loadBot (min: GBMinInstance): Promise<void> {
|
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||||
GBLog.verbose(`loadBot called.`);
|
GBLog.verbose(`loadBot called.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDialogs (min: GBMinInstance) {
|
public async getDialogs(min: GBMinInstance) {
|
||||||
GBLog.verbose(`getDialogs called.`);
|
GBLog.verbose(`getDialogs called.`);
|
||||||
}
|
}
|
||||||
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||||
GBLog.verbose(`loadPackage called.`);
|
GBLog.verbose(`loadPackage called.`);
|
||||||
}
|
}
|
||||||
public async unloadPackage (core: IGBCoreService): Promise<void> {
|
public async unloadPackage(core: IGBCoreService): Promise<void> {
|
||||||
GBLog.verbose(`unloadPackage called.`);
|
GBLog.verbose(`unloadPackage called.`);
|
||||||
}
|
}
|
||||||
public async unloadBot (min: GBMinInstance): Promise<void> {
|
public async unloadBot(min: GBMinInstance): Promise<void> {
|
||||||
GBLog.verbose(`unloadBot called.`);
|
GBLog.verbose(`unloadBot called.`);
|
||||||
}
|
}
|
||||||
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||||
GBLog.verbose(`onNewSession called.`);
|
GBLog.verbose(`onNewSession called.`);
|
||||||
}
|
}
|
||||||
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
|
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||||
GBLog.verbose(`onExchangeData called.`);
|
GBLog.verbose(`onExchangeData called.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,4 +38,4 @@ import * as hubspot from '@hubspot/api-client';
|
||||||
/**
|
/**
|
||||||
* Support for Hub Spot XRM.
|
* Support for Hub Spot XRM.
|
||||||
*/
|
*/
|
||||||
export class HubSpotServices extends GBService {}
|
export class HubSpotServices extends GBService { }
|
||||||
|
|
|
@ -106,11 +106,11 @@ export class AskDialog extends IGBDialog {
|
||||||
|
|
||||||
if (step.options && step.options.firstTime) {
|
if (step.options && step.options.firstTime) {
|
||||||
text = Messages[locale].ask_first_time;
|
text = Messages[locale].ask_first_time;
|
||||||
}
|
}
|
||||||
else if (step.options && step.options.isReturning && !step.context.activity.group) {
|
else if (step.options && step.options.isReturning && !step.context.activity.group) {
|
||||||
text = Messages[locale].anything_else;
|
text = Messages[locale].anything_else;
|
||||||
}
|
}
|
||||||
else if (step.context.activity.group || (step.options && step.options.emptyPrompt)) {
|
else if (step.context.activity.group || (step.options && step.options.emptyPrompt)) {
|
||||||
text = '';
|
text = '';
|
||||||
} else if (user.subjects.length > 0) {
|
} else if (user.subjects.length > 0) {
|
||||||
text = Messages[locale].which_question;
|
text = Messages[locale].which_question;
|
||||||
|
@ -391,14 +391,14 @@ export class AskDialog extends IGBDialog {
|
||||||
async step => {
|
async step => {
|
||||||
if (GBServer.globals.chatGPT) {
|
if (GBServer.globals.chatGPT) {
|
||||||
let input = `Write a BASIC program that ${step.options.dialog.toLowerCase()}. And does not explain.`;
|
let input = `Write a BASIC program that ${step.options.dialog.toLowerCase()}. And does not explain.`;
|
||||||
|
|
||||||
await min.conversationalService.sendText(min, step, 'Thank you. The dialog is being written right now...');
|
await min.conversationalService.sendText(min, step, 'Thank you. The dialog is being written right now...');
|
||||||
|
|
||||||
const CHATGPT_TIMEOUT = 3 * 60 * 1000;
|
const CHATGPT_TIMEOUT = 3 * 60 * 1000;
|
||||||
GBLog.info(`ChatGPT Code: ${input}`);
|
GBLog.info(`ChatGPT Code: ${input}`);
|
||||||
let response = await GBServer.globals.chatGPT.sendMessage(input, {
|
let response = await GBServer.globals.chatGPT.sendMessage(input, {
|
||||||
timeoutMs: CHATGPT_TIMEOUT
|
timeoutMs: CHATGPT_TIMEOUT
|
||||||
});
|
});
|
||||||
|
|
||||||
// Removes instructions, just code.
|
// Removes instructions, just code.
|
||||||
|
|
||||||
|
@ -409,17 +409,17 @@ export class AskDialog extends IGBDialog {
|
||||||
|
|
||||||
// Gets dialog name and file handling
|
// Gets dialog name and file handling
|
||||||
|
|
||||||
let dialogName = step.result.replace('.', '');
|
let dialogName = step.result.replace('.', '');
|
||||||
const docx = urlJoin(`${min.botId}.gbdialog`, `${dialogName}.docx`);
|
const docx = urlJoin(`${min.botId}.gbdialog`, `${dialogName}.docx`);
|
||||||
const sys = new SystemKeywords();
|
const sys = new SystemKeywords();
|
||||||
const document = await sys.internalCreateDocument(min, docx, response);
|
const document = await sys.internalCreateDocument(min, docx, response);
|
||||||
await service.addQA(min, dialogName, dialogName);
|
await service.addQA(min, dialogName, dialogName);
|
||||||
|
|
||||||
let message = `Waiting for publishing...`;
|
let message = `Waiting for publishing...`;
|
||||||
await min.conversationalService.sendText(min, step, message);
|
await min.conversationalService.sendText(min, step, message);
|
||||||
|
|
||||||
await step.replaceDialog('/publish', { confirm: true });
|
await step.replaceDialog('/publish', { confirm: true });
|
||||||
|
|
||||||
message = `Dialog is ready! Let's run:`;
|
message = `Dialog is ready! Let's run:`;
|
||||||
await min.conversationalService.sendText(min, step, message);
|
await min.conversationalService.sendText(min, step, message);
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ export class AskDialog extends IGBDialog {
|
||||||
await step.endDialog();
|
await step.endDialog();
|
||||||
|
|
||||||
await GBVMService.callVM(dialogName.toLowerCase(),
|
await GBVMService.callVM(dialogName.toLowerCase(),
|
||||||
min, step, user, this.deployer, false);
|
min, step, user, this.deployer, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -53,7 +53,7 @@ export class FaqDialog extends IGBDialog {
|
||||||
* @param bot The bot adapter.
|
* @param bot The bot adapter.
|
||||||
* @param min The minimal bot instance data.
|
* @param min The minimal bot instance data.
|
||||||
*/
|
*/
|
||||||
public static setup (bot: BotAdapter, min: GBMinInstance) {
|
public static setup(bot: BotAdapter, min: GBMinInstance) {
|
||||||
const service = new KBService(min.core.sequelize);
|
const service = new KBService(min.core.sequelize);
|
||||||
|
|
||||||
min.dialogs.add(
|
min.dialogs.add(
|
||||||
|
|
|
@ -64,13 +64,13 @@ export class MenuDialog extends IGBDialog {
|
||||||
* @param bot The bot adapter.
|
* @param bot The bot adapter.
|
||||||
* @param min The minimal bot instance data.
|
* @param min The minimal bot instance data.
|
||||||
*/
|
*/
|
||||||
public static setup (bot: BotAdapter, min: GBMinInstance) {
|
public static setup(bot: BotAdapter, min: GBMinInstance) {
|
||||||
const service = new KBService(min.core.sequelize);
|
const service = new KBService(min.core.sequelize);
|
||||||
|
|
||||||
min.dialogs.add(new WaterfallDialog('/menu', MenuDialog.getMenuDialog(min, service)));
|
min.dialogs.add(new WaterfallDialog('/menu', MenuDialog.getMenuDialog(min, service)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getMenuDialog (min: GBMinInstance, service: KBService) {
|
private static getMenuDialog(min: GBMinInstance, service: KBService) {
|
||||||
return [
|
return [
|
||||||
async step => {
|
async step => {
|
||||||
if (step.context.activity.channelId !== 'msteams' && process.env.ENABLE_AUTH) {
|
if (step.context.activity.channelId !== 'msteams' && process.env.ENABLE_AUTH) {
|
||||||
|
|
|
@ -48,26 +48,26 @@ import { GuaribasAnswer, GuaribasQuestion, GuaribasSubject } from './models/inde
|
||||||
*/
|
*/
|
||||||
export class GBKBPackage implements IGBPackage {
|
export class GBKBPackage implements IGBPackage {
|
||||||
public sysPackages: IGBPackage[];
|
public sysPackages: IGBPackage[];
|
||||||
public async getDialogs (min: GBMinInstance) {
|
public async getDialogs(min: GBMinInstance) {
|
||||||
GBLog.verbose(`getDialogs called.`);
|
GBLog.verbose(`getDialogs called.`);
|
||||||
}
|
}
|
||||||
public async unloadPackage (core: IGBCoreService): Promise<void> {
|
public async unloadPackage(core: IGBCoreService): Promise<void> {
|
||||||
GBLog.verbose(`unloadPackage called.`);
|
GBLog.verbose(`unloadPackage called.`);
|
||||||
}
|
}
|
||||||
public async unloadBot (min: GBMinInstance): Promise<void> {
|
public async unloadBot(min: GBMinInstance): Promise<void> {
|
||||||
GBLog.verbose(`unloadBot called.`);
|
GBLog.verbose(`unloadBot called.`);
|
||||||
}
|
}
|
||||||
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||||
GBLog.verbose(`onNewSession called.`);
|
GBLog.verbose(`onNewSession called.`);
|
||||||
}
|
}
|
||||||
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
|
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||||
GBLog.verbose(`onExchangeData called.`);
|
GBLog.verbose(`onExchangeData called.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||||
core.sequelize.addModels([GuaribasAnswer, GuaribasQuestion, GuaribasSubject]);
|
core.sequelize.addModels([GuaribasAnswer, GuaribasQuestion, GuaribasSubject]);
|
||||||
}
|
}
|
||||||
public async loadBot (min: GBMinInstance): Promise<void> {
|
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||||
AskDialog.setup(min.bot, min);
|
AskDialog.setup(min.bot, min);
|
||||||
FaqDialog.setup(min.bot, min);
|
FaqDialog.setup(min.bot, min);
|
||||||
MenuDialog.setup(min.bot, min);
|
MenuDialog.setup(min.bot, min);
|
||||||
|
|
|
@ -646,10 +646,10 @@ export class KBService implements IGBKBService {
|
||||||
packageId: pkg.packageId,
|
packageId: pkg.packageId,
|
||||||
prevId: 0
|
prevId: 0
|
||||||
};
|
};
|
||||||
const a =await GuaribasAnswer.create(answer);
|
const a = await GuaribasAnswer.create(answer);
|
||||||
question['answerId'] = a.answerId;
|
question['answerId'] = a.answerId;
|
||||||
const q = await GuaribasQuestion.create(question);
|
const q = await GuaribasQuestion.create(question);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async importKbPackage(
|
public async importKbPackage(
|
||||||
|
|
|
@ -44,7 +44,7 @@ import { Messages } from '../strings.js';
|
||||||
* Dialogs for handling Menu control.
|
* Dialogs for handling Menu control.
|
||||||
*/
|
*/
|
||||||
export class OAuthDialog extends IGBDialog {
|
export class OAuthDialog extends IGBDialog {
|
||||||
public static getOAuthDialog (min: GBMinInstance) {
|
public static getOAuthDialog(min: GBMinInstance) {
|
||||||
return {
|
return {
|
||||||
id: '/auth',
|
id: '/auth',
|
||||||
waterfall: [
|
waterfall: [
|
||||||
|
|
|
@ -39,13 +39,13 @@
|
||||||
import { GBLog, GBMinInstance, IGBDialog } from 'botlib';
|
import { GBLog, GBMinInstance, IGBDialog } from 'botlib';
|
||||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
||||||
import { Messages } from '../strings.js';
|
import { Messages } from '../strings.js';
|
||||||
import * as phone from 'google-libphonenumber';
|
import * as phone from 'google-libphonenumber';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialogs for handling Menu control.
|
* Dialogs for handling Menu control.
|
||||||
*/
|
*/
|
||||||
export class ProfileDialog extends IGBDialog {
|
export class ProfileDialog extends IGBDialog {
|
||||||
public static getNameDialog (min: GBMinInstance) {
|
public static getNameDialog(min: GBMinInstance) {
|
||||||
return {
|
return {
|
||||||
id: '/profile_name',
|
id: '/profile_name',
|
||||||
waterfall: [
|
waterfall: [
|
||||||
|
@ -83,7 +83,7 @@ export class ProfileDialog extends IGBDialog {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getMobileDialog (min: GBMinInstance) {
|
public static getMobileDialog(min: GBMinInstance) {
|
||||||
return {
|
return {
|
||||||
id: '/profile_mobile',
|
id: '/profile_mobile',
|
||||||
waterfall: [
|
waterfall: [
|
||||||
|
@ -126,7 +126,7 @@ export class ProfileDialog extends IGBDialog {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getMobileConfirmDialog (min: GBMinInstance) {
|
public static getMobileConfirmDialog(min: GBMinInstance) {
|
||||||
return {
|
return {
|
||||||
id: '/profile_mobile_confirm',
|
id: '/profile_mobile_confirm',
|
||||||
waterfall: [
|
waterfall: [
|
||||||
|
@ -167,7 +167,7 @@ export class ProfileDialog extends IGBDialog {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getEmailDialog (min: GBMinInstance) {
|
public static getEmailDialog(min: GBMinInstance) {
|
||||||
return {
|
return {
|
||||||
id: '/profile_email',
|
id: '/profile_email',
|
||||||
waterfall: [
|
waterfall: [
|
||||||
|
|
|
@ -47,7 +47,7 @@ import { GuaribasGroup, GuaribasUser, GuaribasUserGroup } from './models/index.j
|
||||||
*/
|
*/
|
||||||
export class GBSecurityPackage implements IGBPackage {
|
export class GBSecurityPackage implements IGBPackage {
|
||||||
public sysPackages: IGBPackage[];
|
public sysPackages: IGBPackage[];
|
||||||
public async getDialogs (min: GBMinInstance) {
|
public async getDialogs(min: GBMinInstance) {
|
||||||
const out = [
|
const out = [
|
||||||
ProfileDialog.getNameDialog(min),
|
ProfileDialog.getNameDialog(min),
|
||||||
ProfileDialog.getEmailDialog(min),
|
ProfileDialog.getEmailDialog(min),
|
||||||
|
@ -60,23 +60,23 @@ export class GBSecurityPackage implements IGBPackage {
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
public async unloadPackage (core: IGBCoreService): Promise<void> {
|
public async unloadPackage(core: IGBCoreService): Promise<void> {
|
||||||
GBLog.verbose(`unloadPackage called.`);
|
GBLog.verbose(`unloadPackage called.`);
|
||||||
}
|
}
|
||||||
public async loadBot (min: GBMinInstance): Promise<void> {
|
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||||
GBLog.verbose(`loadBot called.`);
|
GBLog.verbose(`loadBot called.`);
|
||||||
}
|
}
|
||||||
public async unloadBot (min: GBMinInstance): Promise<void> {
|
public async unloadBot(min: GBMinInstance): Promise<void> {
|
||||||
GBLog.verbose(`unloadBot called.`);
|
GBLog.verbose(`unloadBot called.`);
|
||||||
}
|
}
|
||||||
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||||
GBLog.verbose(`onNewSession called.`);
|
GBLog.verbose(`onNewSession called.`);
|
||||||
}
|
}
|
||||||
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
|
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||||
GBLog.verbose(`onExchangeData called.`);
|
GBLog.verbose(`onExchangeData called.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||||
core.sequelize.addModels([GuaribasGroup, GuaribasUser, GuaribasUserGroup]);
|
core.sequelize.addModels([GuaribasGroup, GuaribasUser, GuaribasUserGroup]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ export class GuaribasUser extends Model<GuaribasUser> {
|
||||||
|
|
||||||
@Column(DataType.STRING(255))
|
@Column(DataType.STRING(255))
|
||||||
declare userSystemId: string;
|
declare userSystemId: string;
|
||||||
|
|
||||||
@Column(DataType.STRING(255))
|
@Column(DataType.STRING(255))
|
||||||
declare userName: string;
|
declare userName: string;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { FindOptions } from 'sequelize';
|
||||||
* Security service layer.
|
* Security service layer.
|
||||||
*/
|
*/
|
||||||
export class SecService extends GBService {
|
export class SecService extends GBService {
|
||||||
public async ensureUser (
|
public async ensureUser(
|
||||||
instanceId: number,
|
instanceId: number,
|
||||||
userSystemId: string,
|
userSystemId: string,
|
||||||
userName: string,
|
userName: string,
|
||||||
|
@ -41,7 +41,7 @@ export class SecService extends GBService {
|
||||||
/**
|
/**
|
||||||
* Retrives a conversation reference from contact phone.
|
* Retrives a conversation reference from contact phone.
|
||||||
*/
|
*/
|
||||||
public async getConversationReference (phone: string): Promise<ConversationReference> {
|
public async getConversationReference(phone: string): Promise<ConversationReference> {
|
||||||
const options = <FindOptions>{ rejectOnEmpty: true, where: { phone: phone } };
|
const options = <FindOptions>{ rejectOnEmpty: true, where: { phone: phone } };
|
||||||
const user = await GuaribasUser.findOne(options);
|
const user = await GuaribasUser.findOne(options);
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ export class SecService extends GBService {
|
||||||
/**
|
/**
|
||||||
* Updates a conversation reference from contact phone.
|
* Updates a conversation reference from contact phone.
|
||||||
*/
|
*/
|
||||||
public async updateConversationReference (phone: string, conversationReference: string) {
|
public async updateConversationReference(phone: string, conversationReference: string) {
|
||||||
const options = <FindOptions>{ where: { phone: phone } };
|
const options = <FindOptions>{ where: { phone: phone } };
|
||||||
const user = await GuaribasUser.findOne(options);
|
const user = await GuaribasUser.findOne(options);
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ export class SecService extends GBService {
|
||||||
await user.save();
|
await user.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateConversationReferenceById (userId: number, conversationReference: string) {
|
public async updateConversationReferenceById(userId: number, conversationReference: string) {
|
||||||
const options = <FindOptions>{ where: { userId: userId } };
|
const options = <FindOptions>{ where: { userId: userId } };
|
||||||
const user = await GuaribasUser.findOne(options);
|
const user = await GuaribasUser.findOne(options);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ export class SecService extends GBService {
|
||||||
await user.save();
|
await user.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateUserLocale (userId: number, locale: any): Promise<GuaribasUser> {
|
public async updateUserLocale(userId: number, locale: any): Promise<GuaribasUser> {
|
||||||
const user = await GuaribasUser.findOne({
|
const user = await GuaribasUser.findOne({
|
||||||
where: {
|
where: {
|
||||||
userId: userId
|
userId: userId
|
||||||
|
@ -78,7 +78,7 @@ export class SecService extends GBService {
|
||||||
return await user.save();
|
return await user.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateUserHearOnDialog (userId: number, dialogName: string): Promise<GuaribasUser> {
|
public async updateUserHearOnDialog(userId: number, dialogName: string): Promise<GuaribasUser> {
|
||||||
const user = await GuaribasUser.findOne({
|
const user = await GuaribasUser.findOne({
|
||||||
where: {
|
where: {
|
||||||
userId: userId
|
userId: userId
|
||||||
|
@ -89,7 +89,7 @@ export class SecService extends GBService {
|
||||||
return await user.save();
|
return await user.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateUserInstance (userSystemId: string, instanceId: number): Promise<GuaribasUser> {
|
public async updateUserInstance(userSystemId: string, instanceId: number): Promise<GuaribasUser> {
|
||||||
const user = await GuaribasUser.findOne({
|
const user = await GuaribasUser.findOne({
|
||||||
where: {
|
where: {
|
||||||
userSystemId: userSystemId
|
userSystemId: userSystemId
|
||||||
|
@ -103,7 +103,7 @@ export class SecService extends GBService {
|
||||||
/**
|
/**
|
||||||
* Finds and update user agent information to a next available person.
|
* Finds and update user agent information to a next available person.
|
||||||
*/
|
*/
|
||||||
public async updateHumanAgent (
|
public async updateHumanAgent(
|
||||||
userSystemId: string,
|
userSystemId: string,
|
||||||
instanceId: number,
|
instanceId: number,
|
||||||
agentSystemId: string
|
agentSystemId: string
|
||||||
|
@ -150,7 +150,7 @@ export class SecService extends GBService {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async isAgentSystemId (systemId: string): Promise<Boolean> {
|
public async isAgentSystemId(systemId: string): Promise<Boolean> {
|
||||||
const user = await GuaribasUser.findOne({
|
const user = await GuaribasUser.findOne({
|
||||||
where: {
|
where: {
|
||||||
userSystemId: systemId
|
userSystemId: systemId
|
||||||
|
@ -164,7 +164,7 @@ export class SecService extends GBService {
|
||||||
return user.agentMode === 'self';
|
return user.agentMode === 'self';
|
||||||
}
|
}
|
||||||
|
|
||||||
public async assignHumanAgent (
|
public async assignHumanAgent(
|
||||||
min: GBMinInstance,
|
min: GBMinInstance,
|
||||||
userSystemId: string,
|
userSystemId: string,
|
||||||
agentSystemId: string = null
|
agentSystemId: string = null
|
||||||
|
@ -194,7 +194,7 @@ export class SecService extends GBService {
|
||||||
return agentSystemId;
|
return agentSystemId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getUserFromId (instanceId: number, userId: string): Promise<GuaribasUser> {
|
public async getUserFromId(instanceId: number, userId: string): Promise<GuaribasUser> {
|
||||||
return await GuaribasUser.findOne({
|
return await GuaribasUser.findOne({
|
||||||
where: {
|
where: {
|
||||||
instanceId: instanceId,
|
instanceId: instanceId,
|
||||||
|
@ -203,7 +203,7 @@ export class SecService extends GBService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getUserFromSystemId (systemId: string): Promise<GuaribasUser> {
|
public async getUserFromSystemId(systemId: string): Promise<GuaribasUser> {
|
||||||
return await GuaribasUser.findOne({
|
return await GuaribasUser.findOne({
|
||||||
where: {
|
where: {
|
||||||
userSystemId: systemId
|
userSystemId: systemId
|
||||||
|
@ -211,7 +211,7 @@ export class SecService extends GBService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getUserFromAgentSystemId (systemId: string): Promise<GuaribasUser> {
|
public async getUserFromAgentSystemId(systemId: string): Promise<GuaribasUser> {
|
||||||
return await GuaribasUser.findOne({
|
return await GuaribasUser.findOne({
|
||||||
where: {
|
where: {
|
||||||
agentSystemId: systemId
|
agentSystemId: systemId
|
||||||
|
@ -219,7 +219,7 @@ export class SecService extends GBService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAllUsers (instanceId: number): Promise<GuaribasUser[]> {
|
public async getAllUsers(instanceId: number): Promise<GuaribasUser[]> {
|
||||||
return await GuaribasUser.findAll({
|
return await GuaribasUser.findAll({
|
||||||
where: {
|
where: {
|
||||||
instanceId: instanceId
|
instanceId: instanceId
|
||||||
|
@ -235,7 +235,7 @@ export class SecService extends GBService {
|
||||||
* @param name Name of param to get from instance.
|
* @param name Name of param to get from instance.
|
||||||
* @param defaultValue Value returned when no param is defined.
|
* @param defaultValue Value returned when no param is defined.
|
||||||
*/
|
*/
|
||||||
public getParam<T> (user: GuaribasUser, name: string, defaultValue?: T): any {
|
public getParam<T>(user: GuaribasUser, name: string, defaultValue?: T): any {
|
||||||
let value = null;
|
let value = null;
|
||||||
if (user.params) {
|
if (user.params) {
|
||||||
const params = JSON.parse(user.params);
|
const params = JSON.parse(user.params);
|
||||||
|
@ -254,8 +254,7 @@ export class SecService extends GBService {
|
||||||
if (user['dataValues'] && !value) {
|
if (user['dataValues'] && !value) {
|
||||||
value = user['dataValues'][name];
|
value = user['dataValues'][name];
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
switch(name)
|
switch (name) {
|
||||||
{
|
|
||||||
case 'language':
|
case 'language':
|
||||||
value = 'en';
|
value = 'en';
|
||||||
break;
|
break;
|
||||||
|
@ -269,14 +268,13 @@ export class SecService extends GBService {
|
||||||
* Saves user instance object to the storage handling
|
* Saves user instance object to the storage handling
|
||||||
* multi-column JSON based store 'params' field.
|
* multi-column JSON based store 'params' field.
|
||||||
*/
|
*/
|
||||||
public async setParam (userId: number, name: string, value:any) {
|
public async setParam(userId: number, name: string, value: any) {
|
||||||
const options = { where: {} };
|
const options = { where: {} };
|
||||||
options.where = { userId: userId };
|
options.where = { userId: userId };
|
||||||
let user = await GuaribasUser.findOne(options);
|
let user = await GuaribasUser.findOne(options);
|
||||||
// tslint:disable-next-line:prefer-object-spread
|
// tslint:disable-next-line:prefer-object-spread
|
||||||
let obj = JSON.parse(user.params);
|
let obj = JSON.parse(user.params);
|
||||||
if (!obj)
|
if (!obj) {
|
||||||
{
|
|
||||||
obj = {};
|
obj = {};
|
||||||
}
|
}
|
||||||
obj[name] = value;
|
obj[name] = value;
|
||||||
|
|
|
@ -44,25 +44,25 @@ import { Sequelize } from 'sequelize-typescript';
|
||||||
*/
|
*/
|
||||||
export class GBSharePointPackage implements IGBPackage {
|
export class GBSharePointPackage implements IGBPackage {
|
||||||
public sysPackages: IGBPackage[];
|
public sysPackages: IGBPackage[];
|
||||||
public async getDialogs (min: GBMinInstance) {
|
public async getDialogs(min: GBMinInstance) {
|
||||||
GBLog.verbose(`getDialogs called.`);
|
GBLog.verbose(`getDialogs called.`);
|
||||||
}
|
}
|
||||||
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||||
GBLog.verbose(`loadPackage called.`);
|
GBLog.verbose(`loadPackage called.`);
|
||||||
}
|
}
|
||||||
public async unloadPackage (core: IGBCoreService): Promise<void> {
|
public async unloadPackage(core: IGBCoreService): Promise<void> {
|
||||||
GBLog.verbose(`unloadPackage called.`);
|
GBLog.verbose(`unloadPackage called.`);
|
||||||
}
|
}
|
||||||
public async loadBot (min: GBMinInstance): Promise<void> {
|
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||||
GBLog.verbose(`loadBot called.`);
|
GBLog.verbose(`loadBot called.`);
|
||||||
}
|
}
|
||||||
public async unloadBot (min: GBMinInstance): Promise<void> {
|
public async unloadBot(min: GBMinInstance): Promise<void> {
|
||||||
GBLog.verbose(`unloadBot called.`);
|
GBLog.verbose(`unloadBot called.`);
|
||||||
}
|
}
|
||||||
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||||
GBLog.verbose(`onNewSession called.`);
|
GBLog.verbose(`onNewSession called.`);
|
||||||
}
|
}
|
||||||
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
|
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||||
GBLog.verbose(`onExchangeData called.`);
|
GBLog.verbose(`onExchangeData called.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,4 @@
|
||||||
/**
|
/**
|
||||||
* Service facade for SharePoint Online.
|
* Service facade for SharePoint Online.
|
||||||
*/
|
*/
|
||||||
export class GBSharePointService {}
|
export class GBSharePointService { }
|
||||||
|
|
|
@ -38,7 +38,7 @@ import AdmZip from 'adm-zip';
|
||||||
* Support for Whatsapp.
|
* Support for Whatsapp.
|
||||||
*/
|
*/
|
||||||
export class TeamsService extends GBService {
|
export class TeamsService extends GBService {
|
||||||
public async getAppFile (manifest) {
|
public async getAppFile(manifest) {
|
||||||
var zip = new AdmZip();
|
var zip = new AdmZip();
|
||||||
zip.addFile('manifest.json', Buffer.from(manifest, 'utf8'), 'Built with General Bots™.');
|
zip.addFile('manifest.json', Buffer.from(manifest, 'utf8'), 'Built with General Bots™.');
|
||||||
zip.addLocalFile('teams-color.png', null, 'color.png');
|
zip.addLocalFile('teams-color.png', null, 'color.png');
|
||||||
|
@ -46,7 +46,7 @@ export class TeamsService extends GBService {
|
||||||
return zip.toBuffer();
|
return zip.toBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getManifest (marketplaceId, botName, botDescription, id, packageName, yourName) {
|
public async getManifest(marketplaceId, botName, botDescription, id, packageName, yourName) {
|
||||||
let content = Fs.readFileSync('teams-manifest.json', 'utf8');
|
let content = Fs.readFileSync('teams-manifest.json', 'utf8');
|
||||||
|
|
||||||
content = content.replace(/\@\@marketplaceId/gi, marketplaceId);
|
content = content.replace(/\@\@marketplaceId/gi, marketplaceId);
|
||||||
|
|
|
@ -46,26 +46,26 @@ import { WhatsappDirectLine } from './services/WhatsappDirectLine.js';
|
||||||
export class GBWhatsappPackage implements IGBPackage {
|
export class GBWhatsappPackage implements IGBPackage {
|
||||||
public sysPackages: IGBPackage[];
|
public sysPackages: IGBPackage[];
|
||||||
|
|
||||||
public async loadBot (min: GBMinInstance): Promise<void> {
|
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||||
GBLog.verbose(`loadBot called.`);
|
GBLog.verbose(`loadBot called.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDialogs (min: GBMinInstance) {
|
public async getDialogs(min: GBMinInstance) {
|
||||||
GBLog.verbose(`getDialogs called.`);
|
GBLog.verbose(`getDialogs called.`);
|
||||||
}
|
}
|
||||||
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||||
GBLog.verbose(`loadPackage called.`);
|
GBLog.verbose(`loadPackage called.`);
|
||||||
}
|
}
|
||||||
public async unloadPackage (core: IGBCoreService): Promise<void> {
|
public async unloadPackage(core: IGBCoreService): Promise<void> {
|
||||||
GBLog.verbose(`unloadPackage called.`);
|
GBLog.verbose(`unloadPackage called.`);
|
||||||
}
|
}
|
||||||
public async unloadBot (min: GBMinInstance): Promise<void> {
|
public async unloadBot(min: GBMinInstance): Promise<void> {
|
||||||
GBLog.verbose(`unloadBot called.`);
|
GBLog.verbose(`unloadBot called.`);
|
||||||
}
|
}
|
||||||
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||||
GBLog.verbose(`onNewSession called.`);
|
GBLog.verbose(`onNewSession called.`);
|
||||||
}
|
}
|
||||||
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
|
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||||
GBLog.verbose(`onExchangeData called.`);
|
GBLog.verbose(`onExchangeData called.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,11 +192,10 @@ export class WhatsappDirectLine extends GBService {
|
||||||
});
|
});
|
||||||
client.initialize();
|
client.initialize();
|
||||||
};
|
};
|
||||||
if (setUrl){
|
if (setUrl) {
|
||||||
createClient.bind(this)();
|
createClient.bind(this)();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
this.customClient = minBoot.whatsAppDirectLine.customClient;
|
this.customClient = minBoot.whatsAppDirectLine.customClient;
|
||||||
}
|
}
|
||||||
setUrl = false;
|
setUrl = false;
|
||||||
|
@ -998,14 +997,14 @@ export class WhatsappDirectLine extends GBService {
|
||||||
let urlMin: any = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
let urlMin: any = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||||
|
|
||||||
const botNumber = urlMin ? urlMin.core.getParam(urlMin.instance, 'Bot Number', null) : null;
|
const botNumber = urlMin ? urlMin.core.getParam(urlMin.instance, 'Bot Number', null) : null;
|
||||||
if (botNumber){
|
if (botNumber) {
|
||||||
user = await sec.updateUserInstance(user.userSystemId, urlMin.instance.instanceId);
|
user = await sec.updateUserInstance(user.userSystemId, urlMin.instance.instanceId);
|
||||||
}
|
}
|
||||||
let activeMin;
|
let activeMin;
|
||||||
|
|
||||||
// Processes group behaviour.
|
// Processes group behaviour.
|
||||||
|
|
||||||
text = text.replace(/\@\d+ /gi, '');
|
text = text.replace(/\@\d+ /gi, '');
|
||||||
|
|
||||||
let group;
|
let group;
|
||||||
if (provider === 'chatapi') {
|
if (provider === 'chatapi') {
|
||||||
|
|
65
src/app.ts
65
src/app.ts
|
@ -84,7 +84,7 @@ export class GBServer {
|
||||||
GBLog.error(`Running TEST_SHELL ERROR: ${error}...`);
|
GBLog.error(`Running TEST_SHELL ERROR: ${error}...`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = express();
|
const server = express();
|
||||||
|
|
||||||
GBServer.globals.server = server;
|
GBServer.globals.server = server;
|
||||||
|
@ -227,7 +227,7 @@ export class GBServer {
|
||||||
await GBServer.globals.chatGPT.init();
|
await GBServer.globals.chatGPT.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// let s = new GBVMService();
|
// let s = new GBVMService();
|
||||||
// await s.translateBASIC('work/gptA.vbs', GBServer.globals.minBoot );
|
// await s.translateBASIC('work/gptA.vbs', GBServer.globals.minBoot );
|
||||||
// await s.translateBASIC('work/gptB.vbs', GBServer.globals.minBoot );
|
// await s.translateBASIC('work/gptB.vbs', GBServer.globals.minBoot );
|
||||||
|
@ -282,15 +282,62 @@ export class GBServer {
|
||||||
};
|
};
|
||||||
const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
|
const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
|
||||||
GBServer.globals.httpsServer = httpsServer;
|
GBServer.globals.httpsServer = httpsServer;
|
||||||
if (process.env.CERTIFICATE2_PFX) {
|
|
||||||
const options2 = {
|
for (let i = 2; ; i++) {
|
||||||
passphrase: process.env.CERTIFICATE2_PASSPHRASE,
|
const certPfxEnv = `CERTIFICATE${i}_PFX`;
|
||||||
pfx: Fs.readFileSync(process.env.CERTIFICATE2_PFX)
|
const certPassphraseEnv = `CERTIFICATE${i}_PASSPHRASE`;
|
||||||
};
|
const certDomainEnv = `CERTIFICATE${i}_DOMAIN`;
|
||||||
httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options2);
|
|
||||||
|
if (process.env[certPfxEnv] && process.env[certPassphraseEnv] && process.env[certDomainEnv]) {
|
||||||
|
const options = {
|
||||||
|
passphrase: process.env[certPassphraseEnv],
|
||||||
|
pfx: Fs.readFileSync(process.env[certPfxEnv])
|
||||||
|
};
|
||||||
|
httpsServer.addContext(process.env[certDomainEnv], options);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
server.listen(port, mainCallback);
|
server.listen(port, mainCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
--------------------------------------------------------------------------------------------
|
||||||
|
if (process.env.CERTIFICATE_PFX) {
|
||||||
|
const options1 = {
|
||||||
|
passphrase: process.env.CERTIFICATE_PASSPHRASE,
|
||||||
|
pfx: Fs.readFileSync(process.env.CERTIFICATE_PFX)
|
||||||
|
};
|
||||||
|
const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
|
||||||
|
GBServer.globals.httpsServer = httpsServer;
|
||||||
|
|
||||||
|
if (process.env.CERTIFICATE2_PFX) {
|
||||||
|
const options2 = {
|
||||||
|
passphrase: process.env.CERTIFICATE2_PASSPHRASE,
|
||||||
|
pfx: Fs.readFileSync(process.env.CERTIFICATE2_PFX)
|
||||||
|
};
|
||||||
|
httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.CERTIFICATE3_PFX) {
|
||||||
|
const options3 = {
|
||||||
|
passphrase: process.env.CERTIFICATE3_PASSPHRASE,
|
||||||
|
pfx: Fs.readFileSync(process.env.CERTIFICATE3_PFX)
|
||||||
|
};
|
||||||
|
httpsServer.addContext(process.env.CERTIFICATE3_DOMAIN, options3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.CERTIFICATE4_PFX) {
|
||||||
|
const options4 = {
|
||||||
|
passphrase: process.env.CERTIFICATE4_PASSPHRASE,
|
||||||
|
pfx: Fs.readFileSync(process.env.CERTIFICATE4_PFX)
|
||||||
|
};
|
||||||
|
httpsServer.addContext(process.env.CERTIFICATE4_DOMAIN, options4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue