{"record":{"id":"9ae85e1da767274d","repo":"mattermost-community/focalboard","slug":"cannot-get-direct-channel-w","errorCode":null,"errorMessage":"cannot get direct channel: %w","messagePattern":"cannot get direct channel: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/services/notify/plugindelivery/mention_deliver.go","lineNumber":24,"sourceCode":"import (\n\t\"fmt\"\n\n\t\"github.com/mattermost/focalboard/server/services/notify\"\n\t\"github.com/mattermost/focalboard/server/utils\"\n\n\tmm_model \"github.com/mattermost/mattermost/server/public/model\"\n)\n\n// MentionDeliver notifies a user they have been mentioned in a blockv ia the plugin API.\nfunc (pd *PluginDelivery) MentionDeliver(mentionedUser *mm_model.User, extract string, evt notify.BlockChangeEvent) (string, error) {\n\tauthor, err := pd.api.GetUserByID(evt.ModifiedBy.UserID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"cannot find user: %w\", err)\n\t}\n\n\tchannel, err := pd.getDirectChannel(evt.TeamID, mentionedUser.Id, pd.botID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"cannot get direct channel: %w\", err)\n\t}\n\tlink := utils.MakeCardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID, evt.Card.ID)\n\tboardLink := utils.MakeBoardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID)\n\n\tpost := &mm_model.Post{\n\t\tUserId:    pd.botID,\n\t\tChannelId: channel.Id,\n\t\tMessage:   formatMessage(author.Username, extract, evt.Card.Title, link, evt.BlockChanged, boardLink, evt.Board.Title),\n\t}\n\n\tif _, err := pd.api.CreatePost(post); err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn mentionedUser.Id, nil\n}\n","sourceCodeStart":6,"sourceCodeEnd":41,"githubUrl":"https://github.com/mattermost-community/focalboard/blob/a84bbb65e32edf972856b329417096ac413518e9/server/services/notify/plugindelivery/mention_deliver.go#L6-L41","documentation":"MentionDeliver returns this error when getDirectChannel fails to create or fetch the direct message channel between the bot and the mentioned user via the Mattermost plugin API. Without the channel the mention DM cannot be posted. The underlying plugin API error is wrapped with %w.","triggerScenarios":"A mentioned user is valid but the plugin cannot open a direct channel: the mentioned user is deactivated, the bot user lacks permission to create DM channels, or the Mattermost plugin API call fails (server unreachable, rate limited).","commonSituations":"Deactivated or archived mentioned users; bot account misconfiguration (missing bot role/permissions); Mattermost server restarts or plugin API latency; LDAP/SAML-synced users not yet provisioned locally.","solutions":["Verify the mentioned user is active and can receive DMs","Check the bot account has permissions to create direct channels","Inspect the wrapped cause (errors.As/Is) for the plugin API error details","Confirm plugin/bot configuration in Mattermost system console"],"exampleFix":"// before\nchannel, err := pd.getDirectChannel(evt.TeamID, mentionedUser.Id, pd.botID)\nif err != nil {\n\treturn \"\", fmt.Errorf(\"cannot get direct channel: %w\", err)\n}\n// after\nchannel, err := pd.getDirectChannel(evt.TeamID, mentionedUser.Id, pd.botID)\nif err != nil {\n\tif model.IsErrNotFound(err) {\n\t\treturn \"\", nil // user cannot receive DMs; skip silently\n\t}\n\treturn \"\", fmt.Errorf(\"cannot get direct channel: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// ensure mentioned user is active before mention delivery\nmentioned, err := pd.api.GetUser(mentionedUser.Id)\nif err != nil || mentioned.DeleteAt != 0 {\n\t// skip: user cannot receive DMs\n}","typeGuard":"func canReceiveDM(u *mm_model.User) bool {\n\treturn u != nil && u.DeleteAt == 0\n}","tryCatchPattern":"msg, err := pd.MentionDeliver(mentionedUser, extract, evt)\nif err != nil {\n\tvar targetErr error\n\tif errors.As(err, &targetErr) && model.IsErrNotFound(targetErr) {\n\t\treturn \"\", nil // no DM possible; skip silently\n\t}\n\treturn \"\", err\n}","preventionTips":["Verify the bot account has permissions to create DM channels","Skip delivery for deactivated/archived mentioned users","Ensure plugin completes OnActivate before handling notify events","Check Mattermost server connectivity if channel creation fails in bursts"],"tags":["go","mattermost-plugin","channels","notifications"],"backgroundTag":"dm-channel-creation-failed","analyzedSha":"a84bbb65e32edf972856b329417096ac413518e9","analyzedAt":"2026-08-30T09:22:20.720Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}