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
Instead, it is displayed like this:
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?