Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Feb 9, 2022 · 1 comment

Comments

@a-gerhard
Copy link

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.

  • If the bot is not in the configured team (and not a mattermost admin), this line https://github.com/errbotio/err-backend-mattermost/blob/master/mattermost.py#L346 will throw an error. You should add a proper error message what is wrong. Removing this one line allowed our bot to run perfectly until I took a bit deeper into the issue.
  • You should add an option for the bot to not belong to a team, e.g., by leaving the team empty.
@davidlinc1
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants