Skip to content

Commit

Permalink
MM-58134- Disconnect should not be ephemeral message (#648)
Browse files Browse the repository at this point in the history
* disconnect should not be ephemeral message

* lint fix
  • Loading branch information
sbishel authored May 15, 2024
1 parent f7ffaf2 commit 1292481
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions server/bot_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func (p *Plugin) handlePromptForConnection(userID, channelID string) {
// For now, don't display the connect message

// message := "Some users in this conversation rely on Microsoft Teams to receive your messages, but your account isn't connected. "
// p.SendConnectMessage(channelID, userID, message)
// p.SendEphemeralConnectMessage(channelID, userID, message)
}

func (p *Plugin) SendConnectMessage(channelID string, userID string, message string) {
func (p *Plugin) SendEphemeralConnectMessage(channelID string, userID string, message string) {
postID := model.NewId()
connectURL := fmt.Sprintf(p.GetURL()+"/connect?post_id=%s&channel_id=%s", postID, channelID)
connectMessage := fmt.Sprintf("[Click here to connect your account](%s)", connectURL)
Expand All @@ -42,6 +42,28 @@ func (p *Plugin) SendConnectMessage(channelID string, userID string, message str
}
p.API.SendEphemeralPost(userID, post)
}
func (p *Plugin) SendConnectMessage(channelID string, userID string, message string) {
post := &model.Post{
Message: message,
UserId: p.GetBotUserID(),
ChannelId: channelID,
}
if err := p.apiClient.Post.CreatePost(post); err != nil {
p.GetAPI().LogWarn("Failed to create connection post", "user_id", userID, "error", err)
return
}

connectURL := fmt.Sprintf(p.GetURL()+"/connect?post_id=%s&channel_id=%s", post.Id, channelID)
connectMessage := fmt.Sprintf("[Click here to connect your account](%s)", connectURL)
if len(message) > 0 {
connectMessage = message + " " + connectMessage
}

post.Message = connectMessage
if err := p.apiClient.Post.UpdatePost(post); err != nil {
p.GetAPI().LogWarn("Failed to update connection post", "user_id", userID, "error", err)
}
}

func (p *Plugin) SendConnectBotMessage(channelID string, userID string) {
postID := model.NewId()
Expand Down
2 changes: 1 addition & 1 deletion server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (p *Plugin) executeConnectCommand(args *model.CommandArgs) (*model.CommandR
}
}

p.SendConnectMessage(args.ChannelId, args.UserId, "")
p.SendEphemeralConnectMessage(args.ChannelId, args.UserId, "")
return &model.CommandResponse{}, nil
}

Expand Down

0 comments on commit 1292481

Please sign in to comment.