forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-slack-DND-status.sh
executable file
·71 lines (54 loc) · 1.6 KB
/
set-slack-DND-status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# API: https://slack.com/api/dnd.setSnooze
# Parameters
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Set DND Status
# @raycast.mode silent
# Optional parameters:
# @raycast.packageName Slack
# @raycast.argument1 { "type": "text", "placeholder": "number of minutes", "percentEncoded": true, "optional": true}
# @raycast.icon images/slack-logo.png
# Documentation:
# @raycast.description Set your DND status in Slack
# @raycast.author Sam Ching
# @raycast.authorURL https://github.com/samching
# Configuration
# To create a new API token, do the following:
# 1. Create a new Slack app at https://api.slack.com/authentication/basics
# 2. Add `dnd:write` to the user token scopes
# 3. Install the app to your workplace
# 4. Insert your OAuth access token below
API_TOKEN="XXXXXX"
# Default expiration (in mins)
DEFAULT_STATUS_EXPIRATION_IN_MINUTES=30
# Minutes until the the status will expire
STATUS_EXPIRATION_IN_MINUTES="${1}"
# Main program
if [[ -z "$API_TOKEN" ]]
then
echo "No API token provided"
exit 1
fi
if [[ -z "$STATUS_EXPIRATION_IN_MINUTES" ]]
then
STATUS_EXPIRATION_IN_MINUTES=$DEFAULT_STATUS_EXPIRATION_IN_MINUTES # default expiration
fi
RESPONSE=$(
curl \
--header "Content-Type: application/x-www-form-urlencoded" \
--request POST \
--data "token=$API_TOKEN&num_minutes=$STATUS_EXPIRATION_IN_MINUTES" \
--silent \
--show-error \
--fail \
"https://slack.com/api/dnd.setSnooze"
)
if [[ "$RESPONSE" =~ "error" ]]
then
echo "Failed to set status in Slack"
exit 1
else
echo "Turned DND on in Slack for $STATUS_EXPIRATION_IN_MINUTES" minutes
exit 0
fi