-1

I created the following BLOCK but cannot figure out how to use it within a /Command. It shows fine when used within the ack({...}) but does nothing when I use say({...}). The only other way is the client.dialog with type: modal but that is not what I want.

I simple need to know how to respond using my JSON block kit code. Any help is appreciated.

{
    "attachments": [
        {
            "blocks": [
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "plain_text",
                            "text": user_id + ", this was your question",
                            "emoji": True
                        }
                    ]
                },
                {
                    "type": "section",
                    "text": {
                        "type": "plain_text",
                                "text": question,
                                "emoji": True
                    }
                },
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "plain_text",
                            "text": "Here's what I found",
                            "emoji": True
                        }
                    ]
                },
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": answer
                    }
                },
                {
                    "type": "divider"
                },
                {
                    "type": "section",
                    "text": {
                        "type": "plain_text",
                                "text": "Info",
                                "emoji": True
                    }
                },
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "mrkdwn",
                            "text": "*Author:* " + author
                        }
                    ]
                },
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "mrkdwn",
                            "text": "*Book:* " + booktitle
                        }
                    ]
                },
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "mrkdwn",
                            "text": "*Page:* " + str(page_num)
                        }
                    ]
                },
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": content
                    }
                },
                {
                    "type": "divider"
                },
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": "Was this helpful?"
                    },
                    "accessory": {
                        "type": "static_select",
                        "placeholder": {
                            "type": "plain_text",
                            "text": "please select an answer from the drop-down",
                            "emoji": True
                        },
                        "options": [
                            {
                                "text": {
                                    "type": "plain_text",
                                            "text": "*This was spot on*",
                                            "emoji": True
                                },
                                "value": "1"
                            },
                            {
                                "text": {
                                    "type": "plain_text",
                                            "text": "*This was somewhat helpful*",
                                            "emoji": True
                                },
                                "value": "0"
                            },
                            {
                                "text": {
                                    "type": "plain_text",
                                            "text": "*This was not helpful*",
                                            "emoji": True
                                },
                                "value": "-1"
                            }
                        ],
                        "action_id": "static_select-action"
                    }
                }
            ]
        }
    ]
}

EDIT could this work?

  client.chat_postMessage(
    channel=event['channel'],
    blocks=[
        {...})

EDIT

@app.command("/q")
def q_command(client, event, ack, command):
ack("Gotcha! Let me take a look...")
user_id = event.get("user")
#...
client.chat_postMessage(
    channel=event['channel'],
    blocks=[
        { ... }])
DirkLX
  • 1,317
  • 1
  • 10
  • 16

1 Answers1

0

What you mentioned will work.
Although, if you just want to respond to the same channel/dm where the command was invoked,
you should use response_url received in the event payload.
https://api.slack.com/interactivity/handling#message_responses

let res = await axios.post(rsp_url, {
      blocks: blocks
    });

For further reading : You can also check the following documentation.
SDK : https://slack.dev/python-slack-sdk/webhook/index.html#response-url
Message Types: https://slack.dev/python-slack-sdk/web/index.html#messaging

Suyash Gaur
  • 2,481
  • 2
  • 9
  • 22
  • Not working! I have spent an entire day by know. This is really frustrating. Can anyone maybe help with a full example? – DirkLX Sep 01 '21 at 10:21