botpress
Version:
The world's first CMS for bots. Easily create, manage and extend chatbots.
73 lines (58 loc) • 2.18 kB
JavaScript
const {
contentElements,
contentRenderers,
actions: builtinActions,
setup: setupBuiltins
} = require('@botpress/builtins')
const registerCustom = require('./custom')
module.exports = async bp => {
// This bot template includes a couple of built-in elements and actions
// Please see the "@botpress/builtins" package to know more
await registerBuiltin(bp)
// Register custom actions, elements and renderers
await registerCustom(bp)
// Train the NLU model if using the Native NLU Engine
if (bp.nlu && bp.nlu.provider && bp.nlu.provider.name === 'native') {
await bp.nlu.provider.sync()
}
const webchat = {
botName: 'Basic',
botAvatarUrl: null, // You can provide a URL here
botConvoTitle: 'Botpress Basic Webchat Bot',
botConvoDescription: "Hello, I'm a Botpress bot!",
backgroundColor: '#ffffff',
textColorOnBackground: '#666666',
foregroundColor: '#000000',
textColorOnForeground: '#ffffff'
}
bp.createShortlink('chat', '/lite', {
m: 'channel-web',
v: 'fullscreen',
options: JSON.stringify({ config: webchat })
})
bp.logger.info(`------------`)
bp.logger.info(`Webchat available at ${bp.botfile.botUrl}/s/chat`)
bp.logger.info(`------------`)
////////////////////////////
/// Conversation Management
////////////////////////////
// All events that should be processed by the Flow Manager
bp.hear({ type: /bp_dialog_timeout|text|message|quick_reply/i }, (event, next) => {
bp.dialogEngine.processMessage(event.sessionId || event.user.id, event).then()
})
}
async function registerBuiltin(bp) {
await setupBuiltins(bp)
// Register all the built-in content elements
// Such as Carousel, Text, Choice etc..
for (const schema of Object.values(contentElements)) {
await bp.contentManager.loadCategoryFromSchema(schema)
}
await bp.contentManager.recomputeCategoriesMetadata()
// Register all the renderers for the built-in elements
for (const renderer of Object.keys(contentRenderers)) {
bp.renderers.register(renderer, contentRenderers[renderer])
}
// Register all the built-in actions
bp.dialogEngine.registerActions(builtinActions)
}