I have a socket (web) bot and need to trigger message to user from event coming from backend system. I read somewhere that this can be done by spawning bot and then invoking Bot.say to initiate message to user. I'm tried this but no luck. It seems when I spawn the bot it does not have reference to the web socket and connection so unable to send message. It appears the ws is only accessible from incoming ingest message?
I'm very interested in allowing backend to push events to user.. This could be bot message or "non-message" based events. Some examples..
Backend defines session expire and on expire an event fires which instructs bot to ping customer to say something like.. "I'm still here if you need help. What can I help you with?"
Bot transfers conversation to human and now user is in queue waiting for human agent.. an event fires which sends message to user.. e.g. "Your estimated wait time is 2 minutes" as it is appearing to come from bot.
Bot escalated/transferred conversation to human agent, now show "typing indicator" to user when agent starts to type. This is a case of non-message based event, since it is an indicator is needed and there is no message. Although, the indicator needs to be somehow rendered to web client. Basically a non-message event that needs to be delivered to client via websocket.
Please let me know your thoughts. I would like to contribute but I'm not sure which branch I should work from. Create feature branch from master or 'dev/webchannel'?
I implemented the first usecase in my bot.
To send a timeout message to the user I keep an old instance of the Bot in scope for setTimeout callback.
@dipesh-gandhi check out this for submitting PRs https://github.com/howdyai/botkit/blob/master/CONTRIBUTING.md#submitting-pull-requests
@Naktibalda Thanks for response! I'm curious where you are getting instance of Bot? All the places I've seen so far are callbacks and I'd like to avoid checking if instance of Bot exists on every callback.
@peterswimm Thanks Peter! I've seen the CONTRIBUTING file. Is creating feature branch from master the right approach? There is separate branch 'dev/webchannel' so I want to confirm.
@dipesh-gandhi you wont be able to create a branch on the main repo, so youll be submitting any PR from your fork against master.
@dipesh-gandhi My code is much more complicated, but it boils down to:
controller.middleware.receive.use(function(bot, message, next) {
var timeoutFunction = () {
if (bot.connected) {
bot.reply('You were inactive for too long ...');
}
};
setTimeout(timeoutFunction, 10 * 60 * 1000);
});
Thanks @Naktibalda! My design is different so not sure if I can make it work that way. I have a custom middleware and part of it's responsibility is session management. This is because external sources can also determine what happens with the session. My mw is also different in that it doesn't follow standard request/response model. Instead I'm using message queues technique. This allows the middleware to send message at anytime, not necessarily always triggered by user and also ensures delivery of messages not relying on client to resend in case of issues. So at any points the mw message queue can come back with either a message to user or control indicator that a session has expired and need to notify user. In this case I need to access bot and reply and was hoping to directly access bot. Using bot spawn made sense but not working for web channel. I really think there should be access to bot outside of messaging events.
@dipesh-gandhi have you seen these custom features of the web client? https://github.com/howdyai/botkit-starter-web/blob/master/docs/botkit_web_client.md#client-api