NewsGator Custom Activity with an Event Receiver

If you have NewsGator on your SharePoint site and want to refine the look or functionality of some items in the newsfeed, there is a good chance that you will be building a custom activity type.

Here are a few examples of where custom activity types can help:

·items from a non-community list trigger posts to the newsfeed

·disable “share” functionality for particular newsfeed items

·send out updates from a group account without forcing your users to remember an extra set of account credentials

None of this functionality is built into out-of-the-box NewsGator, but is easy enough to create with custom activity types.

Of course, NewsGator documentation outlines the process to create a custom activity for NewsGator, and you can find sample code in the NewsGator developer community. That said, I found myself going back and forth between 1.2 and 2.0, and 2.1 documents to piece together what I needed, so hopefully the steps below can simplify the creation process for you. This information may also be useful to you if you have NewsGator 1.2 custom activities that you would like to convert to 2.0 or 2.1.

Because NewsGator customizations rely on convention over configuration, it’s very important to follow the naming conventions very precisely. I color-coded the names that need to in the code below.

Key components

References

Add the following references:

NewsGator.Social

NewsGator.Social.Data

Microsoft.SharePoint.Administration

NewsGator.Social.ServerData

Resource file

·Defines the activity name and template

·Make sure it has the same name as your project. (E.g FullApplicationName -> FullApplicationName.resx)

·The value for FullApplicationName_ActivityTypeName_Display can be anything you like. It’s just a display name

·The value for FullApplicationName_ActivityTypeName_Template can contain any custom text, HTML, and replacement tokens from the table below. Note that you can use HTML in the template, but HTML in the ActivityValue will cause your post not to show up in the newsfeed.

Property

Type

Replacement Token

ActivityValue

string

{Value}

Author

UserProfileReference

{Publisher}

DateValue

DateTime?

{Date}

Link

SocialLink

{Link}

Link2

SocialLink

{Link2}

LinksList

List<SocialLink>*

{List}

Name

String

{Name}

*See NewsGator.Social API for an explanation of how to use lists of links.

·Example:

Installer/uninstaller feature

·You can name this one whatever you want. (referred to as InstallerFeatureName from here on out)

·Farm scope

·Contains Installation code for your custom type to appear in the Farm Features list and in the activity types list in the user preferences (a little more about that later).

·Contains custom module: it defines customizations like JavaScript, CSS. (Use firebug or some other browser extension to pinpoint which elements you want to customize)

·How to:

Create a new feature, rename to your liking

Add an Event Receiver to your feature

Replace the 1st two methods with the code below

Replace the names, productModuleGuid, and PublicKeyToken

Add appropriate using statements

//you can use the auto-generated value that’s been assigned to this feature receiver

·If the logged in user is not the author and your code doesn’t have the rights to impersonate the author, the activity will not post.

·If your template doesn’t require an ActivityValue, assign it to be “”. Leaving out this field causes an error and your activity won’t post.

Receiver feature

·You can name this one whatever you want (referred to as ReceiverFeatureName from here on out)

·Web scope. Note: in this example, I am using web scope, but depending on what event triggers your receiver, you may want a different scope. Hypothetically, you could use Site scope for a list receiver, just make sure that you are consistent between the feature definition and your receiver code.

·How to:

Create a new feature, rename to your liking

Add an Event Receiver to your feature

Put this into FeatureActivated method of the feature receiver and don’t forget to replace the names and PublicKeyToken:

1.Make sure that the feature at farm levelnamed FullApplicationNameInstallerFeatureName exists and is activated.

2.Make sure that the feature at site level named FullApplicationNameReceiverFeatureName exists and is activated.

3.Make sure that in Newsfeed Settings, “Activities I am following” section there is a checkbox for Activity Name.

If you were able to deploy your solution, but any of the above didn’t happen, check for mismatches between the names in resx, installer feature, receiver feature, and event receiver. For example, a new checkbox in the “Activities I am following” section with no text next to it probably means that you mismatched the ActivityTypeName in the installer and the ActivityTypeName in the resx file.

Why Farm Scope for Installer Feature?

Because if you want to post to my sites, they are likely to be in a separate web app, and you will need to write into an activity feed across web apps.

Where permissions can fail…

If the logged in user is posting activities on behalf of someone else (e.g. an editor is approving a writer’s content).

Per NewsGator Documentation: All application pool accounts on the LOCAL farm are automatically granted delegation and impersonation rights. If you expose an endpoint that allows a system user to delegate event creation on behalf of a user, you will need to grant the calling user Delegation and Impersonation Rights on the service application. To do this, highlight the service application in Central Administration: Manage Service Applications, and select “Administrators”. Add the user and grant them “Delegation and Impersonation” rights. (No other rights are needed for this account.)

What other documentation is available?

Most likely if you are customizing NewsGator activities, you have access to NewsGator-provided resources:

2 thoughts on “NewsGator Custom Activity with an Event Receiver”

You could include a table in the resource to format it, but you can only populate one {value} replacement token. You wouldn’t be able to insert a whole table in the activity, nor would you be able to populate multiple custom cells in a table with your code.

So, you can do something like
< table>
< tr>

Author

Project info

{publisher}

{value}

And in the code say
ActivityValue = projectName+” “+projectStatus

But not

Author

Project

Status

{publisher}

{project}

{status}

And you won’t be able to do a table with information from multiple projects because the template has predefined replacement tokens that you can fill in and they’re limited in number. The only one that has multiples is the link list. If you need a table of links, you can do that.

Hi
Thanks for the post.we are trying to display the external information like project information in the activity feed, so that we can utilize the pivot viewer for searching (like the time line in facebook). for that we have to post the data using code from external source to Newsgator’s activity stream. For which we have to create our own custom activity like project and the template for the activity should be some table. In that case is it possible to have a html tag included in the resource file for the custom activity.