I want to send message with priority from my bot on GO. I using github.com/mattermost/mattermost-server/v6/model
module. I tried many different options, but nothing worked. All messages come as usual, without priority, as it can be done in the GUI of the native client.
Here is the code from my last attempt. Can you please tell me how to solve this problem?
package main
import (
.....
"github.com/mattermost/mattermost-server/v6/model"
.....
)
func sendMessage(logger zerolog.Logger, client *model.Client4, message string, channelID string, priority string) error {
post := &model.Post{
ChannelId: channelID,
Message: message,
}
post.AddProp("priority", priority)
_, resp, err := client.CreatePost(post)
if err != nil {
logger.Error().Err(err).Msg("Message sending error")
return fmt.Errorf("Message sending error: %v", err)
}
if resp.StatusCode != 201 {
logger.Error().Int("status", resp.StatusCode).Msg("Failed to send message")
return fmt.Errorf("Failed to send message. Status: %d", resp.StatusCode)
}
return nil
}
.....
func main() {
.....
err := sendMessage(logger.With().Str("channel", ch.Name).Logger(), client, message, ch.ChannelID, "urgent")
.....
}
I tried using a newer module - github.com/mattermost/mattermost/server/public/model
Nothing worked either.
Thank you very much in advance!
I found a solution to the problem myself:
post := &model.Post{
ChannelId: channelID,
Message: message,
Metadata: &model.PostMetadata{
Priority: &model.PostPriority{Priority: &priority},
},
}