Group membership scripting

I’m the admin for a organization’s forum with several levels of membership, which correspond to custom group membership in the forum. Currently this requires a manual process for every new member where I get the new members email address, check to see if that is associated with a user account and then add them to the custom group.

What I would like is a script that would take a list of email addresses, and if there is a user with that address add them to a group and if not send out an invite with the group permission already added. How would I write a script like that?

Thanks!

EDIT:

Example from below:
I have these three email address:
alice@example.com - Belongs to a forum member who is not a group member of SomeGroup
bob@foo.org - Belongs to a forum member who is a member of SomeGroup
carol@bar.edu - Does not belong to a forum member.

I’d like to add the user associated with alice@example.com to SomeGroup (and send a welcome message), do nothing for the user bob@foo.org, and send a forum invite with the group enrollment flag to carol@bar.edu.

1 Like

You can configure the group so if a user signs up with a certain email domain (The @example.com) they would be automatically added to a group.

Go to the mange tab of the group, membership then the first section Automatic add the domain.

Thanks, but that doesn’t really help here. Our members all use their personal email for this, so they don’t have the same domain.

1 Like

You can set up an invite link and send it to customers but this will only work if they have not signed up yet I believe.

Go to the Members tab then press invite configure the invite and press Save invite.

If you send an invite link it will also work for existing members. :+1: You can even direct them to a particular topic to land on when they arrive, so it can be good for group enrolment, or events.

There’s also the bulk invite feature if you already have a list of addresses?

2 Likes

Didn’t know. I will look at the wiki and it only said upon account creation. Can you fix it since its not a wiki? (Invite users to a group)

1 Like

Let me give an example, because my question must not have been clear.

I have these three email address:
alice@example.com - Belongs to a forum member who is not a group member of SomeGroup
bob@foo.org - Belongs to a forum member who is a member of SomeGroup
carol@bar.edu - Does not belong to a forum member.

I’d like the script to add the user associated with alice@example.com to SomeGroup (and possibly send a welcome message), do nothing for the user bob@foo.org, and send an invite with the group enrolment flag to carol@bar.edu.

Ah, ok I didn’t realize that! Will it send the already existing members a notice that they have been added to the group?

Rather than using a list of email addresses, it would probably make more sense to use the API for this. So, when the user signs up, you should automatically enroll them in the group using this API: Discourse API Docs

That requires that you also have the user already created in Discourse at the time you use the API. This might require a bit more setup, but it could completely automate the flow for you so you aren’t doing manual uploads of user email addresses.

2 Likes

The thing is, what I actually have is a list of email addresses, not user names. My org keeps track of people membership levels by name and email, not forum username because the forum is a small part of the org. The membership coordinator sends me a list of names and emails each week for new members. They may or may not already have a forum account when this happens since we have a public section of the forum.

It doesn’t look like that works, actually. When I try to send an invite link I get There’s no need to invite example@gmail.com , they already have an account!

There’s a possibility I may have confused myself. :slight_smile: Let me have an explore and see if there’s a way to achieve what you want using the existing forum features. :+1:

Edit:

I think this is possible using the Bulk Invite option. If you have a csv file of email addresses, with a second column for the group(s) you wish to add them to, then running that through the Bulk Invite tool will email an invite to anyone who doesn’t have an account, and add existing members to the group(s) you entered in the second column. Though the missing bit would be that this doesn’t generate a notification to say that you’ve been added to the group.

2 Likes

Bulk Invite should work for now, thanks! I’d like to put in a feature request for adding a message to existing members when they get new permissions.

1 Like

I have figured out my confusion. It is the links that do what I thought, not the emails. :slight_smile: So the other way would be to create an invite link (rather than an email), and then send that in an email to all the people on your email list. New members would be taken to the ‘create account and accept invite’ page before being added to the group and sent to the topic (if you added that criteria), existing users who are already logged in would be added to the group and sent straight to the topic you pointed them at, and existing users who weren’t logged in can login from the ‘create account and accept invite’ page (though it is a little ambiguous whether you can do that, but you could add some extra text to the page in the js.create_account.subheader_title to add a little hint), and then be added to the group and sent to the topic:

However, this way also does not send a notification to say they’ve been added to the group, but you do get the opportunity to include an explainer in the initial invite email which might be useful? And the ‘arrive at topic’ could also be leveraged in a similar way as a landing page.

I’m not sure if that’s helpful, but I’m glad I figured it out. :slight_smile:

1 Like