docs: showcase updated use cases in example workflows (#376)
Co-authored-by: Luke Russell <[email protected]>
This commit is contained in:
co-authored by
Luke Russell
parent
6a5a811bd0
commit
e6e5eb1093
@@ -164,7 +164,7 @@ achieved by adding this step to a job in your GitHub workflow and inviting the
|
||||
bot associated with your app to the channel for posting:
|
||||
|
||||
```yaml
|
||||
- name: Post to a Slack channel
|
||||
- name: Post text to a Slack channel
|
||||
uses: slackapi/[email protected]
|
||||
with:
|
||||
method: chat.postMessage
|
||||
@@ -180,7 +180,7 @@ More complex message layouts, such as messages made with [Block Kit][block-kit]
|
||||
blocks, can also be sent with one of the Slack API methods:
|
||||
|
||||
```yaml
|
||||
- name: Post to a Slack channel
|
||||
- name: Post blocks to a Slack channel
|
||||
uses: slackapi/[email protected]
|
||||
with:
|
||||
method: chat.postMessage
|
||||
@@ -203,7 +203,7 @@ outputs from past steps as inputs to current ones:
|
||||
|
||||
```yaml
|
||||
- name: Initiate the deployment launch sequence
|
||||
id: slack
|
||||
id: launch_sequence
|
||||
uses: slackapi/[email protected]
|
||||
with:
|
||||
method: chat.postMessage
|
||||
@@ -226,7 +226,7 @@ outputs from past steps as inputs to current ones:
|
||||
token: ${{ secrets.SLACK_BOT_TOKEN }}
|
||||
payload: |
|
||||
channel: ${{ secrets.SLACK_CHANNEL_ID }}
|
||||
ts: "${{ steps.slack.outputs.ts }}"
|
||||
ts: "${{ steps.launch_sequence.outputs.ts }}"
|
||||
text: "Deployment finished! :rocket:"
|
||||
attachments:
|
||||
- color: "28a745"
|
||||
@@ -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"
|
||||
```
|
||||
|
||||
@@ -307,6 +307,12 @@ Gather a Slack incoming webhook URL:
|
||||
6. [Add this Action as a step][job-step] to your GitHub workflow and provide an
|
||||
input payload to send as a message.
|
||||
|
||||
The webhook URL will resemble something like so:
|
||||
|
||||
```txt
|
||||
https://hooks.slack.com/services/T0123456789/B1001010101/7IsoQTrixdUtE971O1xQTm4T
|
||||
```
|
||||
|
||||
#### Usage
|
||||
|
||||
Add the collected webhook from above to a GitHub workflow and configure the step
|
||||
@@ -342,7 +348,7 @@ The `errors` option defaults to `false` so failed requests do not cause the step
|
||||
to fail. This result can still be gathered from the `ok` output.
|
||||
|
||||
```yaml
|
||||
- name: Send GitHub Action data to a Slack workflow
|
||||
- name: Attempt to call an unknown method
|
||||
uses: slackapi/[email protected]
|
||||
with:
|
||||
errors: true
|
||||
@@ -366,7 +372,7 @@ The `payload-delimiter` option will flatten the input payload using the provided
|
||||
delimiter and will also make values stringified:
|
||||
|
||||
```yaml
|
||||
- name: Send GitHub Action data to a Slack workflow
|
||||
- name: Flatten the default GitHub payload
|
||||
uses: slackapi/[email protected]
|
||||
with:
|
||||
payload-delimiter: "_"
|
||||
@@ -385,7 +391,6 @@ input payload with the `payload-templated` option:
|
||||
|
||||
```yaml
|
||||
- name: Send custom JSON data to Slack workflow
|
||||
id: slack
|
||||
uses: slackapi/[email protected]
|
||||
with:
|
||||
payload-file-path: "./payload-slack-content.json"
|
||||
|
||||
@@ -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/[email protected]
|
||||
with:
|
||||
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
webhook-type: webhook-trigger
|
||||
payload: |
|
||||
key: value
|
||||
foo: bar
|
||||
@@ -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/[email protected]
|
||||
with:
|
||||
payload-file-path: "./example-workflows/Technique_1_Slack_Workflow_Builder/payloads/example.json"
|
||||
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
webhook-type: webhook-trigger
|
||||
@@ -0,0 +1,81 @@
|
||||
# Technique 1: Slack Workflow Builder
|
||||
|
||||
> :memo: This technique uses Workflow Builder, which requires
|
||||
> [a Slack paid plan][plans].
|
||||
|
||||
This technique sends data to Slack using a webhook to start a workflow created
|
||||
using Slack [Workflow Builder][wfb].
|
||||
|
||||
## Setup
|
||||
|
||||
The Slack app manifest included with each example showcases steps of a workflow
|
||||
in [Workflow Builder][wfb] along with the [webhook trigger][triggers] inputs.
|
||||
|
||||
For details on how to setup this technique in GitHub Actions, read the
|
||||
[`README.md`][setup].
|
||||
|
||||
## Example workflows
|
||||
|
||||
1. [**Format generated files**](#format-generated-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 hardcoded channel.
|
||||
|
||||
**Related files**:
|
||||
|
||||
- [`builds.data.json`](./builds.data.json): Payload file being sent.
|
||||
- [`builds.gha.yml`](./builds.gha.yml): GitHub Actions workflow.
|
||||
- [`builds.manifest.json`](./builds.manifest.json): Slack app manifest.
|
||||
- [`builds.trigger.json`](./builds.trigger.json): Slack webhook trigger.
|
||||
|
||||
### Post release announcements
|
||||
|
||||
Select a channel to post news about the most recent release to.
|
||||
|
||||
This example uses [Slack functions][functions] and inline inputs to do the
|
||||
following:
|
||||
|
||||
1. Open a form to select a channel.
|
||||
2. Send a message to the selected channel.
|
||||
3. React with a `:tada:` emoji.
|
||||
|
||||
**Related files**:
|
||||
|
||||
- [`announcements.gha.yml`](./announcements.gha.yml): GitHub Actions workflow.
|
||||
- [`announcements.manifest.json`](./announcements.manifest.json): Slack app
|
||||
manifest.
|
||||
- [`announcements.trigger.json`](./announcements.trigger.json): Slack webhook
|
||||
trigger.
|
||||
|
||||
### Update a channel topic
|
||||
|
||||
Show the latest commit status in the header of a channel.
|
||||
|
||||
This example uses the default GitHub event [context][event-context] and
|
||||
[payload][event-payload] 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.
|
||||
- [`topic.trigger.json`](./topic.trigger.json): Slack webhook trigger.
|
||||
|
||||
[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
|
||||
[triggers]: https://api.slack.com/automation/triggers/webhook
|
||||
[update_channel_topic]: https://api.slack.com/reference/functions/update_channel_topic
|
||||
[wfb]: https://slack.com/features/workflow-automation
|
||||
@@ -0,0 +1,22 @@
|
||||
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
|
||||
|
||||
name: Post release announcements
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
jobs:
|
||||
run:
|
||||
name: Share recent changes with a channel
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Draft with these release notes details
|
||||
uses: slackapi/[email protected]
|
||||
with:
|
||||
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
webhook-type: webhook-trigger
|
||||
payload: |
|
||||
"draft_channel": "${{ secrets.SLACK_CHANNEL_ID }}",
|
||||
"release_notes": ${{ toJSON(github.event.release.body) }},
|
||||
"release_repository": "${{ github.repository }}",
|
||||
"release_version": "${{ github.event.release.tag_name }}",
|
||||
@@ -0,0 +1,113 @@
|
||||
{
|
||||
"_metadata": {
|
||||
"major_version": 2
|
||||
},
|
||||
"display_information": {
|
||||
"name": "Slack GitHub Actions Releaser",
|
||||
"description": "Sharing the latest news in channel"
|
||||
},
|
||||
"features": {
|
||||
"app_home": {
|
||||
"messages_tab_enabled": false
|
||||
},
|
||||
"bot_user": {
|
||||
"display_name": "Slack GitHub Actions Releaser"
|
||||
}
|
||||
},
|
||||
"oauth_config": {
|
||||
"scopes": {
|
||||
"bot": ["chat:write", "chat:write.public", "reactions:write"]
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"org_deploy_enabled": true
|
||||
},
|
||||
"workflows": {
|
||||
"release_announcement": {
|
||||
"title": "Release announcement",
|
||||
"description": "Share excitement around the latest changes",
|
||||
"input_parameters": {
|
||||
"properties": {
|
||||
"draft_channel": {
|
||||
"type": "slack#/types/channel_id"
|
||||
},
|
||||
"release_notes": {
|
||||
"type": "string"
|
||||
},
|
||||
"release_repository": {
|
||||
"type": "string"
|
||||
},
|
||||
"release_version": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"draft_channel",
|
||||
"release_notes",
|
||||
"release_repository",
|
||||
"release_version"
|
||||
]
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"id": "0",
|
||||
"function_id": "slack#/functions/send_message",
|
||||
"inputs": {
|
||||
"channel_id": "{{inputs.draft_channel}}",
|
||||
"message": "A new release of <https://github.com/{{inputs.release_repository}}/releases/tag/{{inputs.release_version}}|{{inputs.release_repository}}@{{inputs.release_version}}> was tagged! :rocket:",
|
||||
"interactive_blocks": [
|
||||
{
|
||||
"type": "actions",
|
||||
"elements": [
|
||||
{
|
||||
"type": "button",
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": "Share"
|
||||
},
|
||||
"action_id": "share"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "1",
|
||||
"function_id": "slack#/functions/open_form",
|
||||
"inputs": {
|
||||
"title": "Share the release notes",
|
||||
"interactivity": "{{steps.0.interactivity}}",
|
||||
"submit_label": "Share",
|
||||
"fields": {
|
||||
"elements": [
|
||||
{
|
||||
"name": "announcement_channel",
|
||||
"title": "Select an announcements channel",
|
||||
"type": "slack#/types/channel_id"
|
||||
}
|
||||
],
|
||||
"required": ["announcement_channel"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"function_id": "slack#/functions/send_message",
|
||||
"inputs": {
|
||||
"channel_id": "{{steps.1.fields.announcement_channel}}",
|
||||
"message": "A new release of <https://github.com/{{inputs.release_repository}}/releases/tag/{{inputs.release_version}}|{{inputs.release_repository}}@{{inputs.release_version}}> was tagged! :rocket:\n```{{inputs.release_notes}}```"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"function_id": "slack#/functions/add_reaction",
|
||||
"inputs": {
|
||||
"message_context": "{{steps.2.message_context}}",
|
||||
"emoji": "tada"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"type": "webhook",
|
||||
"name": "Release webhook",
|
||||
"description": "Share the most recent changes",
|
||||
"workflow": "#/workflows/release_announcement",
|
||||
"inputs": {
|
||||
"draft_channel": {
|
||||
"value": "{{data.draft_channel}}"
|
||||
},
|
||||
"release_notes": {
|
||||
"value": "{{data.release_notes}}"
|
||||
},
|
||||
"release_repository": {
|
||||
"value": "{{data.release_repository}}"
|
||||
},
|
||||
"release_version": {
|
||||
"value": "{{data.release_version}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"status": "done",
|
||||
"task": "Downstream staging rollout",
|
||||
"errors": "",
|
||||
"runner": "github-actions"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
|
||||
|
||||
name: Format generated files
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
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/[email protected]
|
||||
with:
|
||||
payload-file-path: "./example-workflows/Technique_1_Slack_Workflow_Builder/builds.data.json"
|
||||
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
webhook-type: webhook-trigger
|
||||
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"_metadata": {
|
||||
"major_version": 2
|
||||
},
|
||||
"display_information": {
|
||||
"name": "Slack GitHub Actions Builder",
|
||||
"description": "Sharing the latest builds in channel"
|
||||
},
|
||||
"features": {
|
||||
"app_home": {
|
||||
"messages_tab_enabled": false
|
||||
},
|
||||
"bot_user": {
|
||||
"display_name": "Slack GitHub Actions Builder"
|
||||
}
|
||||
},
|
||||
"oauth_config": {
|
||||
"scopes": {
|
||||
"bot": ["chat:write", "chat:write.public"]
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"org_deploy_enabled": true
|
||||
},
|
||||
"workflows": {
|
||||
"build_outputs": {
|
||||
"title": "Build outputs",
|
||||
"description": "Write details of the most recent build",
|
||||
"input_parameters": {
|
||||
"properties": {
|
||||
"errors": {
|
||||
"type": "string"
|
||||
},
|
||||
"runner": {
|
||||
"type": "string"
|
||||
},
|
||||
"status": {
|
||||
"type": "string"
|
||||
},
|
||||
"task": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["errors", "runner", "status", "task"]
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"id": "0",
|
||||
"function_id": "slack#/functions/send_message",
|
||||
"inputs": {
|
||||
"channel_id": "C0123456789",
|
||||
"message": [
|
||||
{
|
||||
"type": "rich_text",
|
||||
"elements": [
|
||||
{
|
||||
"type": "rich_text_section",
|
||||
"elements": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "{{inputs.task}}: ",
|
||||
"style": {
|
||||
"bold": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"text": "{{inputs.status}}",
|
||||
"style": {
|
||||
"code": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "rich_text_quote",
|
||||
"elements": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "{{inputs.errors}} \n"
|
||||
},
|
||||
{
|
||||
"type": "emoji",
|
||||
"name": "robot_face"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"text": " {{inputs.runner}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"type": "webhook",
|
||||
"name": "Status sharing",
|
||||
"description": "Update a channel with build results",
|
||||
"workflow": "#/workflows/build_outputs",
|
||||
"inputs": {
|
||||
"errors": {
|
||||
"value": "{{data.errors}}"
|
||||
},
|
||||
"runner": {
|
||||
"value": "{{data.runner}}"
|
||||
},
|
||||
"status": {
|
||||
"value": "{{data.status}}"
|
||||
},
|
||||
"task": {
|
||||
"value": "{{data.task}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
-14
@@ -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/[email protected]
|
||||
with:
|
||||
payload-delimiter: "_"
|
||||
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
webhook-type: webhook-trigger
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"text": "${{ github.workflow }} workflow failed on ${{ env.DEFAULT_BRANCH }} branch in the ${{ github.event.repository.name }} repository!"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
|
||||
|
||||
name: Update a channel topic
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
run:
|
||||
name: Keep track of the main branch
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Update the channel topic
|
||||
uses: slackapi/[email protected]
|
||||
with:
|
||||
payload-delimiter: "_"
|
||||
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
webhook-type: webhook-trigger
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"_metadata": {
|
||||
"major_version": 2
|
||||
},
|
||||
"display_information": {
|
||||
"name": "Slack GitHub Actions Commits",
|
||||
"description": "Reading the latest pushes"
|
||||
},
|
||||
"features": {
|
||||
"app_home": {
|
||||
"messages_tab_enabled": false
|
||||
},
|
||||
"bot_user": {
|
||||
"display_name": "Slack GitHub Actions Commits"
|
||||
}
|
||||
},
|
||||
"oauth_config": {
|
||||
"scopes": {
|
||||
"bot": ["channels:manage", "groups:write.topic"]
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"org_deploy_enabled": true
|
||||
},
|
||||
"workflows": {
|
||||
"follow_recent_commits": {
|
||||
"title": "Follow recent commits",
|
||||
"description": "Write details of the most recent build",
|
||||
"input_parameters": {
|
||||
"properties": {
|
||||
"commit_message": {
|
||||
"type": "string"
|
||||
},
|
||||
"commit_repository": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["commit_message", "commit_repository"]
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"id": "0",
|
||||
"function_id": "slack#/functions/update_channel_topic",
|
||||
"inputs": {
|
||||
"channel_id": "C0123456789",
|
||||
"topic": ":large_green_square: *{{inputs.commit_repository}}* {{inputs.commit_message}}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"type": "webhook",
|
||||
"name": "Status sharing",
|
||||
"description": "Update a channel with commit details",
|
||||
"workflow": "#/workflows/follow_recent_commits",
|
||||
"inputs": {
|
||||
"commit_message": {
|
||||
"value": "{{data.payload_head_commit_message}}"
|
||||
},
|
||||
"commit_repository": {
|
||||
"value": "{{data.payload_repository_full_name}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Technique 2: Slack API method
|
||||
|
||||
A [token][tokens], such as a bot or user token, must be used to call one of
|
||||
[the Slack API methods][methods] with this technique.
|
||||
|
||||
## Setup
|
||||
|
||||
For details on how to set up 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
|
||||
@@ -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/[email protected]
|
||||
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/[email protected]
|
||||
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: <https://github.com/${{ github.repository }}|*${{ github.repository }}*>: `${{ github.sha }}`"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": ${{ toJSON(github.event.head_commit.message) }}
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -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/[email protected]
|
||||
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/[email protected]
|
||||
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 <!date^${{ steps.conversation.outputs.time }}^{date_num} at {time_secs}|just now>: ${{ github.event.issue.html_url }}"
|
||||
|
||||
- name: Gather information of those to add
|
||||
id: members
|
||||
uses: slackapi/[email protected]
|
||||
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/[email protected]
|
||||
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 }}
|
||||
@@ -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/[email protected]
|
||||
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 }}"
|
||||
@@ -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/[email protected]
|
||||
with:
|
||||
method: chat.postMessage
|
||||
token: ${{ secrets.SLACK_BOT_TOKEN }}
|
||||
payload: |
|
||||
text: "posting from a github action"
|
||||
channel: "C0123456789"
|
||||
@@ -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/[email protected]
|
||||
with:
|
||||
method: chat.postMessage
|
||||
token: ${{ secrets.SLACK_BOT_TOKEN }}
|
||||
payload: |
|
||||
channel: "C0123456789"
|
||||
text: "posting from a github action!"
|
||||
@@ -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 line of text 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
|
||||
+15
-13
@@ -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/[email protected]
|
||||
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: "<https://example.com|Overlook Hotel> \\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: "<https://example.com|*Overlook Hotel*> :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"
|
||||
@@ -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 the most recent commit pushed `${{ github.sha }}`"
|
||||
},
|
||||
"accessory": {
|
||||
"type": "button",
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": "Inspect",
|
||||
"emoji": true
|
||||
},
|
||||
"value": "actions",
|
||||
"url": "https://github.com/${{ github.payload.repository.full_name }}/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"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# 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/[email protected]
|
||||
with:
|
||||
payload-file-path: "./example-workflows/Technique_3_Slack_Incoming_Webhook/saved.data.json"
|
||||
payload-templated: true
|
||||
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
webhook-type: incoming-webhook
|
||||
env:
|
||||
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
|
||||
@@ -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/[email protected]
|
||||
with:
|
||||
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
webhook-type: incoming-webhook
|
||||
payload: |
|
||||
text: "Greetings!"
|
||||
Reference in New Issue
Block a user