This discussion centers on automating user group assignments in Discourse based on the value of a custom user field, particularly for use cases like segmenting condo owners vs. renters or service providers vs. seekers. kstaikov proposed the feature, noting that while email-domain-based auto-grouping exists, custom field-based grouping would be more useful for their community. riking suggested manual group membership, but kstaikov countered that it’s unrealistic for non-tech-savvy users. li-zi shared a workaround using webhooks and the Discourse API via an Express.js server to auto-assign groups upon user creation based on custom field values. weallwegot asked if this solution was open-sourced and later suggested using the Custom Wizard plugin to achieve similar results by triggering group assignments after wizard submission. Finally, JammyDodger confirmed the feature is now officially supported via the ‘Add user to group through custom field’ Automation script, with documentation available here. The feature is now marked as completed, supporting dropdown and confirmation fields, with text fields requiring exact matches.
When creating a group, we have the automatic membership setting based on a user’s email domain name. I would like to have this functionality based on the value of a custom field.
Example Use Case
I have a condo community with a dropdown custom field signifying ownership status (Owner, Renter). I want to have all owners automatically in an owner group and to be able to message only all owners for certain messages.
Caveats
This sounds straight forward for dropdown and confirmation custom fields, but I guess could get hairy for text fields. It would be fine to enable it only for dropdowns and confirmations, otherwise exact text match is fine for text fields.
Since these are user settable custom fields, you can just make the groups open membership and tell people to add / remove themselves via the /groups page.
Not realistic for my use case. Hard to get a bunch of random homeowners, some very old, to bother going around tinkering with their settings. It was hard enough getting them to just register once to get the emails, and it’s hard to even get them to pay attention and do stuff even when there are financial penalties.
For anybody coming across this in the future: I had a similar use case (two distinct user populations – people offering services vs. people seeking services) and ended up implementing it via webhooks and the Discourse API.
More specifically, I…
created a webhook triggered on user events
implemented a barebones Express.js server to receive the payload
set up a POST route for user_created events that checks the value of a custom user field, and then uses the Discourse API to set the user’s group accordingly
This seems like kind of a goofy way to do it because I’m going outside Discourse to modify something within Discourse, but I scoured the forum for answers to this and came up with nothing, so I did my best! Hope this helps someone in the future, and if anyone comes up with a better way of doing it, I’d love to know.
I’m looking to do something very similar to this for auto-segmenting users into groups based on a custom User Field dropdown. Did you happen to open-source this?
@li-zi i know you kind of solved this for your case already, but it seems to me that one other potential solution is to use the Custom Wizard plugin.
I use this to prompt new users to fill out the wizard after signing up.
The wizard has some fields that offer dropdown options.
Then i set up two separate actions to complete after the wizard is submitted:
one to update the user profile custom fields with the wizard field from the drop down
another action to add user to specific group based on the wizard field selection