2

I was playing with Microsoft Bot Framework locally which works fine if I use MSFT bot emulator for testing (both in C# .Net Core and Node.js) but I cannot figure out how to test it using Postman api calls.

Do I really need to register bot first at MSFT even when it is run locally to be able to get authentication ?

Nicolas R
  • 13,812
  • 2
  • 28
  • 57
marcinwal
  • 169
  • 10

2 Answers2

4

Normally, there is a Connector Service between the client and a bot. It is possible to bypass the connector services, and post directly to the bot but there are a few things to keep in mind. One of the issues you will run into is the activity.ServiceUrl is expected to be the callback base url for return messages: ref BotFrameworkAdapter#L843 Without a valid ServiceUrl, bot replies will all end in exceptions, since there is no valid place to send the responses. You can setup a MockChannel to receive these bot replies. Once it is setup, just ensure your ServiceUrl of the message sent to the bot is pointing to that MockChannel.

Sometimes I use the Emulator's Connector Service with PostMan. This can be done without having a MicrosoftAppId and MicrosoftAppPassword. You'll see the endpoint the Emulator Connector Service is listening on within the Log when you open a Live Chat tab: enter image description here

This would then be the baseurl to use for PostMan.

Create Conversation: (note: the emulator expects an Authorization header with a Bearer token, but the value does not matter since we aren't using a MicrosoftAppId and MicrosoftAppPassword) enter image description here

Post Message: enter image description here

Get Messages: enter image description here

Eric Dahlvang
  • 8,252
  • 4
  • 29
  • 50
0

A bot running on localhost should be testable via any HTTP client such as Postman as long as your forming the requests correctly which really only means you just need a payload that is a valid activity representation.

What you might need to check is whether or not you have any app credentials configured on your bot when you're running in localhost. If those are set then you would need to actually properly authenticate against your localhost instance as well, which the emulator will do, but you likely don't want to do when you're just trying to hit it with something like Postman. So, just make sure to clear out the app credentials when running in localhost mode to make your life easier.

If you're not running with any app credentials, then you'll need to update your question with more details about exactly what payload your sending, how your bot is configured, etc and I'll be happy to update my answer.

Drew Marsh
  • 33,111
  • 3
  • 82
  • 100
  • I believe I do not authenticate. Endpoint for Bot Emulator is http://localhost:3978/api/messages. I can see that Emulator starts the conversation using "directline.StartConversation" call but I don't know how to start the same way via Postman. – marcinwal Jan 07 '19 at 08:36
  • Ok, can you update your question with the payload you're sending? It should be a POST and of application/json with a JSON representation of an activity. Once you update with more details I'll have a better idea of how to help. Include screenshots from postman as well if you think it will help. – Drew Marsh Jan 07 '19 at 17:00