rtCamp / action-slack-notify

GitHub Action for sending a notification to a Slack channel
https://github.com/rtCamp/github-actions-library
MIT License
1.09k stars 230 forks source link

Unable to add variables to SLACK_CUSTOM_PAYLOAD #205

Open jdrcodes opened 1 month ago

jdrcodes commented 1 month ago

Hello!

I am trying to make an automation when a user creates a pull request that sends a message to a Slack Channel.

SLACK_CUSTOM_PAYLOAD only admits an string that has to be a JSON, but when I use variables it always returns an 400 error and it does not work, even though the log replaces correctly the variables.

SLACK_CUSTOM_PAYLOAD: | { "author": "${{ steps.set-payload.outputs.PAYLOAD_AUTHOR }}", "ticket_link": "Example text", "pr_link": "Example text", "description": "Example text", "title": "Example text" }

Log:

SLACK_CUSTOM_PAYLOAD: { "author": "jdrcodes", "ticket_link": "Example text", "pr_link": "Example text", "description": "Example text", "title": "Example text" }

Any ideas?

Error sending message: Error on message: 400 Bad Request

L0RD-ZER0 commented 1 month ago

Hello there! I took a look at this payload and it doesn't seem quite right. Might help taking a look at Slack's Advanced Message Formatting, and for further reading, it might help looking at Slack's Message Payloads.

For some of the variables you're trying to set, there are equivalent environment variables such as for author, you can use SLACK_MSG_AUTHOR to specify author. You can find a reference list of all the variables in the readme.

You can specify them using environment variables in the following manner:

env:
    SLACK_MESSAGE_AUTHOR: "${{ steps.set-payload.outputs.PAYLOAD_AUTHOR }}"