From 8bfc8df87eac5474e32eedf55d55931664e7e7dc Mon Sep 17 00:00:00 2001 From: "@zimeg" Date: Wed, 18 Dec 2024 10:50:29 -0800 Subject: [PATCH] docs: showcase updated use cases in example workflows --- README.md | 3 +- .../JSON_payload.yml | 16 ---- .../JSON_payload_from_file.yml | 14 ---- .../README.md | 78 +++++++++++++++++++ .../announcements.gha.yml | 19 +++++ .../announcements.manifest.json | 1 + .../format.data.json | 5 ++ .../format.gha.yml | 22 ++++++ .../format.manifest.json | 1 + .../payloads/example.json | 3 - ...tHub_Trigger_payload.yml => topic.gha.yml} | 15 ++-- .../topic.manifest.json | 1 + .../Technique_2_Slack_API_Method/README.md | 40 ++++++++++ .../Technique_2_Slack_API_Method/author.yml | 56 +++++++++++++ .../Technique_2_Slack_API_Method/invite.yml | 56 +++++++++++++ .../Technique_2_Slack_App/JSON_payload.yml | 32 -------- .../JSON_payload_as_text.yml | 16 ---- .../Technique_2_Slack_App/main.yml | 16 ---- .../README.md | 57 ++++++++++++++ .../{main.yml => blocks.yml} | 28 +++---- .../saved.data.json | 34 ++++++++ .../saved.gha.yml | 23 ++++++ .../text.yml | 19 +++++ 23 files changed, 438 insertions(+), 117 deletions(-) delete mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload.yml delete mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload_from_file.yml create mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/README.md create mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/announcements.gha.yml create mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/announcements.manifest.json create mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/format.data.json create mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/format.gha.yml create mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/format.manifest.json delete mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/payloads/example.json rename example-workflows/Technique_1_Slack_Workflow_Builder/{default_GitHub_Trigger_payload.yml => topic.gha.yml} (55%) create mode 100644 example-workflows/Technique_1_Slack_Workflow_Builder/topic.manifest.json create mode 100644 example-workflows/Technique_2_Slack_API_Method/README.md create mode 100644 example-workflows/Technique_2_Slack_API_Method/author.yml create mode 100644 example-workflows/Technique_2_Slack_API_Method/invite.yml delete mode 100644 example-workflows/Technique_2_Slack_App/JSON_payload.yml delete mode 100644 example-workflows/Technique_2_Slack_App/JSON_payload_as_text.yml delete mode 100644 example-workflows/Technique_2_Slack_App/main.yml create mode 100644 example-workflows/Technique_3_Slack_Incoming_Webhook/README.md rename example-workflows/Technique_3_Slack_Incoming_Webhook/{main.yml => blocks.yml} (55%) create mode 100644 example-workflows/Technique_3_Slack_Incoming_Webhook/saved.data.json create mode 100644 example-workflows/Technique_3_Slack_Incoming_Webhook/saved.gha.yml create mode 100644 example-workflows/Technique_3_Slack_Incoming_Webhook/text.yml diff --git a/README.md b/README.md index 631e9bba..6e608b37 100644 --- a/README.md +++ b/README.md @@ -278,7 +278,7 @@ convenience of the [`files.uploadV2`][files.uploadV2] method: payload: | channel_id: ${{ secrets.SLACK_CHANNEL_ID }} initial_comment: "the results are in!" - file: "results.out" + file: "./path/to/results.out" filename: "results-${{ github.sha }}.out" ``` @@ -385,7 +385,6 @@ input payload with the `payload-templated` option: ```yaml - name: Send custom JSON data to Slack workflow - id: slack uses: slackapi/slack-github-action@v2.0.0 with: payload-file-path: "./payload-slack-content.json" diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload.yml b/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload.yml deleted file mode 100644 index 38ea305e..00000000 --- a/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload.yml +++ /dev/null @@ -1,16 +0,0 @@ -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@v2.0.0 - with: - webhook: ${{ secrets.SLACK_WEBHOOK_URL }} - webhook-type: webhook-trigger - payload: | - key: value - foo: bar diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload_from_file.yml b/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload_from_file.yml deleted file mode 100644 index f8ae7f41..00000000 --- a/example-workflows/Technique_1_Slack_Workflow_Builder/JSON_payload_from_file.yml +++ /dev/null @@ -1,14 +0,0 @@ -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@v2.0.0 - with: - payload-file-path: "./example-workflows/Technique_1_Slack_Workflow_Builder/payloads/example.json" - webhook: ${{ secrets.SLACK_WEBHOOK_URL }} - webhook-type: webhook-trigger diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/README.md b/example-workflows/Technique_1_Slack_Workflow_Builder/README.md new file mode 100644 index 00000000..21e22271 --- /dev/null +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/README.md @@ -0,0 +1,78 @@ +# Technique 1: Slack Workflow Builder + +> :memo: This technique requires [a Slack paid plan][plans] to use Workflow +> Builder. + +This technique sends data to Slack using a webhook to start a workflow created +using Slack [Workflow Builder][wfb]. + +## Setup + +For details on how to setup this technique in GitHub Actions, read the +[`README.md`][setup]. + +## Example workflows + +1. [**Format generated files**](#format-structured-files): Message outputs from + prior steps. +2. [**Post release announcements**](#post-release-announcements): Share releases + to a channel. +3. [**Update a channel topic**](#update-a-channel-topic): Highlight the current + build status. + +### Format generated files + +Convert build outputs from earlier GitHub Action steps into a Slack message. + +This example uses data from a payload file to [send a message][send_message] to +a channel. + +**Related files**: + +- [`format.data.json`](./format.data.json): Payload file being sent. +- [`format.gha.yml`](./format.gha.yml): GitHub Actions workflow. +- [`format.manifest.json`](./format.manifest.json): Slack app manifest. + +### Post release announcements + +Select a channel to post news about the most recent release to. + +This example uses [Slack functions][functions] and a +[connector function][connector] to do the following: + +1. Open a form to select a channel. +2. Gather a random gif from [giphy][giphy]. +3. Send a message to the selected channel. +4. React with an excited emoji. + +The default GitHub event [context][event-context] and [payload][event-payload] +are used as inputs. + +**Related files**: + +- [`announcements.gha.yml`](./announcements.gha.yml): GitHub Actions workflow. +- [`announcements.manifest.json`](./announcements.manifest.json): Slack app + manifest. + +### Update a channel topic + +Show the current build status in the header of a channel. + +This example uses inputs provided inline to +[update a channel topic][update_channel_topic]. + +**Related files**: + +- [`topic.gha.yml`](./topic.gha.yml): GitHub Actions workflow. +- [`topic.manifest.json`](./topic.manifest.json): Slack app manifest. + +[connector]: https://api.slack.com/automation/connectors +[event-context]: https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts#L6 +[event-payload]: https://docs.github.com/en/webhooks/webhook-events-and-payloads +[functions]: https://api.slack.com/automation/functions +[giphy]: https://giphy.com +[send_message]: https://api.slack.com/reference/functions/send_message +[plans]: https://slack.com/pricing +[setup]: https://github.com/slackapi/slack-github-action/blob/main/README.md#technique-1-slack-workflow-builder +[update_channel_topic]: https://api.slack.com/reference/functions/update_channel_topic +[wfb]: https://slack.com/features/workflow-automation diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/announcements.gha.yml b/example-workflows/Technique_1_Slack_Workflow_Builder/announcements.gha.yml new file mode 100644 index 00000000..da891bc5 --- /dev/null +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/announcements.gha.yml @@ -0,0 +1,19 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Post release announcements +on: + release: +jobs: + run: + name: Share recent changes with a channel + runs-on: ubuntu-latest + steps: + - name: Draft with these release notes details + uses: slackapi/slack-github-action@v2.0.0 + with: + webhook: ${{ secrets.SLACK_WEBHOOK_URL }} + webhook-type: webhook-trigger + payload: | + key: value + foo: bar + todo: update this.... diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/announcements.manifest.json b/example-workflows/Technique_1_Slack_Workflow_Builder/announcements.manifest.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/announcements.manifest.json @@ -0,0 +1 @@ +{} diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/format.data.json b/example-workflows/Technique_1_Slack_Workflow_Builder/format.data.json new file mode 100644 index 00000000..ae8e0191 --- /dev/null +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/format.data.json @@ -0,0 +1,5 @@ +{ + "todo": "12345", + "something": "${{ github.???????????? }}", + "details": "${{ env.???????????? }}" +} diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/format.gha.yml b/example-workflows/Technique_1_Slack_Workflow_Builder/format.gha.yml new file mode 100644 index 00000000..1d7224ad --- /dev/null +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/format.gha.yml @@ -0,0 +1,22 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Format generated files +on: + push: +jobs: + run: + name: Write structured data as a message + runs-on: ubuntu-latest + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Start the Slack workflow + uses: slackapi/slack-github-action@v2.0.0 + with: + payload-file-path: "./example-workflows/Technique_1_Slack_Workflow_Builder/format.data.json" + payload-templated: true + webhook: ${{ secrets.SLACK_WEBHOOK_URL }} + webhook-type: webhook-trigger diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/format.manifest.json b/example-workflows/Technique_1_Slack_Workflow_Builder/format.manifest.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/format.manifest.json @@ -0,0 +1 @@ +{} diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/payloads/example.json b/example-workflows/Technique_1_Slack_Workflow_Builder/payloads/example.json deleted file mode 100644 index 6f212ceb..00000000 --- a/example-workflows/Technique_1_Slack_Workflow_Builder/payloads/example.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "text": "${{ github.workflow }} workflow failed on ${{ env.DEFAULT_BRANCH }} branch in the ${{ github.event.repository.name }} repository!" -} diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/default_GitHub_Trigger_payload.yml b/example-workflows/Technique_1_Slack_Workflow_Builder/topic.gha.yml similarity index 55% rename from example-workflows/Technique_1_Slack_Workflow_Builder/default_GitHub_Trigger_payload.yml rename to example-workflows/Technique_1_Slack_Workflow_Builder/topic.gha.yml index aa7f98a8..e5c7243a 100644 --- a/example-workflows/Technique_1_Slack_Workflow_Builder/default_GitHub_Trigger_payload.yml +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/topic.gha.yml @@ -1,12 +1,17 @@ -on: [push] +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +name: Update a channel topic +on: + push: + branches: + - main + - example jobs: - new_push_job: - runs-on: ubuntu-latest + run: name: New push to repo + runs-on: ubuntu-latest steps: - - name: Send GitHub trigger payload to Slack Workflow Builder - id: slack + - name: Update the channel topic uses: slackapi/slack-github-action@v2.0.0 with: payload-delimiter: "_" diff --git a/example-workflows/Technique_1_Slack_Workflow_Builder/topic.manifest.json b/example-workflows/Technique_1_Slack_Workflow_Builder/topic.manifest.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/example-workflows/Technique_1_Slack_Workflow_Builder/topic.manifest.json @@ -0,0 +1 @@ +{} diff --git a/example-workflows/Technique_2_Slack_API_Method/README.md b/example-workflows/Technique_2_Slack_API_Method/README.md new file mode 100644 index 00000000..443ebf6b --- /dev/null +++ b/example-workflows/Technique_2_Slack_API_Method/README.md @@ -0,0 +1,40 @@ +# Technique 2: Slack API method + +A bot token or user token or [token of some other kind][tokens] must be used to +call one of [the Slack API methods][methods] with this technique. + +## Setup + +For details on how to setup this technique in GitHub Actions, read the +[`README.md`][setup]. + +## Example workflows + +1. [**Direct message the author**](#direct-message-the-author): Write to the + Slack user with a matching email. +2. [**Invite a usergroup to channel**](#invite-a-usergroup-to-channel): Create a + channel and invite members. + +### Direct message the author + +Send a direct message to the user that pushed the most recent commits. + +This example uses the email of the pusher to find the user to send a message to. + +**Related files**: + +- [`author.yml`](./author.yml): GitHub Actions workflow. + +### Invite a usergroup to channel + +Create a channel after a bug is reported and add members of a usergroup. + +This example chains multiple Slack API methods together to help fix bugs fast. + +**Related files**: + +- [`invite.yml`](./invite.yml): GitHub Actions workflow. + +[methods]: https://api.slack.com/methods +[setup]: https://github.com/slackapi/slack-github-action?tab=readme-ov-file#technique-2-slack-api-method +[tokens]: https://api.slack.com/concepts/token-types diff --git a/example-workflows/Technique_2_Slack_API_Method/author.yml b/example-workflows/Technique_2_Slack_API_Method/author.yml new file mode 100644 index 00000000..0e62d513 --- /dev/null +++ b/example-workflows/Technique_2_Slack_API_Method/author.yml @@ -0,0 +1,56 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Direct message the author +on: + push: +jobs: + run: + name: Send a notification of recent changes + runs-on: ubuntu-latest + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Find correspondences + id: email + uses: slackapi/slack-github-action@v2.0.0 + with: + method: users.lookupByEmail # https://api.slack.com/methods/users.lookupByEmail + token: ${{ secrets.SLACK_BOT_TOKEN }} + payload: | + email: ${{ github.event.pusher.email }} + + - name: Search email detail + if: ${{ steps.email.outputs.ok }} + run: | + SLACK_USER_ID=$(echo '${{ steps.email.outputs.response }}' | jq -r '.user.id') + echo "SLACK_USER_ID=$SLACK_USER_ID" >> $GITHUB_ENV + + - name: Send a direct message + if: ${{ steps.email.outputs.ok }} + uses: slackapi/slack-github-action@v2.0.0 + with: + errors: true + method: chat.postMessage # https://api.slack.com/methods/chat.postMessage + token: ${{ secrets.SLACK_BOT_TOKEN }} + payload: | + "channel": "${{ env.SLACK_USER_ID }}", + "text": "${{ github.repository }} had a change!", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ":large_green_square: : `${{ github.sha }}`" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ${{ toJSON(github.event.head_commit.message) }} + } + } + ] diff --git a/example-workflows/Technique_2_Slack_API_Method/invite.yml b/example-workflows/Technique_2_Slack_API_Method/invite.yml new file mode 100644 index 00000000..e19f7b9a --- /dev/null +++ b/example-workflows/Technique_2_Slack_API_Method/invite.yml @@ -0,0 +1,56 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Invite a usergroup to channel +on: + issues: + types: + - labeled +jobs: + run: + name: Respond to reports of a new problem + runs-on: ubuntu-latest + if: ${{ github.event.label.name == 'bug' }} + steps: + - name: Create a new Slack channel for communications + id: conversation + uses: slackapi/slack-github-action@v2.0.0 + with: + errors: true + method: conversations.create # https://api.slack.com/methods/conversations.create + token: ${{ secrets.SLACK_BOT_TOKEN }} + payload: | + name: issue-${{ github.event.issue.number }} + + - name: Send the issue link into the Slack channel + uses: slackapi/slack-github-action@v2.0.0 + with: + method: chat.postMessage # https://api.slack.com/methods/chat.postMessage + token: ${{ secrets.SLACK_BOT_TOKEN }} + payload: | + channel: ${{ steps.conversation.outputs.channel_id }} + text: "An issue was opened : ${{ github.event.issue.html_url }}" + + - name: Gather information of those to add + id: members + uses: slackapi/slack-github-action@v2.0.0 + with: + errors: true + method: usergroups.users.list # https://api.slack.com/methods/usergroups.users.list + token: ${{ secrets.SLACK_BOT_TOKEN }} + payload: | + usergroup: ${{ secrets.SLACK_USERGROUP_ID }} + + - name: Combine the list of usergroup users + run: | + SLACK_USERGROUP_USER_IDS=$(echo '${{ steps.members.outputs.response }}' | jq -r '.users | join(",")' ) + echo "SLACK_USERGROUP_USER_IDS=$SLACK_USERGROUP_USER_IDS" >> $GITHUB_ENV + + - name: Add the usergroup to the channel + uses: slackapi/slack-github-action@v2.0.0 + with: + errors: true + method: conversations.invite # https://api.slack.com/methods/conversations.invite + token: ${{ secrets.SLACK_BOT_TOKEN }} + payload: | + channel: ${{ steps.conversation.outputs.channel_id }} + users: ${{ env.SLACK_USERGROUP_USER_IDS }} diff --git a/example-workflows/Technique_2_Slack_App/JSON_payload.yml b/example-workflows/Technique_2_Slack_App/JSON_payload.yml deleted file mode 100644 index c4ee7b00..00000000 --- a/example-workflows/Technique_2_Slack_App/JSON_payload.yml +++ /dev/null @@ -1,32 +0,0 @@ -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@v2.0.0 - with: - token: ${{ secrets.SLACK_BOT_TOKEN }} - method: chat.postMessage - payload: | - channel: "C0123456789" - text: "messages make meeting" - blocks: - - type: "divider" - type: "image" - title: - type: "plain_text" - text: "Slack Slack Slack" - emoji: true - image_url: "https://media.makeameme.org/created/a-slack-this.jpg" - alt_text: "marg" - - type: "actions" - elements: - - type": "button" - text: - type: "plain_text" - text: "${{ github.sha }}" - url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" diff --git a/example-workflows/Technique_2_Slack_App/JSON_payload_as_text.yml b/example-workflows/Technique_2_Slack_App/JSON_payload_as_text.yml deleted file mode 100644 index 5ab0c5da..00000000 --- a/example-workflows/Technique_2_Slack_App/JSON_payload_as_text.yml +++ /dev/null @@ -1,16 +0,0 @@ -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@v2.0.0 - with: - method: chat.postMessage - token: ${{ secrets.SLACK_BOT_TOKEN }} - payload: | - text: "posting from a github action" - channel: "C0123456789" diff --git a/example-workflows/Technique_2_Slack_App/main.yml b/example-workflows/Technique_2_Slack_App/main.yml deleted file mode 100644 index e0e859dd..00000000 --- a/example-workflows/Technique_2_Slack_App/main.yml +++ /dev/null @@ -1,16 +0,0 @@ -on: [push] - -jobs: - new_push_job: - runs-on: ubuntu-latest - name: New push to repo - steps: - - name: Publish to slack channel via bot token - id: slack - uses: slackapi/slack-github-action@v2.0.0 - with: - method: chat.postMessage - token: ${{ secrets.SLACK_BOT_TOKEN }} - payload: | - channel: "C0123456789" - text: "posting from a github action!" diff --git a/example-workflows/Technique_3_Slack_Incoming_Webhook/README.md b/example-workflows/Technique_3_Slack_Incoming_Webhook/README.md new file mode 100644 index 00000000..1f81217a --- /dev/null +++ b/example-workflows/Technique_3_Slack_Incoming_Webhook/README.md @@ -0,0 +1,57 @@ +# Technique 3: Slack incoming webhook + +This technique uses this Action to post a message to a channel or direct message +with [incoming webhooks][incoming-webhook] and a Slack app. + +Incoming webhooks follow the same [formatting][formatting] patterns as other +Slack messaging APIs. Posted messages can be as short as a single line of text, +include additional interactivity with [interactive components][interactivity], +or be formatted with [Block Kit][block-kit] to build visual components. + +## Setup + +For details on how to setup this technique in GitHub Actions, read the +[`README.md`][setup]. + +## Example workflows + +1. [Post an inline text message](#post-an-inline-text-message) +2. [Post an inline block message](#post-an-inline-block-message) +3. [Post blocks found in a file](#post-blocks-found-in-a-file) + +### Post an inline text message + +Write a single world after a push event is received. + +This example uses incoming webhooks to post a plain text message. + +**Related files**: + +- [`text.yml`](./text.yml): GitHub Actions workflow. + +### Post an inline block message + +Format a response to recent adventures. + +This example uses incoming webhooks to post a message with Block Kit. + +**Related files**: + +- [`blocks.yml`](./blocks.yml): GitHub Actions workflow. + +### Post blocks found in a file + +Link to the GitHub Actions job in progress. + +This example uses file data when posting to an incoming webhook. + +**Related files**: + +- [`saved.data.json`](./saved.data.json): Payload file being sent. +- [`saved.gha.yml`](./saved.gha.yml): GitHub Actions workflow. + +[block-kit]: https://api.slack.com/surfaces/messages#complex_layouts +[formatting]: https://api.slack.com/reference/surfaces/formatting +[incoming-webhook]: https://api.slack.com/messaging/webhooks +[interactivity]: https://api.slack.com/messaging/interactivity +[setup]: https://github.com/slackapi/slack-github-action?tab=readme-ov-file#technique-3-slack-incoming-webhook diff --git a/example-workflows/Technique_3_Slack_Incoming_Webhook/main.yml b/example-workflows/Technique_3_Slack_Incoming_Webhook/blocks.yml similarity index 55% rename from example-workflows/Technique_3_Slack_Incoming_Webhook/main.yml rename to example-workflows/Technique_3_Slack_Incoming_Webhook/blocks.yml index eecb8dc8..b6909a98 100644 --- a/example-workflows/Technique_3_Slack_Incoming_Webhook/main.yml +++ b/example-workflows/Technique_3_Slack_Incoming_Webhook/blocks.yml @@ -1,34 +1,36 @@ -on: [push] +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +name: Post an inline block message +on: + push: + branches: + - main jobs: - new_push_job: + run: + name: Share a travel review to channel runs-on: ubuntu-latest - name: New push to repo steps: - - name: Send GitHub trigger payload to Slack Workflow Builder - id: slack + - name: Write the review uses: slackapi/slack-github-action@v2.0.0 with: webhook: ${{ secrets.SLACK_WEBHOOK_URL }} - webhook-type: webhook-trigger + webhook-type: incoming-webhook payload: | - "text": "Danny Torrence left a 1 star review for your property." - "blocks": + 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: { + 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." + text: " :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" + text: "*Average Rating*: 1.0" diff --git a/example-workflows/Technique_3_Slack_Incoming_Webhook/saved.data.json b/example-workflows/Technique_3_Slack_Incoming_Webhook/saved.data.json new file mode 100644 index 00000000..eb515117 --- /dev/null +++ b/example-workflows/Technique_3_Slack_Incoming_Webhook/saved.data.json @@ -0,0 +1,34 @@ +{ + "channel": "${{ env.SLACK_CHANNEL_ID }}", + "text": "Messages met made meetings meet", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Slack notifications sound following ${{ github.sha }}" + }, + "accessory": { + "type": "button", + "text": { + "type": "plain_text", + "text": "Inspect", + "emoji": true + }, + "value": "actions", + "url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.runId }}", + "action_id": "run" + } + }, + { + "type": "image", + "title": { + "type": "plain_text", + "text": "@slackbot has the answers", + "emoji": true + }, + "image_url": "https://media.makeameme.org/created/a-slack-this.jpg", + "alt_text": "Baby Yoda professes the power of a Slack meeting" + } + ] +} diff --git a/example-workflows/Technique_3_Slack_Incoming_Webhook/saved.gha.yml b/example-workflows/Technique_3_Slack_Incoming_Webhook/saved.gha.yml new file mode 100644 index 00000000..175bca7f --- /dev/null +++ b/example-workflows/Technique_3_Slack_Incoming_Webhook/saved.gha.yml @@ -0,0 +1,23 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Post blocks found in a file +on: + push: + branches: + - main +jobs: + run: + name: Share a travel review to channel + runs-on: ubuntu-latest + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Forward a saved message + uses: slackapi/slack-github-action@v2.0.0 + with: + payload-file-path: "./example-workflows/Technique_3_Slack_Incoming_Webhook/saved.data.json" + webhook: ${{ secrets.SLACK_WEBHOOK_URL }} + webhook-type: incoming-webhook diff --git a/example-workflows/Technique_3_Slack_Incoming_Webhook/text.yml b/example-workflows/Technique_3_Slack_Incoming_Webhook/text.yml new file mode 100644 index 00000000..d92af4ef --- /dev/null +++ b/example-workflows/Technique_3_Slack_Incoming_Webhook/text.yml @@ -0,0 +1,19 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Post an inline text message +on: + push: + branches: + - main +jobs: + run: + name: Leave a kind message after updates + runs-on: ubuntu-latest + steps: + - name: Greet the reader + uses: slackapi/slack-github-action@v2.0.0 + with: + webhook: ${{ secrets.SLACK_WEBHOOK_URL }} + webhook-type: incoming-webhook + payload: | + text: "Greetings!"