summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-08-28 20:29:02 +0200
committerWim <wim@42.be>2017-08-28 20:29:02 +0200
commit8b98f605bc1d961ce3afa6ff84ed02e9b5112727 (patch)
treef198c29c836b22e3f7bd3928158b8b8b1b0f4549
parent7c773ebae018ccb9cdf4ae3f21cbe34ffb23cbfe (diff)
downloadmatterbridge-msglm-8b98f605bc1d961ce3afa6ff84ed02e9b5112727.tar.gz
matterbridge-msglm-8b98f605bc1d961ce3afa6ff84ed02e9b5112727.tar.bz2
matterbridge-msglm-8b98f605bc1d961ce3afa6ff84ed02e9b5112727.zip
Add support for editing messages (slack)
-rw-r--r--bridge/slack/slack.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index edbb668f..31d441a9 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -163,14 +163,17 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
np.IconURL = msg.Avatar
}
np.Attachments = append(np.Attachments, slack.Attachment{CallbackID: "matterbridge"})
- b.sc.PostMessage(schannel.ID, message, np)
-
- /*
- newmsg := b.rtm.NewOutgoingMessage(message, schannel.ID)
- b.rtm.SendMessage(newmsg)
- */
-
- return "", nil
+ // if we have no ID it means we're creating a new message, not updating an existing one
+ if msg.ID != "" {
+ ts := strings.Fields(msg.ID)
+ b.sc.UpdateMessage(schannel.ID, ts[1], message)
+ return "", nil
+ }
+ _, id, err := b.sc.PostMessage(schannel.ID, message, np)
+ if err != nil {
+ return "", err
+ }
+ return "slack " + id, nil
}
func (b *Bslack) getAvatar(user string) string {
@@ -233,7 +236,7 @@ func (b *Bslack) handleSlack() {
text = b.replaceURL(text)
text = html.UnescapeString(text)
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)
- msg := config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username), UserID: message.UserID}
+ msg := config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username), UserID: message.UserID, ID: "slack " + message.Raw.Timestamp}
if message.Raw.SubType == "me_message" {
msg.Event = config.EVENT_USER_ACTION
}
@@ -241,6 +244,10 @@ func (b *Bslack) handleSlack() {
msg.Username = "system"
msg.Event = config.EVENT_JOIN_LEAVE
}
+ // edited messages have a submessage, use this timestamp
+ if message.Raw.SubMessage != nil {
+ msg.ID = "slack " + message.Raw.SubMessage.Timestamp
+ }
b.Remote <- msg
}
}