0.0.1 • Published 5 months ago

bot-runtime-t1 v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

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)
})