Add all users to the channel

Hi
Add all users to the channel using wildcards, example @*?
How to do it? Is there such a possibility?

Hi @brrrr66 ,

unfortunately this is not possible at the moment. If you want to add all local users to a channel, you’d have to either use the API or a small script using the mmctl tool to do that.

Thanks!
I looked through mctl, but it also needs an enumeration, as far as I understood. Get a list and then add users.

Did so. I don’t know how it will be if there are > 50 users :slight_smile:

We open “direct messages” and copy all users right from there. The “@” shows All users.
Then we go into the channel and send a message with this list. We will be asked to add the missing ones to the channel.
Screenshot_2023-03-15_11-16-12_2

Yes, but you can script it and it’s basically just one command then to add all users into a new channel if you’ve prepared the script properly.
Clicking through all of them manually works too, of course, but as you said, the more users you have, the harder it gets doing it manually.

1 Like

Do you have an example of such a script on mmctl?

Assuming you only have one team named “test”:

# Create Channel "teamhuddle" in team "test"
# mmctl --local channel create --team test --name teamhuddle --display-name teamhuddle
New channel teamhuddle successfully created

# Add all active users to this channel
# mmctl --local channel users add test:teamhuddle $(mmctl --local user list --all --json 2>/dev/null | jq -r '.[] | select (.delete_at ==0) | .username' | xargs )
#
1 Like

Thanks!
All working! Really had to download the local version of mmctl, I the using docker “sudo docker run -it mattermost/mattermost-team-edition:latest /bin/sh” and there was no “jq” command in the container :slight_smile:
Also I removed the parameter "–local, I connect remotely.
Swore when adding on, as I understand it, system users. I think it’s not critical :slight_smile:

$ ~/bin/mmctl channel users add teamtest:test1 $(~/bin/mmctl user list --all --json 2>/dev/null | jq -r '.[] | select (.delete_at ==0) | .username' | xargs )
Unable to add 'appsbot' to test1. Error: : No team member found for that user ID and team ID., resource: TeamMember id: teamId=okcpj9czktrgmpkke9g41pa6fh, userId=dt7ntcjp3jff9brgtcxgqutoyo
Unable to add 'boards' to test1. Error: : No team member found for that user ID and team ID., resource: TeamMember id: teamId=okcpj9czktrgmpkke9g41pa6fh, userId=a9g8x3dd7bf1ukfb5xu96mpx3a
Unable to add 'calls' to test1. Error: : No team member found for that user ID and team ID., resource: TeamMember id: teamId=okcpj9czktrgmpkke9g41pa6fh, userId=3g9xc9krmbnefqqy566d3dxrne
Unable to add 'channel-recommender' to test1. Error: : No team member found for that user ID and team ID., resource: TeamMember id: teamId=okcpj9czktrgmpkke9g41pa6fh, userId=sx4osxcgqb8y7g8umk47haq18w
Unable to add 'channelexport' to test1. Error: : No team member found for that user ID and team ID., resource: TeamMember id: teamId=okcpj9czktrgmpkke9g41pa6fh, userId=fqebgodaztd3zx868s468cskdr
Unable to add 'feedbackbot' to test1. Error: : No team member found for that user ID and team ID., resource: TeamMember id: teamId=okcpj9czktrgmpkke9g41pa6fh, userId=x1f9fxmz8fyc7g1u1354w7tsxw
Unable to add 'playbooks' to test1. Error: : No team member found for that user ID and team ID., resource: TeamMember id: teamId=okcpj9czktrgmpkke9g41pa6fh, userId=awya86f197frjygtg99d6rxx8o
Unable to add 'system-bot' to test1. Error: : No team member found for that user ID and team ID., resource: TeamMember id: teamId=okcpj9czktrgmpkke9g41pa6fh, userId=zrktr1kdnbftin7mrh4m171h5h
Unable to add 'welcomebot' to test1. Error: : No team member found for that user ID and team ID., resource: TeamMember id: teamId=okcpj9czktrgmpkke9g41pa6fh, userId=78hdqiak8bdj5jm48unrprwrfw

Yes, the warnings for the bot accounts are OK, I did not ignore them in the command, but we could do that but anyways… it gets the job done and these few warnings can be ignored :slight_smile:

Geat, so thanks for the feedback, will mark this issue as resolved now.

1 Like

Very good input @agriesser , unfortunately in my scenario I can’t get the script to work.

First of all, I run things on Docker. Well, not a big deal, I thought I’d simply exec into the container and run mmctl from there.
This works in principle, but apparently jq isn’t part of the image and I don’t seem to be able to install it.

Anyway, next I thought I’d compile the list of user on my host and copy over to the docker image instead of the second mmctl in your oneliner:
sudo docker exec mattermost-app mmctl --local user list --all --json 2>/dev/null | jq -r '.[] | select (.delete_at ==0) | .username' > users

This gave me the raw userlist, one user per line, which I copied over to the docker image via docker cp.
But now I am stuck with the fact that my team name has got a blank in it’s name, at least that’s what I think the issue is.
mmctl --local channel users add 'Kreis Biberach':Workshops-Materialien $(cat /tmp/users | xargs) Error: unable to find channel "Kreis Biberach:Workshops-Materialien"

How would I reflect this:

Name
Workshops-Materialien
Team
Kreis Biberach

In the mmctl command? I tried several combinations of " and ’ with no success I am afraid.

Edit:
Found a solution, turns out that the name of my team isn’t the same as what’s being displayed in the MM client.
Found the real name with sudo docker exec mattermost-app mmctl --local team list

docker is the same thing as sudo, just prepend it to the commands where necessary and use formaters and other stuff from the “outside”, in that case, you can use jq or xargs from the host.
The above commands work for docker containers using this slightly modified version:

docker exec -ti <container> mmctl --local channel create --team test --name teamhuddle --display-name teamhuddle
docker exec -ti <container> mmctl --local channel users add test:teamhuddle $(docker exec -ti <container> mmctl --local user list --all --json 2>/dev/null | jq -r '.[] | select (.delete_at ==0) | .username' | xargs )

The command in the $() block will run first and only the mmctl command will be run inside the container, the output will then be parsed on your host directly (the | jq... part) and the resulting list of usernames will then again be send to the second docker exec command (which is at the beginning of the command).

1 Like