BotFramework-WebChat icon indicating copy to clipboard operation
BotFramework-WebChat copied to clipboard

How to run WebChat locally and talk directly to the locally hosted bot?

Open pefi1011 opened this issue 9 years ago • 47 comments

Hi, is WebChat able to (emulate BotConnector services and) talk directly to the locally hosted bot?

Right now, I'm talking to my locally hosted bot, but I have registered it and exposed it to outer world via ngrok. What should I change to enable this? Dan Driscoll mentioned something like unhooking security.

pefi1011 avatar Dec 22 '16 15:12 pefi1011

WebChat cannot talk directly to a bot. It requires a Direct Line endpoint. There is some talk about adding a Direct Line endpoint to the Emulator, which is the best way I can think of to hook WebChat up to a local bot. Of course the Emulator itself runs a WebChat instance, but I understand you may wish to test WebChat in a website.

billba avatar Dec 22 '16 15:12 billba

Thanks for the reply @billba . Yes, I wanted to run a WebChat in a website and talk directly to the bot avoiding the BotConnector.

pefi1011 avatar Dec 22 '16 15:12 pefi1011

Can you say a little more abut why you want to do this?

billba avatar Dec 22 '16 15:12 billba

I'm developing a bot which should be mainly used in an intranet and hence not exposed to the outer world (in the moment).

pefi1011 avatar Dec 23 '16 14:12 pefi1011

Unfortunately that is not currently a supported scenario. You would need to build your own Direct Line connector.

billba avatar Dec 23 '16 17:12 billba

However it's worth saying that even an Intranet bot can be hosted on the Internet. You control which clients have access, so it would still be private to your employees.

billba avatar Dec 23 '16 17:12 billba

@pefi1011 and @billba....I am running into the same situations...corporate policies do not allow for me to "hook up" an external Bot to an Intranet...just not happening.

forensicsguy20012004 avatar Dec 25 '16 15:12 forensicsguy20012004

Yup, I understand that this is a widespread requirement. But any solution will not be in WebChat itself, whose whole purpose in life is to be speak Direct Line with BotBuilder bots. What you need, as I mentioned above, is a Direct Line connector for BotBuilder bots.

billba avatar Dec 26 '16 23:12 billba

@billba Could you please elaborate what you mean with DirectLine connector? As far as I understand, DirectLine API connects to BotConnector. Once, on the right side which connects different channels with BotConnector and on the left side which connects BotBuilder bots with BotConnector.

Still, if I control over what clients have access, BotConnector sees the whole communications because it's the man in the middle.

P.S. Merry Christmas :smiley:

pefi1011 avatar Dec 27 '16 12:12 pefi1011

@pefi1011 and @billba....so for me..if there was a way to take the "botframework-emulator" and "webenize" it that would take care of things. I have my Bot build through "botbuilder" and hosting my Bot internally ... I just need to get a front-end to it. I played around some more with [BotFramework-WebChat] trying to figure out the best way to get the UI to interface with my bot...still working around with the DirectLine stuff. I just wanted to toss out my "user story."

forensicsguy20012004 avatar Dec 28 '16 13:12 forensicsguy20012004

@pefi1011 as I understand it there is a BotConnector for each channel, e.g. Skype, Slack, Facebook Messenger. There is also one for DirectLine, which is essentially a generic channel used by custom clients and also WebChat. You are correct: BotConnector is a man in the middle. Of course that's also true for e.g. Facebook and any other messaging system that doesn't do end-to-end encryption of messages. So what you (and @forensicsguy20012004) want is a version of the Direct Line BotConnector that you can run on your Intranet.

I totally get this scenario. I just don't have a solution for you at the moment, and whatever that solution is will not be part of WebChat.

billba avatar Dec 28 '16 17:12 billba

Reopening this issue to make it more visible.

billba avatar Dec 28 '16 17:12 billba

We are also looking at the emulator and seeing if the same can be used to emulate a DirectLine endpoint for webchat clients to hook into. Observations (may not be completely accurate as its WIP):

  1. Emulator uses msbotchat (webchat) and extends it to connect to an emulated DirectLine endpoint. Within the emulator client src, mainView.tsx file, I can see this code: `this.directline = new BotChat.DirectLine( { secret: settings.conversation.conversationId, token: settings.conversation.conversationId },' '${Emulator.serviceUrl}/v3/directline'
  2. The emulator server listens on a port for incoming bot connections. When you run the emulator you can see the port its listening on
  3. If we decouple the emulator server and the webchat client and make the server run independently, it (just!) might be possible to run a bot completely on localhost.

We are currently trying to do this. If anyone here makes a breakthru, please do share.

Optional Notes We have found Azure Bot Services to be an awesome deployment option for bots. Its makes the whole deployment experience very simple, so that we can focus on the building the core conversational experience. Also the security and the scale that we get with Azure, we just cannot get it with any on-prem or private cloud infrastructure. That being said, few customers are still wary of taking the plunge into the cloud. They are definitely lagging when it comes to the adoption of a cloud first enterprise. But with Bots, we are making breakthroughs with such clients as well. For example, we have been able to convince customers to use the power of Cognitive Services to make bots smarter. Its a baby step towards Azure, but its working.

abhishan avatar Dec 28 '16 19:12 abhishan

@abhishan This is the approach we are looking at - extracting the Direct Line connector out of the Emulator into its own project that can be run independently.

billba avatar Dec 28 '16 19:12 billba

@abhishan I hope it works. I have used the emulator as a state endpoint in the similar manner.

siddiq-rehman avatar Dec 29 '16 09:12 siddiq-rehman

@siddiq-rehman Kindly share the code or the steps how you achieved this. Especially the security issues.

I have tried to expose the emulator server to a stand alone webchat window, but I faced the following issues:

  1. Cross Domain Request issues - I tried to set CORS in Restify and made some progress there but results were inconclusive
  2. Access Denied Error - After setting CORS, the webchat connection got access denied while connecting. I had set the direct line endpoint to the emulator listening port URL.
  3. DirectLine secret and token - I entered the one that was generated by the webchat client (of emulator). I know this is not correct, but I need to still figure this part out.

Still struggling :(

Any help would be appreciated.

abhishan avatar Dec 29 '16 12:12 abhishan

@abhishan I have used emulator as a state end point in the bot server. I have made changes in chatConnector.js. Wherever the bot server is making a request to the emulator for the state of conversation, there I have bypassed the loop for getting the accesstoken from "https://login.microsoftonline.com/common/oauth2/v2.0/token".

Since the changes are confined only to bot server it was not a difficult task.

But here i tried the same way in webchat client code, so whenever posting the messages i have removed the authorization in the header. But unfortunately it didnt work :(

Still I am too working on it.

siddiq-rehman avatar Dec 30 '16 06:12 siddiq-rehman

@billba @siddiq-rehman

I need to authenticate my user in bot using cookies , already stored in my domain eg. I have a website a.b.com , my user logs into my website When he/she clicks On the bot , the bot should be aware about the user details

I have apis to get the user details , just dont want to ask user to sign in again. I use a session id and other cookies in my website

How can I implement it , my current website runs on azure web app

Thanks

cruise-insights avatar Apr 11 '17 10:04 cruise-insights

Hi,

I am not sure about that, but one thing that I can suggest is, there is a user variable in index.html to which you can pass your cookie. when you check the req.body in ChatConnector file of bot builder module, you can see your user details passed.

This is the basic idea i got. Please reply back if you got any other option.

siddiq-rehman avatar Apr 11 '17 14:04 siddiq-rehman

First of all, this sort of question belongs on StackOverflow.

@siddiq-rehman That's not really what the user property is for.

A better approach is to use the backchannel to send authentication information from your web page to your bot.

billba avatar Apr 11 '17 15:04 billba