@ori-diy/bot-runtimev1
v1.0.0
Published
Runtime environment for Ori chatbots.
Downloads
1
Readme
bot-runtime
TODO: description
How to setup a bot?
//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)
})