Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from botpress/rl_create_bot_v2
feat(core): Add bot creation ui and default template
- Loading branch information
Showing
22 changed files
with
504 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { BotConfig } from './bot.config' | ||
|
||
export class BotConfigBuilder { | ||
private schema = '../../bot.config.schema.json' | ||
private active = false | ||
private version = '0.0.1' | ||
private license: string | undefined | ||
private author: string | undefined | ||
private contentTypes: string[] = [] | ||
private modules: string[] = [] | ||
private outgoingMiddleware: string[] = [] | ||
private incomingMiddleware: string[] = [] | ||
|
||
constructor(private name: string, private id: string, private description: string) {} | ||
|
||
withlicense(license: string): this { | ||
this.license = license | ||
return this | ||
} | ||
|
||
withAuthor(author: string): this { | ||
this.author = author | ||
return this | ||
} | ||
|
||
withContentTypes(...contentTypes: string[]): this { | ||
this.contentTypes = contentTypes | ||
return this | ||
} | ||
|
||
withModules(...modules: string[]): this { | ||
this.modules = modules | ||
return this | ||
} | ||
|
||
withVersion(version: string): this { | ||
this.version = version | ||
return this | ||
} | ||
|
||
withIncomingMiddleware(...incoming: string[]) { | ||
this.incomingMiddleware = incoming | ||
return this | ||
} | ||
|
||
withOugoingMiddleware(...outgoing: string[]) { | ||
this.outgoingMiddleware = outgoing | ||
return this | ||
} | ||
|
||
enabled(active: boolean): this { | ||
this.active = active | ||
return this | ||
} | ||
|
||
build(): BotConfig { | ||
return { | ||
$schema: this.schema, | ||
active: this.active, | ||
id: this.id, | ||
name: this.name, | ||
description: this.description, | ||
version: this.version, | ||
license: this.license, | ||
author: this.author, | ||
imports: { | ||
modules: this.modules, | ||
contentTypes: this.contentTypes, | ||
incomingMiddleware: this.incomingMiddleware, | ||
outgoingMiddleware: this.outgoingMiddleware | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { injectable } from 'inversify' | ||
import { BotConfig } from './bot.config' | ||
import { BotConfigBuilder } from '.' | ||
|
||
export type DefaultArguments = { | ||
id: string | ||
name: string | ||
description: string | ||
} | ||
|
||
@injectable() | ||
export class BotConfigFactory { | ||
createDefault(args: DefaultArguments): BotConfig { | ||
const builder = new BotConfigBuilder(args.name, args.id, args.description) | ||
|
||
builder.withModules('channel-web') | ||
builder.withContentTypes( | ||
'builtin_text', | ||
'builtin_single-choice', | ||
'builtin_image', | ||
'builtin_carousel', | ||
'builtin_card' | ||
) | ||
builder.withOugoingMiddleware('web.sendMessages') | ||
builder.enabled(true) | ||
|
||
return builder.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import fse from 'fs-extra' | ||
import path from 'path' | ||
import { VError } from 'verror' | ||
import { BotConfig } from './bot.config' | ||
import { injectable } from 'inversify' | ||
|
||
@injectable() | ||
export class BotConfigWriter { | ||
async writeToFile(config: BotConfig) { | ||
const filePath = path.join(process.cwd(), `./data/bots/${config.id}/`) | ||
const templatePath = path.join(process.cwd(), '../templates') | ||
const fileName = 'bot.config.json' | ||
|
||
try { | ||
await fse.ensureDir(filePath) | ||
await fse.copySync(templatePath, filePath) | ||
await fse.writeFile(filePath + fileName, JSON.stringify(config, undefined, 2)) | ||
} catch (e) { | ||
throw new VError(e, `Error writing file "${filePath}"`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './config-builder' | ||
export * from './config-factory' | ||
export * from './config-writer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1 @@ | ||
# See https://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
**/node_modules | ||
|
||
# testing | ||
**/coverage | ||
|
||
# production | ||
**/build | ||
|
||
# misc | ||
**/.DS_Store | ||
**/.env.local | ||
**/.env.development.local | ||
**/.env.test.local | ||
**/.env.production.local | ||
|
||
**/npm-debug.log* | ||
**/yarn-debug.log* | ||
**/yarn-error.log* | ||
|
||
back/dist | ||
back/static | ||
|
||
front/**/*.css | ||
/build |
Empty file.
Oops, something went wrong.