简体   繁体   中英

How to change AWS Lambda content type from Plain text to html

I want to display on my chatbot the link.

message: { contentType: 'PlainText', content:"<a href="www.google.com">Test Result</a>" },

html tag displays as it is. How can I display the content as html?

You need to set the content-type to text/html in the headers of your response object, as typically it is (implicitly) set to application/json .

Projected to your case, you need to return your function in your AWS Lambda handler like:

callback(null, {
  statusCode: 200,
  headers: {"content-type": "text/html"},
  body: "<html><body>OK</body></html>"
})

That will set the content type correctly for the client to parse.

For those that are using the serverless framework, you can configure the content-type of your function's response in your serverless.yml file, for example:

  downloadImage:
    handler: lib/client-app-services.downloadImage
    events:
     - http:
        path: client/images/{filename}
        method: get
        cors: true
        integration: lambda
        response:
          headers:
            Content-Type: "'image/jpeg'"
            Cache-Control: "'max-age=120'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM