slacktee icon indicating copy to clipboard operation
slacktee copied to clipboard

Post to thread

Open ky4k0b opened this issue 3 years ago • 1 comments

I needed some stuff to be posted into thread for my logging purposes on production, so I came up with the following:

  1. add a new function for parsing response:
function get_thread_ts() {
    local response=$1
    echo "$(echo "$response" | jq -r .message.ts)"
}
  1. in function send_message() add to json "thread_ts": "$thread_ts",
    (var $thread_ts can be empty, slack will ignore it)

  2. 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
  1. 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)"
  2. 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

ky4k0b avatar Jun 02 '21 01:06 ky4k0b

Supporting thread is a cool idea and I appreciate your implementation proposal. Let me consider about the idea!

Chikashi-Kato avatar Jun 02 '21 02:06 Chikashi-Kato