mattermost-community / mattermost-plugin-welcomebot

Apache License 2.0
64 stars 41 forks source link

Restricted Direct Message Setting in Server Breaks WelcomeBot #93

Open gohrner opened 1 year ago

gohrner commented 1 year ago

Environment (probably not relevant): Mattermost Team Server ESR 6.3.9, Welcomebot 1.2.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 and reacts 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:

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?).

So I wonder:

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.