node.jsamazon-web-servicesaws-lambdacommandslack

AWS lambda function used for slack command returning json instead of text


I have a lambda function build on nodejs.

export const handler = async (event) => {
    return {
            statusCode: 200,
            body: JSON.stringify({
                "response_type": 'in_channel',
                "text": 'hello'
            })
        };
};

the response i get in slack is: {"response_type":"in_channel","text":"hello"} instead of hello;

What is happening? how can i fix this?

the response i get in slack is: {"response_type":"in_channel","text":"hello"} instead of hello;

What is happening? how can i fix this?


Solution

  • This probably happens because the content type is not specified.

    export const handler = async (event) => {
        return {
                statusCode: 200,
                headers: {
                  "content-type": "text/plain"
                },
                body: JSON.stringify{
                    "response_type": 'in_channel',
                    "text": 'hello'
                })
            };
    };