Skip to content

Commit

Permalink
fix(admin): import bot in the current workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
allardy committed Dec 5, 2019
1 parent 2a8a5f3 commit 876329c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/bp/core/routers/admin/bots.ts
Expand Up @@ -203,7 +203,7 @@ export class BotsRouter extends CustomRouter {
req.on('data', chunk => buffers.push(chunk))
await Promise.fromCallback(cb => req.on('end', cb))

await this.botService.importBot(req.params.botId, Buffer.concat(buffers), false)
await this.botService.importBot(req.params.botId, Buffer.concat(buffers), req.workspace!, false)
res.sendStatus(200)
})
)
Expand Down
3 changes: 1 addition & 2 deletions src/bp/core/services/bot-service.ts
Expand Up @@ -214,7 +214,7 @@ export class BotService {
return this.ghostService.forBot(botId).exportToArchiveBuffer('models/**/*', replaceContent)
}

async importBot(botId: string, archive: Buffer, allowOverwrite?: boolean): Promise<void> {
async importBot(botId: string, archive: Buffer, workspaceId: string, allowOverwrite?: boolean): Promise<void> {
if (!isValidBotId(botId)) {
throw new InvalidOperationError(`Can't import bot; the bot ID contains invalid characters`)
}
Expand Down Expand Up @@ -242,7 +242,6 @@ export class BotService {
await this.hookService.executeHook(new Hooks.BeforeBotImport(api, botId, tmpFolder, hookResult))

if (hookResult.allowImport) {
const workspaceId = await this.workspaceService.getBotWorkspaceId(botId)
const pipeline = await this.workspaceService.getPipeline(workspaceId)

await replace({
Expand Down
12 changes: 9 additions & 3 deletions src/bp/sdk/botpress.d.ts
Expand Up @@ -256,8 +256,8 @@ declare module 'botpress/sdk' {
}

export interface ModelConstructor {
new(): Model
new(lazy: boolean, keepInMemory: boolean, queryOnly: boolean): Model
new (): Model
new (lazy: boolean, keepInMemory: boolean, queryOnly: boolean): Model
}

export const Model: ModelConstructor
Expand Down Expand Up @@ -1597,9 +1597,15 @@ declare module 'botpress/sdk' {
* Allows to import directly an archive (tar.gz) in a new bot.
* @param botId The ID of the new bot (or an existing one)
* @param archive The buffer of the archive file
* @param workspaceId The workspace where the bot will be imported
* @param allowOverwrite? If not set, it will throw an error if the folder exists. Otherwise, it will overwrite files already present
*/
export function importBot(botId: string, archive: Buffer, allowOverwrite?: boolean): Promise<void>
export function importBot(
botId: string,
archive: Buffer,
workspaceId: string,
allowOverwrite?: boolean
): Promise<void>
}

export namespace workspaces {
Expand Down

0 comments on commit 876329c

Please sign in to comment.