new(admin.gbapp): /publish from Web or WhatsApp with associated auth.
This commit is contained in:
parent
a469d6da6a
commit
077d70e418
7 changed files with 119 additions and 56 deletions
|
@ -49,11 +49,17 @@ ALTER TABLE dbo.GuaribasInstance ADD
|
||||||
activationCode nvarchar(16) NULL
|
activationCode nvarchar(16) NULL
|
||||||
GO
|
GO
|
||||||
|
|
||||||
# 1.7.9
|
#
|
||||||
|
|
||||||
ALTER TABLE dbo.GuaribasInstance ADD
|
ALTER TABLE dbo.GuaribasInstance ADD
|
||||||
params nvarchar(4000) NULL
|
params nvarchar(4000) NULL
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
ALTER TABLE dbo.GuaribasInstance ADD
|
||||||
|
state nvarchar(16) NULL
|
||||||
|
GO
|
||||||
|
UPDATE dbo.GuaribasInstance SET state= 'active'
|
||||||
|
|
||||||
```
|
```
|
|
@ -66,7 +66,7 @@
|
||||||
"botbuilder-ai": "4.7.0",
|
"botbuilder-ai": "4.7.0",
|
||||||
"botbuilder-dialogs": "4.7.0",
|
"botbuilder-dialogs": "4.7.0",
|
||||||
"botframework-connector": "4.7.0",
|
"botframework-connector": "4.7.0",
|
||||||
"botlib": "1.5.4",
|
"botlib": "1.5.5",
|
||||||
"cli-spinner": "0.2.10",
|
"cli-spinner": "0.2.10",
|
||||||
"dotenv-extended": "2.7.1",
|
"dotenv-extended": "2.7.1",
|
||||||
"exceljs": "3.5.0",
|
"exceljs": "3.5.0",
|
||||||
|
|
|
@ -76,6 +76,29 @@ export class AdminDialog extends IGBDialog {
|
||||||
|
|
||||||
AdminDialog.setupSecurityDialogs(min);
|
AdminDialog.setupSecurityDialogs(min);
|
||||||
|
|
||||||
|
min.dialogs.add(
|
||||||
|
new WaterfallDialog('/admin-auth', [
|
||||||
|
async step => {
|
||||||
|
const locale = step.context.activity.locale;
|
||||||
|
const prompt = Messages[locale].authenticate;
|
||||||
|
|
||||||
|
return await min.conversationalService.prompt(min, step, prompt);
|
||||||
|
},
|
||||||
|
async step => {
|
||||||
|
const locale = step.context.activity.locale;
|
||||||
|
const sensitive = step.result;
|
||||||
|
|
||||||
|
if (sensitive === process.env.ADMIN_PASS ) { // TODO: Per bot: min.instance.adminPass
|
||||||
|
await min.conversationalService.sendText(min, step, Messages[locale].welcome);
|
||||||
|
|
||||||
|
return await step.endDialog(true);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
await min.conversationalService.sendText(min, step, Messages[locale].wrong_password);
|
||||||
|
return await step.replaceDialog('/admin-auth');
|
||||||
|
}
|
||||||
|
}]));
|
||||||
|
|
||||||
min.dialogs.add(
|
min.dialogs.add(
|
||||||
new WaterfallDialog('/admin', [
|
new WaterfallDialog('/admin', [
|
||||||
async step => {
|
async step => {
|
||||||
|
@ -181,57 +204,69 @@ export class AdminDialog extends IGBDialog {
|
||||||
|
|
||||||
let canPublish = AdminDialog.canPublish(min, from);
|
let canPublish = AdminDialog.canPublish(min, from);
|
||||||
|
|
||||||
if (canPublish) {
|
if (!canPublish) {
|
||||||
|
await step.beginDialog('/admin-auth');
|
||||||
const botId = min.instance.botId;
|
}
|
||||||
const locale = step.context.activity.locale;
|
else {
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].working('Publishing'));
|
step.next(true);
|
||||||
|
|
||||||
step.activeDialog.state.options.args = (step.options as any).args;
|
|
||||||
const filename = step.activeDialog.state.options.args ?
|
|
||||||
step.activeDialog.state.options.args.split(' ')[0] : null;
|
|
||||||
|
|
||||||
const packages = [];
|
|
||||||
if (filename === null || filename === "") {
|
|
||||||
await min.conversationalService.sendText(min, step, `Starting publishing for ${botId}.gbkb...`);
|
|
||||||
packages.push(`${botId}.gbkb`);
|
|
||||||
} else {
|
|
||||||
await min.conversationalService.sendText(min, step, `Starting publishing for ${filename}...`);
|
|
||||||
packages.push(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(packages, async packageName => {
|
|
||||||
|
|
||||||
const cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`;
|
|
||||||
|
|
||||||
if (await (deployer as any).getStoragePackageByName(min.instance.instanceId,
|
|
||||||
packageName) !== null) {
|
|
||||||
const cmd2 = `undeployPackage ${packageName}`;
|
|
||||||
await GBAdminService.undeployPackageCommand(cmd2, min);
|
|
||||||
}
|
|
||||||
await GBAdminService.deployPackageCommand(min, cmd1, deployer);
|
|
||||||
await min.conversationalService.sendText(min, step, `Finished publishing ${packageName}.`);
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
await min.conversationalService.sendText(min, step, `ERROR: ${error}`);
|
|
||||||
GBLog.error(error);
|
|
||||||
return await step.replaceDialog('/ask', { isReturning: true });
|
|
||||||
}
|
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].publish_success);
|
|
||||||
if (!step.activeDialog.state.options.confirm) {
|
|
||||||
return await step.replaceDialog('/ask', { isReturning: true });
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return await step.endDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].publish_must_be_admin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].publish_canceled);
|
else {
|
||||||
|
await min.conversationalService.sendText(min, step, Messages[locale].publish_canceled);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async step => {
|
||||||
|
const locale = step.context.activity.locale;
|
||||||
|
if (!step.result) {
|
||||||
|
await min.conversationalService.sendText(min, step, Messages[locale].publish_must_be_admin);
|
||||||
|
|
||||||
|
return step.endDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
const botId = min.instance.botId;
|
||||||
|
|
||||||
|
await min.conversationalService.sendText(min, step, Messages[locale].working('Publishing'));
|
||||||
|
|
||||||
|
step.activeDialog.state.options.args = (step.options as any).args;
|
||||||
|
const filename = step.activeDialog.state.options.args ?
|
||||||
|
step.activeDialog.state.options.args.split(' ')[0] : null;
|
||||||
|
|
||||||
|
const packages = [];
|
||||||
|
if (filename === null || filename === "") {
|
||||||
|
await min.conversationalService.sendText(min, step, `Starting publishing for ${botId}.gbkb...`);
|
||||||
|
packages.push(`${botId}.gbkb`);
|
||||||
|
} else {
|
||||||
|
await min.conversationalService.sendText(min, step, `Starting publishing for ${filename}...`);
|
||||||
|
packages.push(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
await CollectionUtil.asyncForEach(packages, async packageName => {
|
||||||
|
|
||||||
|
const cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`;
|
||||||
|
|
||||||
|
if (await (deployer as any).getStoragePackageByName(min.instance.instanceId,
|
||||||
|
packageName) !== null) {
|
||||||
|
const cmd2 = `undeployPackage ${packageName}`;
|
||||||
|
await GBAdminService.undeployPackageCommand(cmd2, min);
|
||||||
|
}
|
||||||
|
await GBAdminService.deployPackageCommand(min, cmd1, deployer);
|
||||||
|
await min.conversationalService.sendText(min, step, `Finished publishing ${packageName}.`);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
await min.conversationalService.sendText(min, step, `ERROR: ${error}`);
|
||||||
|
GBLog.error(error);
|
||||||
|
return await step.replaceDialog('/ask', { isReturning: true });
|
||||||
|
}
|
||||||
|
await min.conversationalService.sendText(min, step, Messages[locale].publish_success);
|
||||||
|
if (!step.activeDialog.state.options.confirm) {
|
||||||
|
return await step.replaceDialog('/ask', { isReturning: true });
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return await step.endDialog();
|
||||||
|
}
|
||||||
|
|
||||||
}]));
|
}]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,9 @@ export class GuaribasInstance extends Model<GuaribasInstance>
|
||||||
@Column
|
@Column
|
||||||
public description: string;
|
public description: string;
|
||||||
|
|
||||||
|
@Column({ type: DataType.STRING(16) })
|
||||||
|
public state: string;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
public version: string;
|
public version: string;
|
||||||
|
|
||||||
|
|
|
@ -525,10 +525,15 @@ export class GBConversationalService {
|
||||||
language: string
|
language: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
|
||||||
if (process.env.TRANSLATOR_DISABLED === "true"){
|
if (process.env.TRANSLATOR_DISABLED === "true"){
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (text.length > 5000){
|
||||||
|
text = text.substr(0,4999);
|
||||||
|
GBLog.warn(`Text that bot will translate will be truncated due to MSFT service limitations.`);
|
||||||
|
}
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
baseUrl: endPoint,
|
baseUrl: endPoint,
|
||||||
|
|
|
@ -215,7 +215,8 @@ export class GBCoreService implements IGBCoreService {
|
||||||
return GuaribasInstance.findAll(options);
|
return GuaribasInstance.findAll(options);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return GuaribasInstance.findAll({});
|
const options = { where: { state: 'active' } };
|
||||||
|
return GuaribasInstance.findAll(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,17 +224,25 @@ export class GBCoreService implements IGBCoreService {
|
||||||
* Loads just one Bot instance by its internal Id.
|
* Loads just one Bot instance by its internal Id.
|
||||||
*/
|
*/
|
||||||
public async loadInstanceById(instanceId: number): Promise<IGBInstance> {
|
public async loadInstanceById(instanceId: number): Promise<IGBInstance> {
|
||||||
const options = { where: { instanceId: instanceId } };
|
const options = { where: { instanceId: instanceId, state: 'active' } };
|
||||||
|
|
||||||
return GuaribasInstance.findOne(options);
|
return GuaribasInstance.findOne(options);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Loads just one Bot instance.
|
||||||
|
*/
|
||||||
|
public async loadInstanceByActivationCode(code: string): Promise<IGBInstance> {
|
||||||
|
|
||||||
|
let options = { where: { activationCode: code, state: 'active' } };
|
||||||
|
|
||||||
|
return await GuaribasInstance.findOne(options);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Loads just one Bot instance.
|
* Loads just one Bot instance.
|
||||||
*/
|
*/
|
||||||
public async loadInstanceByBotId(botId: string): Promise<IGBInstance> {
|
public async loadInstanceByBotId(botId: string): Promise<IGBInstance> {
|
||||||
const options = { where: {} };
|
const options = { where: {} };
|
||||||
options.where = { botId: botId };
|
options.where = { botId: botId, state: 'active' };
|
||||||
|
|
||||||
return await GuaribasInstance.findOne(options);
|
return await GuaribasInstance.findOne(options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -343,7 +343,12 @@ export class GBMinService {
|
||||||
if (botId === '[default]' || botId === undefined) {
|
if (botId === '[default]' || botId === undefined) {
|
||||||
botId = GBConfigService.get('BOT_ID');
|
botId = GBConfigService.get('BOT_ID');
|
||||||
}
|
}
|
||||||
const instance = await this.core.loadInstanceByBotId(botId);
|
let instance = await this.core.loadInstanceByBotId(botId);
|
||||||
|
|
||||||
|
if (instance === null){
|
||||||
|
instance = await this.core.loadInstanceByActivationCode(botId);
|
||||||
|
}
|
||||||
|
|
||||||
if (instance !== null) {
|
if (instance !== null) {
|
||||||
const webchatTokenContainer = await this.getWebchatToken(instance);
|
const webchatTokenContainer = await this.getWebchatToken(instance);
|
||||||
const speechToken = instance.speechKey != null ? await this.getSTSToken(instance) : null;
|
const speechToken = instance.speechKey != null ? await this.getSTSToken(instance) : null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue