Slack messaging from scripts

Andy Brown · 24/05/2024 · 1 min read


First create a Slack app and get the webhook URL.

Then you can use the following command to test your application:

curl -X POST -H 'Content-type: application/json' --data '{"text":" Hello, world"}' https://hooks.slack.com/services/webhook-id

Building message blocks

You can build up messages using message blocks like this:

"blocks": [
  {
    "type": "header",
    "text": {
      "type": "plain_text",
      "text": "You can reference properties: #{some_property}",
      "emoji": true
    }
  },
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "*You can use Slack's flavour of markdown too!*"
    }
  },
  {
    "type": "divider" 
  }
]

@-ing people and groups

You can @ people using their user id: <@ABCD> You can @ groups using the group id: <!subteam^ABCD>

For example:

{
  "type": "section",
  "text": {
    "type": "mrkdwn",
    "text": "This is how to @ the following team: <!subteam^S06QHB2EAN8>" 
  }
}

Discussions

Login to Post Comments
No Comments Posted