How to capture what Alexa console sends to the endpoint? - azure

I am currently learning about the chatbots and developed two different skills. One has an endpoint on Azure and the other's endpoint is on AWS. Everything works fine. I would like to know if there is a way to see what the Alexa console sends to your endpoint (including the header)? The Alexa console only shows the body. I would like to capture header and body so I can test my endpoints with Postman.

POST / HTTP/1.1
Content-Type : application/json;charset=UTF-8
Host : your.application.endpoint
Content-Length :
Accept : application/json
Accept-Charset : utf-8
Signature:
SignatureCertChainUrl:
https://s3.amazonaws.com/echo.api/echo-api-cert.pem
It's the HTTP HEADER that Alexa is sending with its Body
For more info : Request and Response JSON Reference

Related

Not getting response from AWS after uploading image through ESP32

General context:
I am working on an IoT application where I upload images from an ESP32 connected to an SBC.
The uploading is done through an API provided by a third-party backend developer.
The upload API works through other mediums (such as Postman, python requests library, python http client library)
The ESP32 is connected to the SBC through UART.
I construct/generate the HTTP request on the SBC and send it as bytes. I have written a function on ESP32 that can send the bytes as a generic HTTP request, to the URL specified.
Then it sends the response string back to the SBC.
All of this works. For small requests, I am facing no issues. I am able to download images, etc.
However, when uploading an image, I don't get a response and I end up timing out after 30s. I checked without timeout FYI, but no response.
I checked from the server-side. It appears my request has succeeded and the server is sending me 200 with the URL of the image. Using that URL, I was able to verify that the image was uploaded successfully.
However, I do not receive this response on the microcontroller.
Not sure what the issue is. Any suggestions as to what I can do?
I can't give out the code but I'll send a general structure:
ESP32
-> Receives URL, port, length of request
-> Connects to server and reads the request from UART and writes to server
-> Wait for response after response is sent
Python raw http
POST (server path) HTTP/1.1
Host: (url)
correlation-id: test5
Content-Type: multipart/form-data; boundary=WebKitFormBoundary7MA4YWxkTrZu0gW
Authorization: Bearer (access token)
Content-Length: 268
--WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="portraits"; filename="name"
Content-Type: image/jpeg
(data)
--WebKitFormBoundary7MA4YWxkTrZu0gW--
Edit 1:
So, turns out it is not only "upload image", some other requests are also behaving similarly. Our server has many microservices. The services written in nodeJS which have more than 1 redirects are not working...?
I figured out what the issue is and hopefully, it will help anyone else facing the same issue. Also, some of my requests to the backend server which used a different authentication method worked
I had been generating the raw HTTP using postman code generation but it turns out Postman doesn't add a few headers which are needed for communicating with more complex servers.
What I mean is that if I host a local server, the above code will work. I had already tested it that way
What solved my problem is adding these headers:
POST (server path) HTTP/1.1
Host: (server URL)
User-Agent: ESP32
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
correlation-id: test
Authorization: Bearer (access_token)
Content-Length: 146360
Content-Type: multipart/form-data; boundary=af59ef02d60cd0efefb7bc03db1f4ffc
--af59ef02d60cd0efefb7bc03db1f4ffc
Content-Disposition: form-data; name="portraits"; filename="(name)"
Content-Type: image/jpeg
(data)
--af59ef02d60cd0efefb7bc03db1f4ffc--

grcp request payload format

I'm trying to log in into a site which requires grcp content-type using requests. I alrady have a HTTP 2 client, but I don't know how body of my post request should look like.
When I'm trying to simply copy request as a curl from chrome network tab, request body looks like this:
%äEMAIL"PASSWORD(0
When I'm trying to request site with same body as I copied from chrome tab, I'mm getting response with this headers:
Grpc-Message: grpc: received message larger than max (218767392 vs. 4194304)
Grpc-Status: 8
I'm sure It's becouse wrong payload format
If anybody knows how can I pass data in request plase help.
If you're trying to send a one-off gRPC request, https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md would be helpful to know as to how to construct a message. Otherwise, using gRPC clients (https://github.com/grpc/grpc) would make more sense.

API Gateway doesn't pass headers to Lambda

I am trying to make a multipart http query through API Gateway to a Lambda. I have set the binary media type to 'multipart/form-data'. The issue is that I need to access the Content-Type header, so that I can parse the body correctly in my lambda logic.
But when I console log the lambda event, I can see that the Content-Type header is missing, even though I can see that it is well sent by my client.
Also, everything works perfectly in local with serverless-offline, without going through API Gateway.
So I'm guessing API Gateway does its own processing of my request and send a different version of it to my Lambda, with different headers.
How can I force API Gateway to pass this header to my Lambda ?
Thank you very much!
In the integration request try adding an HTTP Header Content-Type mapped from application/x-www-form-urlencoded.
Then add a mapping template for multipart/form-data
{
"Content-Type" : "$input.params('Content-Type')",
"body_base64" : "$util.base64Encode($input.body)"
}
If you are using an OpenAPI template to create the api with terraform or serverless then configure the x-amazon-apigateway-integration: node
requestTemplates:
multipart/form-data: "{\n \"Content-Type\"\
\ : \"$input.params('Content-Type')\",\n \"body_base64\" : \"$util.base64Encode($input.body)\"\
\n}"
passthroughBehavior: "never"
type: "aws"

Azure Logic App - Receive file from http request

I have an ASP.Net handler that returns a PDF report. I want the Azure Logic App to request the file and then add it to an e-mail as an attachment.
When I try to do this through an HTTP request I get the following error:
BadRequest. Http request failed as there is an error: 'Error while copying content to a stream.'
If I make the request with a browser I get a HTTP 200 response and it works. See request/response headers from chrome and fiddler.
I'm sure I could solve this with an Azure Function to get the file blob and pass it to the e-mail stage but it appears in the documentation that Logic Apps can handle streams and base64 encode. Am I missing something here?
I tried with the following a static result in an HTTP request to mimic the HTTP request/stream as much as possible. I guess it comes down to that you need to design the body of the stream in a way the includes content and content-type like I did below with my mockup HTTP request
pdf content
content-type: application/pdf and application/octet-stream worked
Send and email action:
Sent email
Outlook result:

Receiving webhook in express from local application

I have an application (headless CMS) running locally. It has an option to send a webhook to another application. I have been trying to interpret this webhook via express using posts. I have not been able to even get it to register a request coming in from the application. I tested this route using postman and found that it is working when I post to it.
router.post('/', (req, res) => {
console.log("Recieved");
console.log(req.body);
res.status(200).send('ok')
});
Thus, when I send a post to: http://localhost:3000/recall via postman. I get the following header back:
Access-Control-Allow-Credentials →true
Access-Control-Allow-Headers →X-Requested-With,content-type
Access-Control-Allow-Methods →GET, POST, OPTIONS, PUT, PATCH, DELETE
Access-Control-Allow-Origin →http://localhost:3000
Connection →keep-alive
Content-Length →2
Content-Type →text/html; charset=utf-8
Date →Mon, 03 Sep 2018 21:23:22 GMT
ETag →W/"2-eoX0dku9ba8cNUXvu/DyeabcC+s"
X-Powered-By →Express
With the body:
ok
My script also prints the body of the post.
I can verify the webhook is working by testing it with request bin. I get back the following:
FORM/POST PARAMETERS
None
HEADERS
Cloudfront-Forwarded-Proto: http
Cloudfront-Is-Mobile-Viewer: false
Cloudfront-Is-Desktop-Viewer: true
Connect-Time: 1
Via: 1.1 3566cbcd49f71967b52a565888e4d272.cloudfront.net (CloudFront), 1.1 vegur
Content-Length: 387
Connection: close
Accept: */*
Content-Type: application/json
Cloudfront-Viewer-Country: US
X-Amz-Cf-Id: dRe5CvkLFJZJNcpZbhmeEHo0ar_taj6guvN8utwkyVXM7ZMJc5BZTw==
Cloudfront-Is-Smarttv-Viewer: false
X-Request-Id: 4b6d2cdc-5c45-495b-b358-2e808e1bfeb4
Cloudfront-Is-Tablet-Viewer: false
Total-Route-Time: 0
Host: requestbin.fullcontact.com
BODY
{"event":"singleton.remove","hook":"Save After Sington","backend":1,"args":[{"name":"Wonder","label":"Wonder","_id":"Wonder5b8cef36a0097","fields":[{"name":"Best","label":"","type":"text","default":"","info":"","group":"","localize":false,"options":[],"width":"1-1","lst":true,"acl":[]}],"template":"","data":null,"_created":1535962934,"_modified":1535962934,"description":"","acl":[]}]}
I tried enabling cross-origin requests. How could I fix this problem? My thought is it has something to do with the fact this request is originating and ending locally.
For an application to consume webhooks it needs to have a publicly accessible URL. Basically, the rest of the world (internet) doesn't know your localhost:3000 endpoints exist.
An easy way to fix this is to use a lightweight tool like ngrok to expose your local server; in turn allowing other applications to communicate with yours.
You will need to define the specific callback route that you want to consume the webhook POST request. Examples below.
Run your node script
Turn on ngrok
send webhook POST requests to your endpoint using the NGROK https address
Now, instead of sending your webhook to localhost:8000/MyWebhookConsumingEndpoint
you send it to
https://95e26af4.ngrok.io/MyWebhookConsumingEndpoint

Resources