aboutsummaryrefslogtreecommitdiffstats
path: root/warmachine/connections/slack.py
diff options
context:
space:
mode:
authorjason2016-08-09 15:58:03 -0600
committerjason2016-08-09 15:58:03 -0600
commit3debc34c3d659f5f4849b585917513a8eaea4138 (patch)
treedfa5a0c2ef0216d59767e0a2cc02970c92221779 /warmachine/connections/slack.py
parentb915ef41c19a6eb4cb5f80e2f5f52b835afa9a53 (diff)
downloadwarmachine-ng-3debc34c3d659f5f4849b585917513a8eaea4138.tar.gz
warmachine-ng-3debc34c3d659f5f4849b585917513a8eaea4138.zip
add standup messaging
- message all users in a channel asking for their standup - continue messaging the users until they reply to the standup
Diffstat (limited to 'warmachine/connections/slack.py')
-rw-r--r--warmachine/connections/slack.py44
1 files changed, 28 insertions, 16 deletions
diff --git a/warmachine/connections/slack.py b/warmachine/connections/slack.py
index 845b5c8..0ef39dc 100644
--- a/warmachine/connections/slack.py
+++ b/warmachine/connections/slack.py
@@ -78,24 +78,9 @@ class SlackWS(Connection):
78 """ 78 """
79 Say something in the provided channel or IM by id 79 Say something in the provided channel or IM by id
80 """ 80 """
81
82 # If the destination is a user, figure out the DM channel id 81 # If the destination is a user, figure out the DM channel id
83 if destination_id.startswith('U'): 82 if destination_id.startswith('U'):
84 url = 'https://slack.com/api/im.open?{}'.format(urlencode({ 83 destination_id = self.get_dm_id_by_user(destination_id)
85 'token': self.token,
86 'user': destination_id,
87 }))
88
89 req = urllib.request.Request(url)
90 r = urllib.request.urlopen(req).read().decode('utf-8')
91
92 data = json.loads(r)
93
94 if not data['ok']:
95 raise Exception(data)
96 return
97
98 destination_id = data['channel']['id']
99 84
100 await self._send(json.dumps({ 85 await self._send(json.dumps({
101 'id': 1, # TODO: this should be a get_msgid call or something 86 'id': 1, # TODO: this should be a get_msgid call or something
@@ -224,6 +209,33 @@ class SlackWS(Connection):
224 )) 209 ))
225 self.user_map[msg['user']]['presence'] = msg['presence'] 210 self.user_map[msg['user']]['presence'] = msg['presence']
226 211
212 def get_dm_id_by_user(self, user_id):
213 """
214 Return the channel id for a direct message to a specific user.
215
216 Args:
217 user_id (str): slack user id
218
219 Return:
220 str: DM channel id for the provided user. None on error
221 """
222 url = 'https://slack.com/api/im.open?{}'.format(urlencode({
223 'token': self.token,
224 'user': user_id,
225 }))
226
227 req = urllib.request.Request(url)
228 r = urllib.request.urlopen(req).read().decode('utf-8')
229
230 data = json.loads(r)
231
232 if not data['ok']:
233 raise Exception(data)
234 return
235
236 return data['channel']['id']
237
238
227 def get_users_by_channel(self, channel): 239 def get_users_by_channel(self, channel):
228 url = 'https://slack.com/api/groups.info?{}'.format(urlencode( 240 url = 'https://slack.com/api/groups.info?{}'.format(urlencode(
229 { 241 {