Custom Use Case
You will often want to send notifications in a format other than the one that action-slack has determined.
In such a case, consider using status: custom.
If you specify a payload in accordance with the slack specification, action-slack will notify you as it is.
Use status: custom and custom_payload to customize notifications to your liking.
steps: - uses: h3y6e/action-slack@v4 with: status: custom custom_payload: | { text: "Custom Field Check", attachments: [{ "author_name": "h3y6e@action-slack", // json fallback: 'fallback', color: 'good', title: 'CI Result', text: 'Succeeded', fields: [{ title: 'lower case', value: 'LOWER CASE CHECK'.toLowerCase(), short: true }, { title: 'reverse', value: 'gnirts esrever'.split('').reverse().join(''), short: true }, { title: 'long title1', value: 'long value1', short: false }], actions: [{ }] }] } env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredAs you can see, the JavaScript functionality is available in the custom_payload. (e.g. toLowerCase())
We have even more options for those who want to use custom notifications, but want to use the Fields feature.
steps: - uses: h3y6e/action-slack@v4 with: status: custom fields: workflow,job,commit,repo,ref,author,took custom_payload: | { attachments: [{ color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', text: `${process.env.AS_WORKFLOW}\n${process.env.AS_JOB} (${process.env.AS_COMMIT}) of ${process.env.AS_REPO}@${process.env.AS_REF} by ${process.env.AS_AUTHOR} ${{ job.status }} in ${process.env.AS_TOOK}`, }] } env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} if: always() # Pick up events even if the job fails or is canceled.You can access the values retrieved by Fields through environment variables. See Fields for the available environment variables.
