Mechanic's "http" action makes it extremely simple to send data to external webservices. And Slack's incoming webhooks feature makes it easy to turn that data into a Slack message.

To get started, read Slack's guide to incoming webhooks, and follow their instructions for creating an incoming webhook.

You'll arrive at a step where you've got an incoming webhook URL, like this one:

https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

Bring this URL over to your Mechanic task, and add something like this to your task script:

{% action "http" %}
  {
    "method": "post",
    "url": {{ options.slack_incoming_webhook_url__required | json }},
    "body": {
      "text": "hello, world!"
    }
  }
{% endaction %}

Or, using extra formatting:

{% action "http" %}
  {
    "method": "post",
    "url": {{ options.slack_incoming_webhook_url__required | json }},
    "body": {
      "blocks": [
        {
          "type": "section",
          "text": {
            "type": "mrkdwn",
            "text": "<https://google.com/|Google.com>"
          }
        }
      ]
    }
  }
{% endaction %}

Either of these samples will add a new required option to your task, labeled "Slack incoming webhook URL". Adjust to taste. :)

More resources

Did this answer your question?