slacktee
slacktee copied to clipboard
Post to thread
I needed some stuff to be posted into thread for my logging purposes on production, so I came up with the following:
- add a new function for parsing response:
function get_thread_ts() {
local response=$1
echo "$(echo "$response" | jq -r .message.ts)"
}
-
in function send_message() add to json "thread_ts": "$thread_ts",
(var $thread_ts can be empty, slack will ignore it) -
in function send_message() execute get_thread_ts in else part:
if [[ $(get_ok_in_response "$post_result") != "true" ]]; then
write_to_stderr "$post_result"
exit_code=1
else
get_thread_ts "$post_result"
fi
- in main() add thread_ts for uploading files:
upload_result="$(curl -F file=@"$filename" -F token="$token" $channels_param -F thread_ts="$thread_ts" https://slack.com/api/files.upload 2> /dev/null)"
- add reading $thread_ts with -r key in parse_args()
And now I can do stuff like this:
thread_ts=$(echo anything|slacktee -q)
echo something|slacktee -r $thread_ts
Supporting thread is a cool idea and I appreciate your implementation proposal. Let me consider about the idea!