Runtime environment for Ori chatbots.
npm install @oriserve01/bot-runtimebot-runtime> TODO: description
``javascript
//Pull the configuration, which can reside anywhere like db storage, or flat file.
const workflows_docs = await WorkflowViewModel.find({ active: true }).exec()
//convert the configuration to dialog
const workflow_dialogs = workflows_docs.map(workflow => new WorkflowDialog(workflow.wid, workflow.scripts()))
// Define a storage adapter
const memoryStorage = new MongoStorage({
uri: ${process.env.MONGO_URI}
})
const mainDialog = new OnIntentDialog('default', workflow_dialogs[0])
const bot = new OriBot(mainDialog, memoryStorage)
//Define an channel adapter
const botAdapter = new WebSocketAdapter()
//Define socket handlers
socket.on('new_message', (data, callback) => {
botAdapter.processSocketEvent(socket, 'new_message', data, (context) => bot.run(context))
callback(false)
})
socket.on('buttonSelection', (data, callback) => {
botAdapter.processSocketEvent(socket, 'buttonSelection', data, (context) => bot.run(context))
callback(false)
})
``