I would like to use Blocks instead of Attachments in my Slack App but the app fails to return the message

824 Views Asked by At

I recently made my first Slack app - a sort of Tech Support FAQs tool for my workplace workspace. I originally wanted the responses to be much more complex using the Slack Block Kit, and having trawled the documentation on the Slack API site it looked like I could simply exchange Attachments for Blocks:

function respondWithFaq(text, callbackId, respond, choice) {
  frequentlyAskedQuestions.callback_id = callbackId
  frequentlyAskedQuestions.text = 'What are you trying to do?'
  respond({
    text: text,
    attachments: [frequentlyAskedQuestions[choice]], //All different choices are saved in a .json array and then saved at the top in a variable called frequentlyAskedQuestions
    replace_original: true
  })
}

However, when I swap that tag out the messages never print. I have used the Block Kit builder to try and construct more complex and useful responses using multiple sections but it doesn't seem to like more than 1 section in it's responses.

My .json files are structured in arrays depending on which choice was made in the previous select menu like so:

[
  {
    "fallback": "Upgrade your Slack client to use messages like these.",
    "color": "#3AA3E3",
    "attachment_type": "default",
    "callback_id" : "slack_help",
    "actions": [
        {
          "name": "subject_list",
          "text": "Select one",          
          "type": "select",
          "options": [
            {
              "text": "Add somebody to a channel",
              "value": "addToChannel"
            },
            {
              "text": "Find an old message",
              "value": "oldMessageThread"
            },
            {
              "text": "Fix my camera",
              "value": "cameraBroken"
            },
            {
              "text": "Fix my audio",
              "value": "audioBroken"
            },
            {
              "text": "Add a new workspace",
              "value": "addWorkspace"
            },
            {
              "text": "Submit a support ticket",
              "value": "submitTicket"
            }
          ]
        }
      ]
  },
  {
    "fallback": "Upgrade your Slack client to use messages like these.",
    "color": "#3AA3E3",
    "attachment_type": "default",
    "callback_id" : "box_help",
    "actions": [
        {
          "name": "subject_list",
          "text": "Select one",          
          "type": "select",
          "options": [
            {
              "text": "Fix Box Tools",
              "value": "boxTools"
            },
            {
              "text": "Unable to open a file from Box",
              "value": "microsoftOnline"
            },
            {
              "text": "Find a file or folder",
              "value": "findFile"
            },
            {
              "text": "Edit a file that has been shared with me",
              "value": "editFile"
            },
            {
              "text": "Merge my Box accounts",
              "value": "accountMerge"
            },
            {
              "text": "Submit a support ticket",
              "value": "submitTicket"
            }
          ]
        }
      ]
  },

and so on...

I wondered if this was something to do with the Response URL formatting but having read that documentation it appears that Blocks can be used within that.

Any advice or documentation that could help me with this?

I recognise that I am quite new to coding and perhaps I've done something really obvious - please point it out so I can learn!

I followed this tutorial online to create the app, and as they used attachments so did I. Then I tried to adapt from there.

0

There are 0 best solutions below