errbotio / err-backend-mattermost

GNU General Public License v3.0
42 stars 22 forks source link

Option to not add the bot to a team, and proper error handling if the bot doesn't belong to a team. #54

Open a-gerhard opened 2 years ago

a-gerhard commented 2 years ago

We run a chat bot that only messages users. There is no need for the bot to be in a team on our mattermost server.

davidlinc1 commented 1 year ago

For posterity as I'm sure @a-gerhard has moved on from this issue, but it seems like the requirement for a bot to be hard-coded to a specific team is not any sort of technical requirement, but a design decision that's enforced by a single if statement.

If you know what you're doing (which is essentially giving this bot access to every team, which may have unacceptable security implications for your use case), you can bypass it. Here's my workaround:

In err-backend-mattermost.py, I found this line:

        # In some cases (direct messages) team_id is an empty string
        if data["team_id"] != "" and self.teamid != data["team_id"]:
            log.info(
                "Message came from another team ({}), ignoring...".format(
                    data["team_id"]
                )
            )
            return

and above that, I added this line of code:

        # Adding this to bypass the following check.
        # Hacky, but had to make sure the bot can respond to messages across teams.
        self.teamid = data["team_id"]

So now, over in config.py, just put any existing team for BOT_IDENTITY. No matter where an event comes from, that check will think it came from the configured team.