Skip to content

Commit

Permalink
Send invite message as bot message, not ephemeral (#607)
Browse files Browse the repository at this point in the history
* send invite message as bot message, not ephemeral

* update connect message

* check error

* cleanup

* edit post message to not set id
  • Loading branch information
sbishel authored Apr 17, 2024
1 parent 0253e60 commit 9c70367
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
12 changes: 11 additions & 1 deletion server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,17 @@ func (a *API) oauthRedirectHandler(w http.ResponseWriter, r *http.Request) {
UserId: a.p.GetBotUserID(),
CreateAt: model.GetMillis(),
}
_ = a.p.GetAPI().UpdateEphemeralPost(mmUser.Id, post)

_, appErr = a.p.GetAPI().GetPost(stateArr[2])
if appErr == nil {
_, appErr = a.p.GetAPI().UpdatePost(post)
if appErr != nil {
a.p.API.LogWarn("Unable to update post", "post", post.Id, "error", err.Error())
}
} else {
_ = a.p.GetAPI().UpdateEphemeralPost(mmUser.Id, post)
}

connectURL := a.p.GetURL() + "/primary-platform"
http.Redirect(w, r, connectURL, http.StatusSeeOther)
}
Expand Down
24 changes: 19 additions & 5 deletions server/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,30 @@ func (p *Plugin) SendInviteMessage(user *model.User, pendingSince time.Time, cur
invitedUser.InvitePendingSince = currentTime
}

if err := p.store.StoreInvitedUser(invitedUser); err != nil {
return errors.Wrapf(err, "error storing user in invite list")
}

channel, err := p.apiClient.Channel.GetDirect(user.Id, p.userID)
if err != nil {
return errors.Wrapf(err, "failed to get bot DM channel with user_id %s", user.Id)
}

message := fmt.Sprintf("@%s, you're invited to use the MS Teams connected experience. ", user.Username)
p.SendConnectMessage(channel.Id, user.Id, message)
invitePost := &model.Post{
Message: message,
UserId: p.userID,
ChannelId: channel.Id,
}
if err := p.apiClient.Post.CreatePost(invitePost); err != nil {
return errors.Wrapf(err, "error sending bot message")
}

connectURL := fmt.Sprintf(p.GetURL()+"/connect?post_id=%s&channel_id=%s", invitePost.Id, channel.Id)
invitePost.Message = fmt.Sprintf("%s [Click here to connect your account](%s)", invitePost.Message, connectURL)
if err := p.apiClient.Post.UpdatePost(invitePost); err != nil {
return errors.Wrapf(err, "error sending bot message")
}

if err := p.store.StoreInvitedUser(invitedUser); err != nil {
return errors.Wrapf(err, "error storing user in invite list")
}

return nil
}
Expand Down

0 comments on commit 9c70367

Please sign in to comment.