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

How do I test my bot running on localhost?

Open dluc opened this issue 2 years ago • 6 comments

With Bot Framework Emulator I can test a bot running locally on localhost, e.g. connecting to http://localhost:3978/api/messages.

How do I connect WebChat to the same localhost endpoint?

image

dluc avatar Jun 23 '22 20:06 dluc

Web Chat cannot connect to the bot directly. It must connect to a chat service.

The chat service could be, for example:

  • Azure Bot Services (ABS)
    • You can use a HTTP tunneling service, such as ngrok, to redirect the traffic from ABS to localhost
  • Bot Framework Emulator
    • Emulator is emulating ABS and will expose itself

When you run it in Emulator, in the Log window, you should see "Emulator listening on http://...". IIRC, you should pass it like this, using the domain property.

window.WebChat.renderWebChat({
  directLine: window.WebChat.createDirectLine({
    domain: 'http://localhost:.../v3/directline'
  })
});

Could you try this out and see? You can run a Fiddler, run Emulator, and you should see Web Chat inside Emulator is pointing to a similar URL. That's what you need in the domain field.

I am recently busy working on some issues in Web Chat so I cannot get you the exact steps to get the job done. But I am 95% sure this is possible. 🙏🏻 Will be great if you can post your findings here. I will try to post more if I can find any.

compulim avatar Jun 24 '22 08:06 compulim

image

You can check out their code here, https://github.com/microsoft/BotFramework-Emulator/blob/main/packages/app/client/src/state/sagas/chatSagas.ts#L740. This code initialize DirectLineJS chat adapter and plug into Web Chat.

compulim avatar Jun 24 '22 08:06 compulim

hi @compulim, I'm looking for a development workflow that doesn't require a deployment, until the bot is ready. E.g. I want to enable any developer in my team to create web chat bots and run demos (locally, sharing the screen, recording a video), without depending on cloud resources, Azure access, etc.

Looks like I need to add extra .NET code to handle requests to "/v3/directline", if I want to run the code locally without external dependencies.

As a reference, I'm using the sample code at https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/csharp_dotnetcore/02.echo-bot which implements only one "api/messages" route.

dluc avatar Jun 24 '22 19:06 dluc

In any case, thanks for the pointers, if I make some progress in this direction I will post an update. For now, given time constraints, I'm switching to a different approach using SignalR (kind of reinventing the wheel I know). Thanks!

dluc avatar Jun 24 '22 19:06 dluc

SignalR! Their team has a (relatively) new project called Azure Web PubSub and it is based on their existing SignalR infrastructure. In short, it is SignalR in Web Socket API. So no extra SDK, minimal learning curve, and superb browser compatibility.

I experimented using Web Chat with Azure Web PubSub as the chat protocol and it's fun. 😁

https://docs.microsoft.com/en-us/azure/azure-web-pubsub/overview

compulim avatar Jun 24 '22 19:06 compulim

/v3/directline are Azure Bot Services REST API, and ABS will relay it to the bot's /api/messages endpoint.

Bot Framework Emulator is emulating/mocking ABS /v3/directline REST APIs and "converting" them to talk to your bot's /api/messages. I believe we don't document these ABS REST APIs. However, you can find Emulator code of emulating these APIs here, https://github.com/microsoft/BotFramework-Emulator/tree/main/packages/app/main/src/server/routes/directLine/handlers.

These ABS REST APIs is for, say, handling multiple conversations, file attachment storage, backplane for relaying messages to server farm of bots, etc.

compulim avatar Jun 24 '22 19:06 compulim