botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Is there any way to connect directly to a chatbot without using the direct line api?

Open erlendw opened this issue 10 years ago • 28 comments

And if not; Is there any way to test direct line locally?

erlendw avatar Aug 16 '16 12:08 erlendw

You can test using the Channel Emulator. https://docs.botframework.com/en-us/tools/bot-framework-emulator/

In the link describe: How to test your own bot locally, and how to connect the emulator to the published app.

rcarmonad avatar Aug 22 '16 18:08 rcarmonad

thanks

VishalWaman avatar Aug 23 '16 04:08 VishalWaman

I see that the question was not specific enough. I was thinking more along the lines of writing a custom client connector without going through the Direct Line api hosted by Microsoft. I want to host my bot locally, and not have to use the direct line api.

erlendw avatar Aug 23 '16 08:08 erlendw

I think code of Bot emulator can be used, It does same locally.. but its not available

VishalWaman avatar Aug 23 '16 09:08 VishalWaman

Dan Driscoll briefly discussed that it would be possible to write a wrapper or something for the emulator on this podcast https://www.youtube.com/watch?v=z_JOzrEKCB4. @dandriscoll could you please elaborate on this?:)

erlendw avatar Aug 23 '16 09:08 erlendw

It would be great to be able to re-create the Channel Emulator code in a mobile app - mostly to avoid the extra latency of a middleware webservice as well as to be able to support things like cards and actions in the app.

At the moment DirectLine strips out many of these features and instead sends a plain text fallback e.g. appends '(1. yes or 2. no)'.

I have to include code in my mobile app that tries to interpret these fallbacks as e.g. asking for confirmation which is a little brittle since the text may change at any time, may be different in different languages etc.

There is some documentation on the SDK (i.e. https://docs.botframework.com/en-us/restapi/authentication/#navtitle) but it seems to be from the point of view of creating a bot, not from the client side.

brendanarnold avatar Aug 31 '16 10:08 brendanarnold

This is exactly why i want to connect directly as well! Running through the direct line api is so much slower than hosting the bot on a local server.

I have tried to decompile the emulator, but there is too much code to get something working quickly. If you want to try and have a look at it just download dotpeek and find the stuff you need from the install location of the bot emulator

Hopefully more people are interested in an actual direct line to the bot, instead of going through the api :)

erlendw avatar Sep 01 '16 09:09 erlendw

The short answer is this: yes, although you're now operating outside the Bot Framework world.

Bots are just web services. If you unhook security and talk directly to the bot's activity endpoint, you can operate your bot locally on your machine. It may be simpler to just open your own API on the bot's service because emulating what we do in the channels is actually a fair amount of work. (It's by no means impossible -- this is exactly what we do in the emulator -- but there is a fair amount of complexity there.)

If you want to stay within the Bot Framework universe, the bot's endpoint does need to be accessible by the Bot Framework services, i.e. on the internet. If you're publishing on the internet, you will probably want to secure your endpoint, and the Bot Framework security model by design does not allow just anyone to call a bot -- our libraries only allow in authentic Bot Framework services.

Direct Line is intended to power this and we're working on a new version that will preserve the message as it passes through the channel.

dandriscoll avatar Sep 01 '16 14:09 dandriscoll

If you are improving the direct line API, can I request there is a property in the json response which can be populated with custom metadata?

I have needed to pass specific info to my mobile app and the only way to do this I've found is to send serialised json instead of plain text responses (which looks terrible in all the other channels)

brendanarnold avatar Sep 01 '16 19:09 brendanarnold

Thanks a lot Dan! If I were to open my own api as you mentioned, would it be possible to just pass message objects to a rest endpoint? What I'm having hard time understanding is how I could use for example Postman to communicate with the bot.

erlendw avatar Sep 01 '16 21:09 erlendw

Hi @brendanarnold, yes, your client/bot controls the entire channelData field. Its contents are passed through Direct Line untouched. It's your own private tunnel.

Hi @erlendw, you can certainly reuse any of our libraries to create a custom API if you'd like. It's your API, so you can pass whatever objects you'd like -- if you want to pass objects that look like Bot Framework objects, please feel free :)

dandriscoll avatar Sep 01 '16 23:09 dandriscoll

@dandriscoll appreciate that you took the time to help! I will try it out!

erlendw avatar Sep 02 '16 07:09 erlendw

you can use local tunnels to test your bot locally :)

rahul251993 avatar Sep 27 '16 10:09 rahul251993

@rahul251993 I am not familiar with tunnels, would you care to elabourate? :)

erlendw avatar Sep 27 '16 10:09 erlendw

@erlendw local tunnels basically provide a URL which you can use to connect with your bot and test locally on slack or whatever application you want. You can do 'npm install -g localtunnel' to install it. Once installed you can setup your application where you want to test your bot either skype or slack or whatever. You also need to change message endpoint of app as : http://test.localtunnel.me/------------ the bot ID. After setup you can run localtunnel in console by using 'lt --port ****--subdomain test'. I hope it helps you. Cheers

rahul251993 avatar Sep 27 '16 11:09 rahul251993

@rahul251993 Sweet, this is very helpful because i need to reach some apis that are only available at my office domain, and this means i can test it without deploying to a local server. However I fail to see how it will help with the direct line client stuff tho. But very nice either way :)

Can't get it to work on windows, but it was worth a shot :)

erlendw avatar Sep 27 '16 11:09 erlendw

Hi, I am new to microsoft bot framework. Can anyone tell me what is Messaging endpoint URL?

sachinavinaw avatar Jan 17 '17 05:01 sachinavinaw

"Messaging endpoint" .... This is your node js sever url which listens to your Bot

Should be something like below https://*********/api/messages

VishalWaman avatar Jan 17 '17 05:01 VishalWaman

Thanks @VishalWaman. It worked for me.

I saved my bot and tried to test it, following error appears:

500 InternalServerError System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:3978 at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Intercom.DevPortal.Server.Controllers.BotManagerController.d__76.MoveNext() in C:\a\1\s\DevPortalLib\Controllers\BotManagerController.cs:line 2038

sachinavinaw avatar Jan 17 '17 06:01 sachinavinaw

Hi @erlendw Can you tell me how to connect bot without using DirectLine API?

Do i need to pass Activity object to connect to chat bot?

gjayakumar92 avatar Feb 17 '17 09:02 gjayakumar92