forked from GoogleCloudPlatform/professional-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_help_message.py
executable file
·72 lines (63 loc) · 3.13 KB
/
post_help_message.py
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
72
#!/usr/bin/env python3
# Copyright 2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import slack
import logging
logger = logging.getLogger(__name__)
def post_help_message(channel_id, user_id, context):
"""
Informs the user of the app's available commands.
Parameters
----------
channel_id : str
unique string used to idenify a Slack channel. Used to send messages to the channel
user_id : str
the Slack user_id of the user who submitted the request. Used to send ephemeral
messages to the user
context : str
Extra information to go with the help message. Usually a statement of a command
not existing
"""
client = slack.WebClient(token=os.environ.get('SLACK_TOKEN'))
client.chat_postEphemeral(
channel=channel_id,
user=user_id,
text=f"{context}Here are the available commands:"
"\n/google-cloud-support track-case [case number] -- case updates will be"
" posted to this channel"
"\n/google-cloud-support add-comment [case number] [comment] -- adds a comment"
" to the case"
"\n/google-cloud-support change-priority [case number] [priority, e.g. P1] --"
" changes the priority of the case"
"\n/google-cloud-support subscribe [case number] [email 1] ... [email n] --"
" subscribes the given emails addresses to the case to receive updates"
" to their inboxes. This overwrites the previous list of emails"
"\n/google-cloud-support escalate [case number] [reason] [justification] --"
" escalates the support case. Reason must be either RESOLUTION_TIME,"
" TECHNICAL_EXPERTISE, or BUSINESS_IMPACT"
"\n/google-cloud-support close-case [case number] -- closes a case"
"\n/google-cloud-support stop-tracking [case number] -- case updates will no"
" longer be posted to this channel"
"\n/google-cloud-support list-tracked-cases -- lists all cases being tracked"
" in this channel"
"\n/google-cloud-support list-tracked-cases-all -- lists all cases being"
" tracked in the workspace"
"\n/google-cloud-support case-details [case_number] -- pull all of the case"
" data as json"
"\n/google-cloud-support sitrep -- report of all active cases in the org")
if __name__ == "__main__":
channel_id = os.environ.get('TEST_CHANNEL_ID')
user_id = os.environ.get('TEST_USER_ID')
context = 'This is a test of the post_help_message function. '
post_help_message(channel_id, user_id, context)