Reputation: 45
I'm trying to test my bot using postman using the link provided by ngrok i.e. https://xxxxxx.ngrok.io/api/messages. But receiving a 400 bad request as shown below
I tried setting up a breakpoint on my controll and it does hit but it doesnt proceed to the catch statement.
I know there is nothing wrong about my bot since it works fine when using the emulator.
My plan here was to implement my bot to my custom chat without registering to any azure services.
Additional Info:
My request body is empty. I followed the answer from this question MS bot tested locally with postman even if I use this link https://xxxxx.ngrok.io/v3/directline/conversations, it returns an 404 not found as shown below. But when I open my bot using the emulator then executing the link with /v3/directline/conversations it works fine.
Upvotes: 3
Views: 1323
Reputation: 408
As the answer in the question you linked states:
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.
When you use the emulator, if forms the body of the request and it succeeds. If you want to use Postman to explore the way the API works, you must form the requests according to the framework documentation.
The /v3/directline/conversations
API documentation states that you need to supply a valid TokenParameters
object in the request body to get a response.
For working with the main REST API, you will need to use the base URL supplied by the cloud provider:
When a user sends a message to your bot, the incoming request contains an Activity object with a serviceUrl property that specifies the endpoint to which your bot should send its response. To access the Bot Connector service, use the serviceUrl value as the base URI for API requests.
Read more in the Bot Framework REST API Reference documentation.
Finally, to try and answer your overall issue, we can look at the fact the NGROK service is simply a way to expose a local environment publicly. The link provided by the NGROK service is meant to be used by the Bot Framework cloud service as described in this tutorial. When you set up forwarding via NGROK, you can chat with your bot via Facebook, Skype, etc. and receive requests in you application running locally. If you want to call an endpoint of your application, when it runs locally, using Postman you can simply use localhost:PORT_NUMBER
with the port number where your Dot Net application is serving its HTTP API.
If you look at the provided starter code sample you will see that on line #14
the controller is annotated to serve the requests on /api/messages
URL. Use the applicationUrl
specified in your configuration file to make a GET or POST request. Since your app probably doesn't have authentication yet you don't need a Bearer
token. Finally, keep in mind that POST request is intended to carry a body with it (even if the body is empty)! This may create issues with your workflow. Try using a GET request as it is a simpler tool.
Upvotes: 1