Slack
The Slack action allows Mechanic to post messages to public and private channels in your Slack instance (as the Mechanic app bot or a customer username).
The Slack action provides a wrapper around HTTP calls to the Slack Web API. The various Slack API methods supported by this integration all share the same top-level structure in the action options.
Options
account
string
Required: the Slack account to use. Must match one of the Slack accounts linked in the Mechanic authentication settings.
method
string
Required: the HTTP verb as required by the Slack API for the specific method (e.g. "GET", "POST")
url_path
string
Required: the Slack API method (e.g. "/chat.postMessage")
headers
hash
Required: "Content-Type": "application/json"
body
hash
Required: the object that contains a JSON representation of the properties and content of the message
Supported API Methods
Currently, these are the only Slack API methods supported by this integration.
Authentication
This action requires installing the Mechanic Slack app in your Slack account with the appropriate permissions. To install the app:
Go to the Settings screen
Click Authentication
Install the Mechanic Slack app from the Slack tab
Examples
Post a Simple Message
{% action "slack" %}
{
"account": "SLACK_ACCOUNT_NAME",
"method": "POST",
"url_path": "/chat.postMessage",
"headers": {
"Content-Type": "application/json"
},
"body": {
"channel": "CHANNEL_ID",
"text": "Slack Example Message",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Lorem ipsum dolor sit amet consectetur adipiscing elit."
}
}
]
}
}
{% endaction %}Post a Message with Custom Username and Icon
{% action "slack" %}
{
"account": "SLACK_ACCOUNT_NAME",
"method": "POST",
"url_path": "/chat.postMessage",
"headers": {
"Content-Type": "application/json"
},
"body": {
"username": "AiRobot",
"icon_emoji": ":robot_face:",
"channel": "CHANNEL_ID",
"text": "Slack Example Message",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Lorem ipsum dolor sit amet consectetur adipiscing elit."
}
}
]
}
}
{% endaction %}Action Response
The body of the action response will vary based on which Slack API method is called. Generally, the response is an object with the following structure (most fields removed for brevity). Running a Slack action task and reviewing the response is often the best way to see what will be returned in the body.
{
"type": "slack",
"run": {
"ok": true,
"result": {
"status": 200,
"body": {
...
}
}
}
}Last updated
Was this helpful?