diff --git a/README.md b/README.md index 8111d0b..fc3375b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ you will need to define expected variables in the payload the webhook will recei Add this Action as a [step][job-step] to your project's GitHub Action Workflow file: -``` +```yaml - name: Send GitHub Action trigger data to Slack workflow id: slack uses: slackapi/slack-github-action@v1.17.0 @@ -38,12 +38,17 @@ Add this Action as a [step][job-step] to your project's GitHub Action Workflow f or -``` +```yaml - name: Send custom JSON data to Slack workflow id: slack uses: slackapi/slack-github-action@v1.17.0 with: - payload: "{\"key\":\"value\",\"foo\":\"bar\"}" # This data can be any valid JSON from a previous step in the GitHub Action + # This data can be any valid JSON from a previous step in the GitHub Action + payload: | + { + "key": "value", + "foo": "bar" + } env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} ``` @@ -77,13 +82,44 @@ By creating a new Slack app or using an existing one, this approach allows your Add this Action as a [step][job-step] to your project's GitHub Action Workflow file: -``` +```yaml - name: Post to a Slack channel id: slack uses: slackapi/slack-github-action@v1.17.0 with: - channel-id: 'CHANNEL_ID' # Slack channel id or user id to post message. https://api.slack.com/methods/chat.postMessage#channels - slack-message: 'posting from a github action!' + # Slack channel id, channel name, or user id to post message. + # See also: https://api.slack.com/methods/chat.postMessage#channels + channel-id: 'CHANNEL_ID' + # For posting a simple plain text message + slack-message: "GitHub build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} +``` + +Using JSON payload for constructing a message is also available: + +```yaml +- name: Post to a Slack channel + id: slack + uses: slackapi/slack-github-action@v1.16.0 + with: + # Slack channel id, channel name, or user id to post message. + # See also: https://api.slack.com/methods/chat.postMessage#channels + channel-id: 'CHANNEL_ID' + # For posting a rich message using Block Kit + payload: | + { + "text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}" + } + } + ] + } env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} ``` @@ -104,12 +140,25 @@ Incoming Webhooks conform to the same rules and functionality as any of Slack's ### Usage -``` +```yaml - name: Send custom JSON data to Slack workflow id: slack uses: slackapi/slack-github-action@v1.17.0 with: - payload: "{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"You have a new request: \"}},{\"type\":\"section\",\"fields\":[{\"type\":\"mrkdwn\",\"text\":\"*Type:* Computer (laptop)\"},{\"type\":\"mrkdwn\",\"text\":\"*When:* Submitted Aut 10\"}]}]}" + # For posting a rich message using Block Kit + payload: | + { + "text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}" + } + } + ] + } env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK diff --git a/example-workflows/Workflow_Builder/JSON_payload.yml b/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload.yml similarity index 76% rename from example-workflows/Workflow_Builder/JSON_payload.yml rename to example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload.yml index 4e2fced..1cf3b1d 100644 --- a/example-workflows/Workflow_Builder/JSON_payload.yml +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload.yml @@ -9,6 +9,10 @@ jobs: id: slack uses: slackapi/slack-github-action@v1.17.0 with: - payload: "{\"key\":\"value\",\"foo\":\"bar\"}" + payload: | + { + "key": "value", + "foo": "bar" + } env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/example-workflows/Workflow_Builder/JSON_payload_from_file.yml b/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload_from_file.yml similarity index 74% rename from example-workflows/Workflow_Builder/JSON_payload_from_file.yml rename to example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload_from_file.yml index 4cb84d5..250e585 100644 --- a/example-workflows/Workflow_Builder/JSON_payload_from_file.yml +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload_from_file.yml @@ -9,6 +9,6 @@ jobs: id: slack uses: slackapi/slack-github-action@v1.17.0 with: - payload-file-path: "./example-workflows/payloads/example.json" + payload-file-path: "./example-workflows/Technique_1_Slack_Workflow_Builder/payloads/example.json" env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/example-workflows/Workflow_Builder/default_GitHub_Trigger_payload.yml b/example-workflows/Technique_1_Slack_Workflow_Builder/default_GitHub_Trigger_payload.yml similarity index 100% rename from example-workflows/Workflow_Builder/default_GitHub_Trigger_payload.yml rename to example-workflows/Technique_1_Slack_Workflow_Builder/default_GitHub_Trigger_payload.yml diff --git a/example-workflows/payloads/example.json b/example-workflows/Technique_1_Slack_Workflow_Builder/payloads/example.json similarity index 100% rename from example-workflows/payloads/example.json rename to example-workflows/Technique_1_Slack_Workflow_Builder/payloads/example.json diff --git a/example-workflows/chat_postMessage_with_bot_token/JSON_payload.yml b/example-workflows/Technique_2_Slack_App/JSON_payload.yml similarity index 100% rename from example-workflows/chat_postMessage_with_bot_token/JSON_payload.yml rename to example-workflows/Technique_2_Slack_App/JSON_payload.yml diff --git a/example-workflows/chat_postMessage_with_bot_token/JSON_payload_as_text.yml b/example-workflows/Technique_2_Slack_App/JSON_payload_as_text.yml similarity index 85% rename from example-workflows/chat_postMessage_with_bot_token/JSON_payload_as_text.yml rename to example-workflows/Technique_2_Slack_App/JSON_payload_as_text.yml index ec0ca47..26dabf8 100644 --- a/example-workflows/chat_postMessage_with_bot_token/JSON_payload_as_text.yml +++ b/example-workflows/Technique_2_Slack_App/JSON_payload_as_text.yml @@ -10,6 +10,6 @@ jobs: uses: slackapi/slack-github-action@v1.17.0 with: channel-id: 'SLACK_CHANNEL_ID' # ID of Slack Channel you want to post to - payload: "{\"text\":\"posting from a github action\"}" + payload: "{\"text\": \"posting from a github action\"}" env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} diff --git a/example-workflows/chat_postMessage_with_bot_token/main.yml b/example-workflows/Technique_2_Slack_App/main.yml similarity index 100% rename from example-workflows/chat_postMessage_with_bot_token/main.yml rename to example-workflows/Technique_2_Slack_App/main.yml diff --git a/example-workflows/Technique_3_Slack_Incoming_Webhook/main.yml b/example-workflows/Technique_3_Slack_Incoming_Webhook/main.yml new file mode 100644 index 0000000..573c949 --- /dev/null +++ b/example-workflows/Technique_3_Slack_Incoming_Webhook/main.yml @@ -0,0 +1,51 @@ +on: [push] + +jobs: + new_push_job: + runs-on: ubuntu-latest + name: New push to repo + steps: + - name: Send GitHub trigger payload to Slack Workflow Builder + id: slack + uses: slackapi/slack-github-action@v1.16.0 + with: + payload: | + { + "text": "Danny Torrence left a 1 star review for your property.", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Danny Torrence left the following review for your property:" + } + }, + { + "type": "section", + "block_id": "section567", + "text": { + "type": "mrkdwn", + "text": " \\n :star: \\n Doors had too many axe holes, guest in room 237 was far too rowdy, whole place felt stuck in the 1920s." + }, + "accessory": { + "type": "image", + "image_url": "https://is5-ssl.mzstatic.com/image/thumb/Purple3/v4/d3/72/5c/d3725c8f-c642-5d69-1904-aa36e4297885/source/256x256bb.jpg", + "alt_text": "Haunted hotel image" + } + }, + { + "type": "section", + "block_id": "section789", + "fields": [ + { + "type": "mrkdwn", + "text": "*Average Rating*\\n1.0" + } + ] + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK +