Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ resolution <cea|dmt [modes]> sets the screen resolution
system [cpu|ram|disk|volt|temperature] display real system informations
message gitter <apitoken|authorize> sets api/channel info in config file and sends/recieves message
<send|show|read|mark>
slack <apitoken|send> sets api/channel info in config file and sends message
slack <apitoken|send|channels> sets api/channel info in config file and sends message
shutdown [now|in|force] shutdown the system
```

Expand Down
1 change: 1 addition & 0 deletions _treehouses
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ treehouses message gitter show
treehouses message gitter read
treehouses message gitter mark
treehouses message slack apitoken
treehouses message slack channels
treehouses message slack send
treehouses networkmode
treehouses networkmode info
Expand Down
2 changes: 1 addition & 1 deletion modules/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ resolution <cea|dmt [modes]> sets the screen resolution
system [cpu|ram|disk|volt|temperature] display real system informations
message gitter <apitoken|authorize> sets api/channel info in config file and sends/recieves message
<send|show|read|mark>
slack <apitoken|send> sets api/channel info in config file and sends message
slack <apitoken|send|channels> sets api/channel info in config file and sends message
shutdown [now|in|force] shutdown the system
EOF
echo "$helpdefault"
Expand Down
23 changes: 17 additions & 6 deletions modules/message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,33 @@ function message {
apitoken)
if [[ $3 != "" ]]; then
tempVar=$(echo $3 | cut -d "-" -f 1)
if [[ $tempVar == "xoxp" ]]; then
if [[ $tempVar != "xoxp" ]]; then
log_comment_and_exit1 "invalid token"
else
conf_var_update "slack_apitoken" "$3"
echo "your apitoken is $3"
else
log_comment_and_exit1 "invalid token"
fi
elif check_apitoken slack; then
get_apitoken slack
else
echo "You do not have an authorized access token for slack"
echo ""
echo "To get an authorized access token"
echo ""
echo "Navigate to https://api.slack.com/apps and create an APP. Provide a name for the APP and select the \"Development Slack Workspace (eg : Open Learning Exchange)\" from the drop down list"
echo "Go to \"OAuth & Permission\" under \"features \" and select the scope under \"User Token Scopes\" and add \"chat:write\" for the APP from the drop down list"
echo "Then install APP to the workspace and click the allow button to give permissions in the redirected link and then you will get the \"OAuth access token\""
echo "Run $BASENAME message slack apitoken <oauth access token>"
fi
;;
channels)
if check_apitoken slack; then
list=$(curl -s -F token=$access_token https://slack.com/api/conversations.list)
channel_names=$(echo $list | python -m json.tool | jq '.channels[].name' | tr -d '"')
echo "Channels names:"
echo "$channel_names"
else
log_comment_and_exit1 "Error: You do not have an authorized access token" "To get access token, run $BASENAME message slack apitoken"
fi
;;
send)
channel=$3
if check_apitoken slack; then
Expand All @@ -246,7 +255,6 @@ function message {
fi
shift; shift; shift;
message=$*
echo "$message"
message_response=$(curl -s -X POST -H 'Authorization: Bearer '$access_token'' -H 'Content-type: application/json' --data "{\"channel\":\"$channel\",\"text\":\"$message\"}" https://slack.com/api/chat.postMessage)
message_response=$(echo $message_response | python -m json.tool | jq '.ok' | tr -d '"')
if [[ $message_response == "true" ]]; then
Expand Down Expand Up @@ -301,6 +309,9 @@ function message_help {
echo " $BASENAME message slack apitoken"
echo " check for API token for slack"
echo
echo " $BASENAME message slack channels"
echo " check for channels"
echo
echo " $BASENAME message slack send \"channel_name or channel ID\" \"Hi, you are very awesome\""
echo " Sends a message to a slack channel using channel name, eg, channel: #channel_name"
echo
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@treehouses/cli",
"version": "1.24.82",
"version": "1.24.83",
"remote": "4000",
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
"main": "cli.sh",
Expand Down