You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Go调用Mattermost SDK发送优先级消息失败,求解决方案

解决Mattermost机器人发送带原生优先级标记的消息问题

你之前通过post.AddProp("priority", priority)添加的是自定义帖子属性,Mattermost客户端不会将其识别为原生的优先级标记。要实现客户端GUI中的优先级标识,需要直接设置model.Post结构体的Priority字段——这是Mattermost官方定义的、用于识别消息优先级的字段。

修改后的代码示例

将原代码中添加自定义属性的逻辑替换为直接设置Priority字段即可:

func sendMessage(logger zerolog.Logger, client *model.Client4, message string, channelID string, priority string) error {

    post := &model.Post{
        ChannelId: channelID,
        Message:   message,
        Priority:  priority, // 直接设置原生优先级字段
    }
    // 移除原有的 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
}

注意事项

  • 传入的priority必须是Mattermost支持的有效值:"urgent"、"high"、"normal"(默认值)
  • 确保你的Mattermost服务器版本为v6及以上(与你使用的SDK版本匹配),该版本原生支持优先级消息功能
  • 若使用新版SDK github.com/mattermost/mattermost/server/public/model,代码逻辑完全一致,Post结构体同样包含Priority字段

内容的提问来源于stack exchange,提问作者Alexey Nakhimov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 21:35:11