0

I have built a message to be returned in slack from a payload generated in a js module. The message was formatted in block kit builder as:

    {
    "blocks": [
        {
            "type": "section",
            "text": {
                "text": "Tides for *Aberdeen* on _Saturday, 5th February 2023 (GMT)_",
                "type": "mrkdwn"
            },
            "fields": [
                {
                    "type": "mrkdwn",
                    "text": "*Time*"
                },
                {
                    "type": "mrkdwn",
                    "text": "*Height*"
                }
            ]
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "For multiple days and tide height predictions use  <https://script.google.com/macros/s/AKfycbwdzfkbP-YiBD0r7moZ80MrjgU68CYQ-pNqm8YbPoDQd_iSOk7vGOxV7xBdZrxQSzsafQ/exec|:uktides: Uk Tides>."
            }
        }
    ]
}

And this gives the following in block kit builder:

enter image description here

However when the app runs, the returned payload is displayed as:

enter image description here

i.e. the formatting is somehow ignored.

The relevant section of my code is:

    var payload = {
    "blocks": [
        {
            "type": "section",
            "text": {
                "text": "Tides for *Aberdeen* on _Saturday, 5th February 2023 (GMT)_",
                "type": "mrkdwn"
            },
            "fields": [
                {
                    "type": "mrkdwn",
                    "text": "*Time*"
                },
                {
                    "type": "mrkdwn",
                    "text": "*Height*"
                }
            ]
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "For multiple days and tide height predictions use  <https://script.google.com/macros/s/AKfycbwdzfkbP-YiBD0r7moZ80MrjgU68CYQ-pNqm8YbPoDQd_iSOk7vGOxV7xBdZrxQSzsafQ/exec|:uktides: Uk Tides>."
            }
        }
    ]
}
  
const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  socketMode: true,
  appToken: process.env.SLACK_APP_TOKEN,
  // Socket Mode doesn't listen on a port, but in case you want your app to respond to OAuth,
  // you still need to listen on some port!
  port: process.env.PORT || 3000,
  extendedErrorHandler: true
});

// Listens to incoming messages that contain "hello"
app.message('hello', async ({ message, say }) => {
  // say() sends a message to the channel where the event was triggered
  await say(`Hey there <@${message.user}>! my name is Ollie 2.1, how can I help you?`);

});

app.command('/tides', async ({ command, ack, say, respond }) => {
    // Acknowledge command request
    await ack();

    await parseCommand(`${command.text}`);

    await say(JSON.stringify(payload));
  
    //await respond(`${command.text}`);

  });

Can anyone see what I am doing wrong?

Thanks.

Jim Burke
  • 251
  • 3
  • 14

1 Answers1

0

I realised that I did not need to JSON.stringify the payload and by simply returning the payload, it formatted correctly. However I receive warnings in the console output so not fully resolved yet!

Jim Burke
  • 251
  • 3
  • 14