Demonstration: Post to a Slack channel, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Demonstration: Post to a Slack channel

Demonstration: Post to a Slack channel

Runs Occurs when a user manually triggers the task. Configuration includes slack account and slack channel id.

15-day free trial – unlimited tasks

Documentation

Demonstration: Post to a Slack channel

This task posts a demonstration message in the Slack channel of your choice. Try it out to learn how the Slack action works!

Quick Start

  1. Install the Mechanic Slack app in your Slack workspace (Settings β†’ Authentication β†’ Slack)
  2. Set two task options:
    • Your Slack account
    • The Slack channel ID to post to
      • If this is a private channel, then you must add the Mechanic bot to the channel before it can post messages
  3. Run the task

Look in your Slack channel for the demonstration message. (Although you'll likely get a combination of app, email, and web notifications for this one post πŸ˜‚)

Want to Learn More?

This task demonstrates how to:
- Create a new message in an Slack channel
- Build dynamic message structure with some common Slack block kit components: header, section, divider, button

Take a look at the task code to see exactly how it works, then use this example in your own tasks.

Slack has extensive API documentation covering the many endpoints this integration can utilize. In relation to this demo task, the following API docs are the most relevant:
- https://docs.slack.dev/reference/methods/chat.postmessage
- https://docs.slack.dev/messaging/
- https://docs.slack.dev/block-kit/

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
mechanic/user/trigger
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
slack account (required) , slack channel id (required)
Code
{% assign slack_account = options.slack_account__required %}
{% assign slack_channel_id = options.slack_channel_id__required %}

{% comment %}
  IMPORTANT:
  -- This task requires the Mechanic app for Slack be installed in your Slack instance
  -- It will create a bot user - Mechanic - which the API actions will be made on behalf of
  -- This bot can automatically post to any public channels, but it must be added to any private channels you wish to post to
  -- Most Slack API errors will be surfaced by the integration, since the Slack convention is to return a 200 status even when there are errors

  API REFERENCEs:
  -- https://docs.slack.dev/reference/methods/chat.postmessage
  -- https://docs.slack.dev/messaging/
  -- https://docs.slack.dev/block-kit/
{% endcomment %}

{% if event.topic == "mechanic/user/trigger" %}
  {% comment %}
    ** Slack API - Post a new message **
    -- This action will create a new message in the configured channel of the connected Slack account
  {% endcomment %}

  {% action "slack" %}
    {
      "account": {{ slack_account | json }},
      "method": "POST",
      "url_path": "/chat.postMessage",
      "headers": {
        "Content-Type": "application/json"
      },
      "body": {
        "channel": {{ slack_channel_id | json }},
        "text": "Slack Integration Test",
        "blocks": [
          {
            "type": "header",
            "text": {
              "type": "plain_text",
              "text": "πŸŽ‰ Your Slack Integration is Working!"
            }
          },
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "Great job setting up the Slack integration! Here's what I can do:"
            }
          },
          {
            "type": "section",
            "fields": [
              {
                "type": "mrkdwn",
                "text": "*βœ… Send Messages*\nSend messages as @mechanic"
              },
              {
                "type": "mrkdwn",
                "text": "*#️⃣ Post to Public Channels*\nSend messages to public channels the app isn’t a member of"
              },
              {
                "type": "mrkdwn",
                "text": "*πŸ“‘ Upload Files*\nUpload, edit, and delete files as @mechanic"
              },
              {
                "type": "mrkdwn",
                "text": "*πŸ‘¨πŸ½β€πŸ”§ Customize Messages*\nSend messages with a customized username and avatar"
              }
            ]
          },
          {
            "type": "divider"
          },
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "*Shop Details:*\nβ€’ Name: {{ shop.name }}\nβ€’ Domain: {{ shop.domain }}\nβ€’ Email: {{ shop.email }}"
            },
            "accessory": {
              "type": "button",
              "text": {
                "type": "plain_text",
                "text": "Visit Shop"
              },
              "url": "https://{{ shop.domain }}",
              "action_id": "button-action"
            }
          }
        ]
      }
    }
  {% endaction %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more