microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

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

Closed erlendw closed 8 years ago

erlendw commented 8 years ago

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

rcarmonad commented 8 years ago

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.

VishalWaman commented 8 years ago

thanks

erlendw commented 8 years ago

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.

VishalWaman commented 8 years ago

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

erlendw commented 8 years ago

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?:)

brendanarnold commented 8 years ago

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.

erlendw commented 8 years ago

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

dandriscoll commented 8 years ago

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.

brendanarnold commented 8 years ago

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)

erlendw commented 8 years ago

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.

dandriscoll commented 8 years ago

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

erlendw commented 8 years ago

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

rahul251993 commented 8 years ago

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

erlendw commented 8 years ago

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

rahul251993 commented 8 years ago

@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

erlendw commented 8 years ago

@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 :)

sachinavinaw commented 7 years ago

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

VishalWaman commented 7 years ago

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

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

sachinavinaw commented 7 years ago

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

gjayakumar92 commented 7 years ago

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?

erlendw commented 7 years ago

I actually never found a solution for this:(

On 17 Feb 2560 BE, at 10:32, Jaya kumar G notifications@github.com wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

siddiq-rehman commented 7 years ago

I am possibly looking into other solution of chatbot, which are faster and better than directline. :(

Infact i loved the bot framework, but speed matters more than it.

macherlarupesh commented 7 years ago

Hi I am working on Microsoft bor framework. Any one tell me, How to work message end point remotely on bot framework emulator..

kamna0611 commented 6 years ago

Hi @erlendw were you able to achieve this? I am trying to do something similar and no luck yet :(

ghost commented 6 years ago

I believe this can be used here: https://www.npmjs.com/package/offline-directline

peltemm commented 5 years ago

Why is this issue clossed? Does annyone found a solution for this issue yet?

EricDahlvang commented 5 years ago

This issue is closed because the Bot Framework team prefers How To questions be asked on Stack Overflow. GitHub issues is for Feature Requests and Bug reports.


This Load Testing blog post describes how to retrieve a token and call then bot directly: https://blog.botframework.com/2017/06/19/load-testing-a-bot/ (note: you will need to setup a Mock Channel, for the response message.)

prateekiiest commented 4 years ago

@erlendw I guess you are looking into some sort of this https://stackoverflow.com/questions/56573792/using-botframework-emulator-or-bots-hosted-remotely-without-internet-connectivit along the line?