aboutsummaryrefslogtreecommitdiff
path: root/connector/mattermost
diff options
context:
space:
mode:
Diffstat (limited to 'connector/mattermost')
-rw-r--r--connector/mattermost/mattermost.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go
index 12ac604..52eb40f 100644
--- a/connector/mattermost/mattermost.go
+++ b/connector/mattermost/mattermost.go
@@ -243,7 +243,7 @@ func (mm *Mattermost) Leave(roomId RoomID) {
// Not supported? TODO
}
-func (mm *Mattermost) Send(event *Event) error {
+func (mm *Mattermost) Send(event *Event) (string, error) {
post := &model.Post{
Message: event.Text,
}
@@ -254,29 +254,29 @@ func (mm *Mattermost) Send(event *Event) error {
if event.Room != "" {
ch, err := mm.checkRoomId(event.Room)
if err != nil {
- return err
+ return "", err
}
post.ChannelId = ch
} else if event.Recipient != "" {
ui, err := mm.checkUserId(event.Recipient)
if err != nil {
- return err
+ return "", err
}
_, resp := mm.conn.Client.CreateDirectChannel(mm.conn.User.Id, ui)
if resp.Error != nil {
- return resp.Error
+ return "", resp.Error
}
channelName := model.GetDMNameFromIds(ui, mm.conn.User.Id)
err = mm.conn.UpdateChannels()
if err != nil {
- return err
+ return "", err
}
post.ChannelId = mm.conn.GetChannelId(channelName, "")
} else {
- return fmt.Errorf("Invalid target")
+ return "", fmt.Errorf("Invalid target")
}
if event.Attachments != nil {
@@ -284,28 +284,28 @@ func (mm *Mattermost) Send(event *Event) error {
for _, file := range event.Attachments {
rdr, err := file.Read()
if err != nil {
- return err
+ return "", err
}
defer rdr.Close()
data, err := ioutil.ReadAll(rdr)
if err != nil {
- return err
+ return "", err
}
up_file, err := mm.conn.UploadFile(data, post.ChannelId, file.Filename())
if err != nil {
log.Warnf("UploadFile error: %s", err)
- return err
+ return "", err
}
post.FileIds = append(post.FileIds, up_file)
}
}
- _, resp := mm.conn.Client.CreatePost(post)
+ created_post, resp := mm.conn.Client.CreatePost(post)
if resp.Error != nil {
log.Warnf("CreatePost error: %s", resp.Error)
- return resp.Error
+ return "", resp.Error
}
- return nil
+ return created_post.Id, nil
}
func (mm *Mattermost) Close() {