Closed stillefront closed 6 years ago
Sounds like an interesting project.
There is no reason why you couldn't use another botmaster object after the first one. However, based on the fact that you are calling it a middleware object, I'm not sure that that is necessarily what you would like to do. You can chain middleware by using botmaster.use
in a chain as described in the Middleware documentation: http://botmasterai.com/documentation/latest/working-with-botmaster/middleware.html.
The bot
parameter is passed on via the middleware object itself. See __runIncomingMiddleware
and __runOutgoingMiddleware
in: https://github.com/botmasterai/botmaster/blob/master/lib/middleware.js for more details and then note that, say, for incoming middleware, __runIncomingMiddleware
is called by BaseBot. __emitUpdate
. Understanding that is not really relevant to solving your problem though. You are free to have a more thorough read through it if you want.
You can't get the controller to use another bot
parameter. As this parameter is here to tell you which bot actually got the request associated with the update. You can however, find other bot
objects within your controller and use them. Something like this would do:
const Botmaster = require('botmaster');
const SocketioBot = require('botmaster-socket.io');
const botmaster = new Botmaster();
const socketioBot1 = new SocketioBot({
id: 'SOME_BOT_ID_OF_YOUR_CHOOSING',
server: botmaster.server, // this is required for socket.io. You can set it to another node server object if you wish to. But in this example, we will use the one created by botmaster under the hood
});
botmaster.addBot(socketioBot1);
const socketioBot2 = new SocketioBot({
id: 'SOME_OTHER_BOT_ID_OF_YOUR_CHOOSING',
server: botmaster.server,
});
botmaster.addBot(socketioBot2);
const socketioBot3 = new SocketioBot({
id: 'YET_SOME_OTHER_BOT_ID_OF_YOUR_CHOOSING',
server: botmaster.server,
});
botmaster.addBot(socketioBot3);
botmaster.use({
type: 'incoming',
name: 'my-middleware',
controller: (bot, update) => {
// in this example, bot is here: socketioBot1
// however, I want to send a response to all the other bots,
// so I find them
const otherBots = botmaster.bots.filter(otherBot => otherBot.id !== bot.id)
for (const otherBot of Bots) {
otherBot.sendTextMessageTo('Hello world!', 'SOME_RECIPIENT_ID');
}
}
});
Now, figuring out who to send the message to within the bot might be the tricky part here. However, I doubt that's how you would end up solving this problem. What you really want is quite simply multiple Watson Conversations communicating with one another via socket.io.
I am assuming that the use of socket.io is in order to add some visual aspect to the project
when a frontend receives a message. Because of that. I have to conclude that botmaster is not the correct tool for solving this problem. As mentioned in the documentation here: http://botmasterai.com/documentation/latest/
Its philosophy is to minimize the amount of code developers have to write in order to create 1-on-1 conversational chatbots that work on multiple platforms. It does so by defining a standard with respect to what format messages take and how 1-on-1 conversations occur. Messages to/from the various messaging channels supported are all mapped onto this botmaster standard, meaning the code you write is much reduced when compared to a set of point:point integrations.
To better answer you, I would specify here: `1-on-1 conversational chatbots that manages conversations between a human and a bot. It was not designed to handle automated conversations amongst chatbots themselves.
The best way to do this from the tools you have at hand would be plain socket.io
and Watson Conversation using the nodejs API or straight up REST calls. You will want to have a socket.io server to which clients connect.
Each client would be backed by its own instance of Watson Conversation (backed by its own Workspace) and messages would flow from the clients to the server that would have the role of dispatching incoming messages to all the other clients in the room.
For an example of how I use socket.io
rooms in botmaster-socket.io
, see the __setupSocketioServer
here:
https://github.com/botmasterai/botmaster-socket.io/blob/master/lib/socket.io_bot.js
In this use case, I am using a room in quite a different way than you would. For me, a room meant to be composed of the same person potentially logged in via different devices. But I want to make sure that all devices get the updates. You will want to do something similar (as you want everyone to see all messages). However, on the client side, you will want to filter so that only the Watson Conversation instance that are pertinent to a certain message answer.
Hope that helped somewhat. Can't really help more as this is outside the scope of Botmaster. I will therefore now close this issue.
Currently I'm working on a platform for a project at university. I want to experiment with multiple chatbots talking to each other in a single chatroom. It has no deeper practical application besides being somewhat of an art project where students are designing bot personas who will then "date" each other on a fictional platform.
My bots are made with IBM Watson and I'm using botmaster with sessionware and the watson middleware with a configuration based on socket.io. I'm able to connect to one single bot at a time but can't get multiple bots into one session / socket room. There is no information on this issue in the botmaster documentation and I'm struggling with the following part:
0: botmaster.use({
1: type: 'incoming',
2: name: 'my-awesome-middleware',
3: controller: (bot, update, next) => {
4: // watsonUpdate.output.text is an array as watson can reply with a few
5: // messages one after another
6: return bot.sendTextCascadeTo(update.watsonUpdate.output.text,update.sender.id);
7: }
8: });
Line 0: why can't I use a second middleware object named "botmaster2" in parallel or after the "botmaster" object? Line 3: how is the parameter 'bot' transferred to the middleware (I can only trace 'update')?
How can I tell the controller to use some other "bot" parameter or, the other way around: how to identify which bot is actually used through the middleware? It all seems pretty much abbreviated and straightforward for one use case, but hides the features and information to solve my particular problem.