So I am trying to send a message to a specific slack channel using a secrets.json
file to specify the payloads for both messages and the web-hook URL. I am able to post things to the message but it does not load the message as a payload even though the payload variable is set correctly. How can I load message payloads within the curl command I am specifying?
Here is the code:
richardbarret@1152-MBP ~/Git/SalesforceCLI/Integration/Slack master ● ./automated_messages.sh ✔ 1488 10:48:42
https://hooks.slack.com/services/XXXXXXXXX/XXXXXXX/XXXXXX
Webhook Variable is Working.
invalid_payload% richardbarret@1152-MBP ~/Git/SalesforceCLI/Integration/Slack master ● cat automated_messages.sh ✔ 1489 10:48:59
#!/bin/bash
# ===========================================================
# Created By: Richard Barrett
# Organization: Mirantis
# Department: Customer Success Operation
# Purpose: Send Message to Slack Channel
# Date: 03/20/2020
# ===========================================================
# System Variables
webhook_url=$(cat secrets.json | jq ".slack_config.slack_target_url" | tr -d \")
echo $webhook_url
printf "Webhook Variable is Working.\n"
message_1=$(cat secrets.json | jq ".slack_messages.message_1" | tr -d \")
message_2=$(cat secrets.json | jq ".slack_messages.message_2" | tr -d \")
message_3=$(cat secrets.json | jq ".slack_messages.message_3" | tr -d \")
# Use Messages in this command syntax
# Example
# curl -X POST -H 'Content-type: application/json' --data '{"text":"TEST TEXT BODY"}' $webhook_url
# General Message:
curl -X POST -H 'Content-type: application/json' --data '{"text":"$message_1"}' $webhook_url
# Messages for Handover:
#curl -X POST -H 'Content-type: application/json' --data '{"text":"Handovers: https://mirantis.my.salesforce.com/XXXXXXXXXXXXXXX"}' $webhook_url
# Message for All Change Requests:
#curl -X POST -H 'Content-type: application/json' --data '{"text":"All Change Requests: https://mirantis.my.salesforce.com/XXXXXXXXXXXX"}' $webhook_url
# Message for Change Requests in Ready to Execute
# curl -X POST -H 'Content-type: application/json' --data '{"text":"All CRs in Ready to Execute:"}' $webhook_url
I fixed the Invalid Payload
because I forgot to use the "text":
option within the --data
so I know that is not the issue. When I run the above script all that get's posted it the following:
So I tried deleting the quotations around $message_1
and got the message:
Webhook Variable is Working.
invalid_payload%
I deleted the Webhook response because it has a slack token. The webhook works, but the messages are not loading in the payload curl for the --data for some odd reason.
The secrets.json
looks like this:
{
"slack_config": {
"slack_target_url": "https://hooks.slack.com/services/XXXXXXX/XXXXXXXXXXX/XXXXXXXXXXXXXXX"
},
"slack_messages": {
"message_1": "SLACK_MESSAGE_1 Testing Secrets Calls from secrets.json File",
"message_3": "SLACK_MESSAGE_3 Testing Secrets Calls from secrets.json File",
"message_2": "SLACK_MESSAGE_2 Testing Secrets Calls from secrets.json File"
}
}