Misbehaviour of Welcomebot and Restricted Direct Message Setting in Server

Hi all,

I already started pulling my hair out because welcomebot just would not work for me. Fortunately before becoming bald I found the cause, but am not sure whether its a bug in welcomebot, a bug in Mattermost server, or if I just missed some documentation - can anyone enlighten me on this?

Once I better know the background, I’ll create a bug report, if appropriate.

Environment (probably not relevant): Mattermost Team Server ESR 6.3.9, Welcomebot 0.7.0.

There are multiple Teams on the server.

Welcomebot was configured and running and I remember it already worked in the past. It also reacted to /welcomebot commands.

However, it did NOT (any more) send any welcome message to new users, did NOT add the new users to channels, and did NOT send configured welcome messages to users joining channels with welcome message.

The server logs showed an error message when a user joined, which didn’t really help me:

{"timestamp":"2022-07-11 19:15:43.993 +02:00","level":"error","msg":"failed to query direct message channel","caller":"app/plugin_api.go:928","plugin_id":"com.mattermost.welcomebot","user_id":"xxxxxxxxxxxxxxxxxxxx"}

Fortunately, during debuggin I then tried channel-specific welcome messages I had never used before, and these triggered a more helpful error message:

{"timestamp":"2022-07-12 06:41:34.823 +02:00","level":"info","msg":"{\"level\":\"error\",\"msg\":\"error occured while creating direct channel to the user\",\"fields\":[{\"Key\":\"UserId\",\"Type\":15,\"Integer\":0,\"String\":\"xxxxxxxxxxxxxxxxxxxx\",\"Interface\":null},{\"Key\":\"error\",\"Type\":25,\"Integer\":0,\"String\":\"\",\"Interface\":{\"id\":\"api.channel.create_channel.direct_channel.team_restricted_error\",\"message\":\"A direct channel cannot be created between these users because they do not share a team in common.\",\"detailed_error\":\"\",\"status_code\":403}}]}\n","caller":"io/io.go:425","plugin_id":"com.mattermost.welcomebot","source":"plugin_stderr"}

Actually my server has following setting enabled:

"RestrictDirectMessage": "team"

This was the culprit, after disabling this setting, Welcomebot suddenly worked.

Using the CLI, I was able to add the welcomebot account to the relevant teams, and then it continued to work after re-enabling this setting.

However, several things are fishy here:

  • According to this setting’s description in the GUI, it should ONLY affect the UI and now have any influence on server side permissions:

    ‘Any member of the team’ limits the ability in the Direct Messages ‘More’ menu to only open Direct Message channels with users who are in the same team. Note: This setting only affects the UI, not permissions on the server.
    Don’t get me wrong, I think permission checking on the server would actually be important for this setting, it’s just that the help text does not seem to match implemented behaviour (any more?).

  • I could not find any hint / warning anywhere that the behaviour of Welcomebot would be influenced by this setting, and also didn’t find any configuration instructions for any special measures to take if this setting is enabled.

So I wonder:

  • Did I miss some instructions somewhere?
  • Would Welcomebot be supposed to work “automatically” despite RestrictDirectMessage being enabled? Is this some misconfiguration in my instance (and if so, how could it happen)?
  • May there be other integrations / plugins be affected by this setting?
  • Is it a correct / official solution to add bot accounts to teams using the CLI, or would the correct solution be different?

Maybe someone with more insight into Mattermost permissions / bot accounts can shed some light into this.

From my current understanding, I see at least two documentation bugs:

  1. The help text for the RestrictDirectMessage setting is wrong, it actually DOES influence permission checking on the server.
  2. Welcomebot lacks information about the RestrictDirectMessage setting in its setup documentation, and that additional steps are required like manually adding welcomebot to the Teams it shall be active on.
  • Or is the problem a different one, and shouldn’t the server check Direct Message permissions?
  • Or maybe bot accounts should be excluded from this check?
  • Or maybe the Welcome bot plugin should add the welcomebot account to all Teams mentioned in the config.json automatically?

Hi,

did you pick the welcomebot plugin version correctly? Checking github I see the latest version is 1.2.0 which should work with Mattermost server 5.12.0+

I’m referring to https://github.com/mattermost/mattermost-plugin-welcomebot

From documentation the welcomebot must be enabled for each team in config.json. Is that configured?
Maybe this is related to the team a user is added to, when he/she first logs in.

Sorry, typo - I have 1.2.0 installed. I somehow confused the version number with the version of another installed plugin.
Marketplace says that the WelcomeBot plugin is up to date.

Yes, WelcomeBot is activated for the team in question.

I fear that probable most instanced don’t have "RestrictDirectMessage": "team" enabled…

I now reported the misbehaviours: