I am trying to send a formatted JS object on Slack using the API.
Best I could do was sending to chat.postMessage
as:
const testObj = {a: "Hello", b: "World"};
...
data: {
channel: "#my-channel"
text: JSON.stringify(testObj, null, "\t")
}
But it's still not formatted well and can't be minimized like JSON file on Slack.
How can I send it better formatted or as a JSON file?
I would recommend you to use the Text Snippet feature via files.upload method, so you can format the content type properly, in this case javascript.
Send Slack Text Snippet | Run in Fusebit ![]() |
---|
const testObj = {a: "Hello", b: "World"};
const result = await slackClient.files.upload({
channels: slackUserId,
content: testObj,
title: 'Sample',
filetype: 'javascript'
});
const {name, pretty_type} = result.file;
ctx.body = { message: `Successfully sent a text snippet of type ${pretty_type} called ${name} to Slack user ${slackUserId}!` };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With