0

I am sending a JSON response from Node.js server to a Slack App. This response is displayed in raw form, as JSON, instead of being formatted properly.

Minimum code that replicates the problem:
server.js:

const express = require('express');
const app = express();

// POST request processing
app.post('/', function(req, res){
    var arr1 = [{"type":"section","text":{"type":"mrkdwn","text":"*Lorem Ipsum*"}},
    {"type":"section","text":{"type":"mrkdwn","text":"_Lorem Ipsum_"}},
    {"type":"section","text":{"type":"mrkdwn","text":"`Lorem Ipsum`"}}]
    res.setHeader('Content-Type', 'application/json');
    res.json(arr1);  
});

// Listen to the AppEngine/Heroku - specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log('Server listening on port ${PORT}...');
});

The JSON message should be rendered like visible here: api.slack.com/tools/block-kit-builder

enter image description here

Instead, it is displayed like this:

enter image description here

I have also tried this and numerous other ways:

res.end(JSON.stringify(arr1));

I've found this proper-way-to-return-json-using-node-or-express on SO, and looked through Slack and Node.js documentation. I've advanced quite far in my app, but responses are still not rendered properly, so I figured I would ask here.

Any ideas?

afaf12
  • 5,163
  • 9
  • 35
  • 58
  • Use the appropriate [SDK](https://slack.dev/node-slack-sdk/) – James Aug 03 '19 at 22:57
  • Possible duplicate of [Slack bot doesn't interpret json message](https://stackoverflow.com/questions/57132115/slack-bot-doesnt-interpret-json-message) – Erik Kalkoken Aug 04 '19 at 09:53

1 Answers1

0

please use a simple express response res.send(your JSON object);