Add support for editing messages (slack)

This commit is contained in:
Wim 2017-08-28 20:29:02 +02:00
parent 7c773ebae0
commit 8b98f605bc

View File

@ -163,14 +163,17 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
np.IconURL = msg.Avatar np.IconURL = msg.Avatar
} }
np.Attachments = append(np.Attachments, slack.Attachment{CallbackID: "matterbridge"}) np.Attachments = append(np.Attachments, slack.Attachment{CallbackID: "matterbridge"})
b.sc.PostMessage(schannel.ID, message, np) // 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)
newmsg := b.rtm.NewOutgoingMessage(message, schannel.ID) b.sc.UpdateMessage(schannel.ID, ts[1], message)
b.rtm.SendMessage(newmsg)
*/
return "", nil 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 { func (b *Bslack) getAvatar(user string) string {
@ -233,7 +236,7 @@ func (b *Bslack) handleSlack() {
text = b.replaceURL(text) text = b.replaceURL(text)
text = html.UnescapeString(text) text = html.UnescapeString(text)
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account) 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" { if message.Raw.SubType == "me_message" {
msg.Event = config.EVENT_USER_ACTION msg.Event = config.EVENT_USER_ACTION
} }
@ -241,6 +244,10 @@ func (b *Bslack) handleSlack() {
msg.Username = "system" msg.Username = "system"
msg.Event = config.EVENT_JOIN_LEAVE 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 b.Remote <- msg
} }
} }