Skip to content

Commit

Permalink
Merge pull request attzonko#22 from thorlock12/update-method
Browse files Browse the repository at this point in the history
Add update message functionality attzonko#21
  • Loading branch information
gotlium authored Oct 27, 2016
2 parents 5b7d188 + b61040e commit f2d8cca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mattermost_bot/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@ def reply(self, text):
self.send(self._gen_reply(text))

def send(self, text, channel_id=None):
self._client.channel_msg(channel_id or self._body['channel_id'], text)
return self._client.channel_msg(channel_id or self._body['channel_id'],
text)

def update(self, text, message_id, channel_id=None):
return self._client.update_msg(
message_id, channel_id or self._body['channel_id'], text
)

def react(self, emoji_name):
self._client.channel_msg(
Expand Down
14 changes: 14 additions & 0 deletions mattermost_bot/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ def create_post(self, user_id, channel_id, message, files=None, pid=""):
'root_id': pid,
})

def update_post(self, message_id, user_id, channel_id, message, files=None, pid=""):
return self.post(
'/teams/%s/channels/%s/posts/update' % (self.team_id, channel_id),
{
'id': message_id,
'channel_id': channel_id,
'message': message,
})

def channel(self, channel_id):
return self.get('/teams/%s/channels/%s/' % (self.team_id, channel_id))

Expand Down Expand Up @@ -137,6 +146,11 @@ def channel_msg(self, channel, message, pid=""):
c_id = self.channels.get(channel, {}).get("id") or channel
return self.api.create_post(self.user["id"], c_id, message, pid=pid)

def update_msg(self, message_id, channel, message, pid=""):
c_id = self.channels.get(channel, {}).get("id") or channel
return self.api.update_post(message_id, self.user["id"],
c_id, message, pid=pid)

def get_users(self):
return self.api.get_profiles()

Expand Down

0 comments on commit f2d8cca

Please sign in to comment.