New User Auto Subscription to Blog

On our site, we have a Community Announcement blog.  This is where we put most general announcements for all of our community.  The parent group is (and nearly our entire site) is "Joinless" so we don't maintain membership for specific groups.  I say this because I don't think that the Forum Auto Subscriber extension is a valid option for what I'm looking to do.

Desired Outcome: When a new user is created in the community, have that user's account automatically subscribed to the Community Announcements blog.  We'll tell them what we're doing on their behalf in both the welcome conversation and the customization we did for Core Message with ID #24.

From my best guesses, I could build something in Automation Studio that triggers on the API Event User.AfterCreate and have it automatically update the user's subscription settings.

But I've got questions:

  1. Is the User.AfterCreate the correct API event?  I "feels" right, but it may not be.
  2. Am I right in assuming that since this runs under the user's context that I want to steer clear of the "Execute as the service account" option?
  3. Has anyone done something like this before and would you be willing to share?
  4. Is there a "primer" on the Automation Studio.  I'm not a developer, but I occasionally impersonate one to help our community.

Those are my questions.  If anyone can help me out, I'd be very appreciative.

Parents
  • 1.  User.AfterCreate should work fine.  You automation would only fire for new users, so existing users would need to be subscribed in a different way.

    2.  This would be a case where you are fine running under the user's context, since the user would be able to subscribe to the application on their own.  "Execute as the service account" is used in instances where elevated permissions are needed to perform the actions in the automation.  Should also note that there is a $core_v2_widget.ExecuteFile that is available to allow functions to be performed by a different user than the automation is executing as.  

    4.   Automations has some further information on Automations. 

  • I gave it my best shot based on the information that you all provided.  I think I've got it, but I could use another set of eyes because as I stated much earlier, I'm not a developer.  Would anyone be willing to give it a set of eyes for me?

    <automation name="${resource:Title}" version="11.1.3.12348" description="${resource:Description}" id="0124c48392ba4d5c978dbea060c7fd65" executeAsServiceUser="false" isSingleton="false" trigger="Event" lastModified="2021-05-27 14:13:34Z">
    	<events>
    		<event key="user.aftercreate" />
    	</events>
    	<executionScript language="JavaScript"><![CDATA[// pull variables from the Configuration options
    var appId = core_v2_page.ParseQueryString(core_v2_widget.GetCustomValue('appId', '')).Value('appId');
    var appTypeId = core_v2_page.ParseQueryString(core_v2_widget.GetCustomValue('appTypeId', '')).Value('appTypeId');
    
    // Error trap for blanks
    if (appId === '' || appTypeId === '') {
        return;
    }
    
    // make the call to subscribe to content via its applicationId and applicationTypeId
    // After checking many things it appears that the TypeId (used in the third 'options' parameter is always an all zero GUID)
    //    The API documentation (https://community.telligent.com/community/11/w/api-documentation/65739/core_5f00_v2_5f00_applicationsubscription-script-api#Create)
    //    reports that this third parameter is optional, but I'm including it anwway
    var response = core_v2_applicationSubscription.Create(appId, appTypeId, { TypeId: '00000000-0000-0000-0000-000000000000' } );
    
    // ---------- VARIOUS NOTES ----------
    
    // retrieve the user id of the accessing user
    // I don't think I need the user ID at all since we are running under the user's account...
    //   and I can't pass it as a parameter to core_v2_applicationSubscription anwyay
    
    // Get the user ID from the user kicking off this automation
    // var userId = context_v2_automationtrigger.Arguments.Id;
    
    // Get the user ID from the account accessing this 'thing'
    // var userId = core_v2_user.Accessing.Id;]]></executionScript>
    	<configuration><![CDATA[<propertyGroup id="options" labelResourceName="Options_Name" descriptionResourceName="Options_Description">
            <!-- for our purposes, I'm setting the default application ID of the 'Community Announcements' -->
            <property id="appId" labelResourceName="AppID_Name" descriptionResourceName="AppId_Description" dataType="Guid" defaultValue="0944ea71-1eff-4cf0-862e-bb16a27295e3" />
            <!-- for our purposes, I'm setting the default application type ID of 'blogs' -->
            <property id="appTypeId" labelResourceName="AppTypeID_Name" descriptionResourceName="AppTypeID_Description" dataType="Guid" defaultValue="ca0e7c80-8686-4d2f-a5a8-63b9e212e922" />
    </propertyGroup>]]></configuration>
    	<languageResources><![CDATA[<language key="en-us">
      <resource name="AppId_Description">Enter the Application ID [GUID] of the desired Subscription Content (Defaults to GUID of 'Community Announcements' Blog)</resource>
      <resource name="AppID_Name">Application ID</resource>
      <resource name="AppTypeID_Description">Enter the Application Type ID [GUID] of the desired Subscription Content (Defaults to GUID of Application Type 'Blog')</resource>
      <resource name="AppTypeID_Name">Application Type ID</resource>
      <resource name="Description">Automatically Subscribe new users to Application content (like blogs)</resource>
      <resource name="Options_Description">Enter the Application ID and Application Type ID for the blog</resource>
      <resource name="Options_Name">Options</resource>
      <resource name="Title">Subscribe: New Users to Application Content</resource>
    </language>]]></languageResources>
    </automation>

  • One big gotcha, now that I look at this.  The User.AfterCreate event is already running as the service account, not as the user who was created (users don't have permission to create users, so that process is executed as the service account). 

    TypeId is optional, so it doesn't need to be included, you can just include an empty options parameter.  The reason it exists is to provide the ability to have different types of subscriptions.  A subscription to comments on a blog post, a subscription to updates to the blog post, etc.  While we typically don't separate subscriptions like this, that is why it exists.

    Try this:

    <automation name="${resource:Title}" version="11.0.0.0" description="${resource:Description}" id="0124c48392ba4d5c978dbea060c7fd65" executeAsServiceUser="false" isSingleton="false" trigger="Event" lastModified="2021-05-27 15:54:29Z" provider="31f486cc-03b5-42b6-b5df-81cdd976aa59">
    	<events>
    		<event key="user.aftercreate" />
    	</events>
    	<executionScript language="JavaScript"><![CDATA[var appId = core_v2_widget.GetGuidValue('appId');
    var appTypeId = core_v2_widget.GetGuidValue('appTypeId');
    
    var user = core_v2_user.Get({ Id: context_v2_automationTrigger.Arguments.Id });
    if (!user || user.HasErrors()) {
        core_v2_exceptions.Log('here');
        return;
    }
    
    if (!appId || appId === '00000000-0000-0000-0000-000000000000')
        return;
    if (!appTypeId || appTypeId === '00000000-0000-0000-0000-000000000000')
        return;
    
    var parameters = { appId: appId, appTypeId: appTypeId };
    
    core_v2_widget.ExecuteFile('subscribe.jsm', { Parameters: parameters, RunAsUserName: user.Username });]]></executionScript>
    	<configuration><![CDATA[<propertyGroup id="options" labelResourceName="Options_Name" descriptionResourceName="Options_Description">
            <!-- for our purposes, I'm setting the default application ID of the 'Community Announcements' -->
            <property id="appId" labelResourceName="AppID_Name" descriptionResourceName="AppId_Description" dataType="Guid" defaultValue="0944ea71-1eff-4cf0-862e-bb16a27295e3" />
            <!-- for our purposes, I'm setting the default application type ID of 'blogs' -->
            <property id="appTypeId" labelResourceName="AppTypeID_Name" descriptionResourceName="AppTypeID_Description" dataType="Guid" defaultValue="ca0e7c80-8686-4d2f-a5a8-63b9e212e922" />
    </propertyGroup>]]></configuration>
    	<languageResources><![CDATA[<language key="en-us">
      <resource name="AppId_Description">Enter the Application ID [GUID] of the desired Subscription Content (Defaults to GUID of 'Community Announcements' Blog)</resource>
      <resource name="AppID_Name">Application ID</resource>
      <resource name="AppTypeID_Description">Enter the Application Type ID [GUID] of the desired Subscription Content (Defaults to GUID of Application Type 'Blog')</resource>
      <resource name="AppTypeID_Name">Application Type ID</resource>
      <resource name="Description">Automatically Subscribe new users to Application content (like blogs)</resource>
      <resource name="Options_Description">Enter the Application ID and Application Type ID for the blog</resource>
      <resource name="Options_Name">Options</resource>
      <resource name="Title">Subscribe: New Users to Application Content</resource>
    </language>]]></languageResources>
    	<files>
    		<file name="subscribe.jsm"><![CDATA[dmFyIGFwcElkID0gY29yZV92Ml91dGlsaXR5LlBhcnNlR3VpZChjb3JlX3YyX3dpZGdldC5HZXRFeGVjdXRpb25QYXJhbWV0ZXJWYWx1ZSgnYXBwSWQnKSk7CnZhciBhcHBUeXBlSWQgPSBjb3JlX3YyX3V0aWxpdHkuUGFyc2VHdWlkKGNvcmVfdjJfd2lkZ2V0LkdldEV4ZWN1dGlvblBhcmFtZXRlclZhbHVlKCdhcHBUeXBlSWQnKSk7CmNvcmVfdjJfYXBwbGljYXRpb25TdWJzY3JpcHRpb24uQ3JlYXRlKGFwcElkLCBhcHBUeXBlSWQsIHt9KTs=]]></file>
    	</files>
    </automation>

  • Wow - just wow.  I tested it on my staging environment and it worked with zero problems.  Thanks   - I would have missed those nuances about the permissions.

    I know that now that this is working, the next will be "How do we get all of the Application Contents that can be subscribed to in this with just checkboxes for the list?"  And that particular problem will be for another day!

  • No problem.  Oh you can remove core_v2_exceptions.Log('here');  That no longer needs to be there, was just testing that code path.  Otherwise you will get a 'here' exception every time this runs and the user doesn't load right (which should not happen).

Reply Children