From 833236d40fe859db091583519f35c9d696f62b01 Mon Sep 17 00:00:00 2001 From: Cryptoval Trading Technologies Date: Sat, 7 Feb 2026 23:47:55 +0000 Subject: [PATCH] moved send_mmost.sh --- send_mmost.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 send_mmost.sh diff --git a/send_mmost.sh b/send_mmost.sh new file mode 100755 index 0000000..fc52218 --- /dev/null +++ b/send_mmost.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +channel_name=${1} +if [ "" == "${channel_name}" ] +then + echo "Usage: ${0} " + exit 1 +fi + +url=$(jq -r '.MATTERMOST.url' ${HOME}/.creds) +team=$(jq -r '.MATTERMOST.team' ${HOME}/.creds) +bearer=$(jq -r '.MATTERMOST.bearer' ${HOME}/.creds) + +#lowercase channel +channel_name=$(echo "${channel_name}" | awk '{print tolower($0)}') +# space to '-' +channel_name=${channel_name//" "/"-"} + +get_channel_url="${url}/api/v4/teams/name/${team}/channels/name/${channel_name}" + +Cmd="curl -s" +Cmd="${Cmd} -X GET" +Cmd="${Cmd} -H \"Content-Type: Application/JSON\"" +Cmd="${Cmd} -H \"Authorization: Bearer ${bearer}\"" +Cmd="${Cmd} ${get_channel_url}" +Cmd="${Cmd} | jq -r '.id'" + +channel_id=$(eval ${Cmd}) + +input="$(cat)" + +body="{" +body="${body}\"channel_id\":\"${channel_id}\"" +body="${body}, \"message\":\"${input}\"" +body="${body}}" + +# replace new line with literal \n +body=$(echo "${body}" |awk '{printf "%s\\n", $0}') + +post_url="${url}/api/v4/posts" + +Cmd="curl -s" +Cmd="${Cmd} --request POST" +Cmd="${Cmd} --header \"Content-Type: Application/JSON\"" +Cmd="${Cmd} --header \"Authorization: Bearer ${bearer}\"" +Cmd="${Cmd} --data @-" +Cmd="${Cmd} ${post_url}" + +(echo "${body}" | eval ${Cmd}) > /dev/null +