Comment Notifications via API

Set up comment notifications so that media owners are alerted anytime someone comments, or to alert those who have made comments that someone else has added to their thread. There are 2 types of notifications:

Comment Notification Email

The Comment Notification Email alerts media owners that someone has commented on their submission.


Thread Notification Email

The Thread Notification Email alerts users who previously commented on an item, that another user has added a comment to the same item.

Step 1: Enable Comment Notifications in your Vhost Settings

  • Go to Settings > Project Settings in the nav bar
  • On the main Settings tab, beside Media Comment Notifications and Thread Comment Notifications choose either 'Send by default' or 'User must opt-in'
    • Send by default - Means that users will receive the notification even if they have not explicitly opted into this email.
    • User must opt-in - Means that users must opt-in to this new email type first, before they start receiving these notifications.


 

  • Be sure to hit 'save' once you've done this

Step 2: Set Up the Comment Email Templates

  • Go to Applications in the main nav bar
  • If you already have an existing application where you manage all of your email templates, you can re-use that, or you can create a new application to create these email templates:
    • Install a new app:
    • When selecting the App type, choose the Blank Application


  • Click 'create'
  • Navigate to Wrapper Templates and edit the body of the default template to be:
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  <head>  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head> 
<body> {$content} </body>
</html>
 

 
 
Navigate to Email Templates as shown below:
 
 
Create a new email for new comments on media:
  • Template Name - Media Comments
  • Wrapper Template - Use default template
  • Subject - You have a new comment!
  • Sender - the email you wish to send comment emails from, example: notification@yourcompany.com
  • Body - Copy and paste the template:
	<table width="500" style="font-family:Arial;">
<tr>
<td style="border:1px solid #ccc; padding: 10px;">
             <table>
            <tr>
                <td>
                    <h2 style="font-size:14px;">{$$firstname},</h2>
                <p style="font-size:12px;">
                    {$$message}
                </p>
<table width="500">
                  <tr>
                    <td style="margin-top:10px; padding:10px; background-color:#e2e2e2;" width="318">
                        <p style=" font-size:14px;">
                        {$$comment}
                        </p>
                    </td>
                    </tr>
                </table>
</td>
           </tr>
             </table>
        </td>
        </tr>
        <tr>
        <td style="padding:10px; font-size:10px; color:#505050; text-align:center;">
             Check out all the entries at <a href="http://INSERT REDIRECT LINK HERE</a>
            </td>
        </tr>
        <tr>
            <td style="padding:10px; font-size:10px; color:#505050; text-align:center;">
OPT OUT FROM THE NOTIFICATIONS AT: <BR />
<a href="http://INSERT LINK TO USER PROFILE MANAGER HERE</a>
</td> </tr> </table>
      

You will end up with:

 

 

Then create the second email template, which is for New Thread Comments:

  • Template Name - Thread Comments
  • Wrapper Template - Use default template
  • Subject - Someone commented on your thread!
  • Sender - the email you wish to send thread comment emails from, example: notification@yourcompany.com
  • Body - Copy and paste the template from below:
	<table width="500" style="font-family:Arial;">
		 <tr>
        <td style="border:1px solid #ccc; padding: 10px;">
             <table>
            <tr>
                <td>
                <h2 style="font-size:14px;">{$$email_recipient_firstname},</h2>
                <p style="font-size:12px;">
                    {$$author} just posted a comment on "{$$media_title}":</p>
                <table width="500">
                    <tr>
                    <td style="margin-top:10px; padding:10px; background-color:#e2e2e2;" width="318">
                        <p style=" font-size:14px;">
                        {$$comment}
                        </p>
                    </td>
                    </tr>
</table> </td>
            </tr>
             </table>
        </td>
        </tr>
        <tr>
 <td style="padding:10px; font-size:10px; color:#505050; text-align:center;">
            See more at <a href="http://INSERT REDIRECT LINK TO COMMENT HERE</a>
            </td>
        </tr>
        <tr>
            <td style="padding:10px; font-size:10px; color:#505050; text-align:center;">
                 OPT OUT FROM THE NOTIFICATIONS AT: <BR />
                   <a href="http://INSERT REDIRECT LINK TO USER PROFILE MANAGER HERE</a>
        </td>
        </tr>
    </table>
       

You should have 2 email templates in the end, as shown below:


Step 3: Configure Comment Channels

  • In the top nav, go to Media > Channels
  • Click 'new' to create a comments channel

  • Fill out the fields and hit 'create' 

  • Open the channel details so that you can select the email templates for Media Comments  and Thread Comments
  • The drop down will expand, and you will find the templates under the application you created in Step 2 above.

Step 5: API's to add comments and trigger the emails

See the media.insertTextFile API documentation for full details.

Below is an example API call used to create a comment and auto-approve the comment. Email notifications will be sent immediately in this case:

	http://api.newspark.ca/services/rest/media.insertTextFile?vhost=[VID]&fileData[title]=Comment test&fileData[message]=Message1&fileData[parentid]=[MEDIA_ID]	&fileData[context]=COMMENT&fileData[moderationstatus]=1&fileData[uid]=[USERID_OF_COMMENTER]&fileData[channel]= [CHANNELID_FOR_COMMENTS]&APIKEY=[APIKEY]

 

  • fileData[moderationstatus]=1 will approve the comment and trigger the notification email immediately.

 

 

Below is an example API call used to add a comment that requires moderation. This means that notification emails are sent only when the comment has been manually approved by moderators in New Spark Platform.

http://api.newspark.ca/services/rest/media.insertTextFile?vhost=[VID]&fileData[title]=Comment test&fileData[message]=Message1&fileData[parentid]=[MEDIA_ID]	&fileData[context]=COMMENT&fileData[moderationstatus]=0&fileData[uid]=[USERID_OF_COMMENTER]&fileData[channel]= 15963&APIKEY=[APIKEY]

 

  • fileData[moderationstatus]=0 will set the comment to be queued for moderation, and when it is manually approved in New Spark Platform, only then will the email notification be sent out.


 

Step 6: API's to manage the user's notification settings

See users.updateuserInfo API for full details.

Below is an example API call to toggle user settings to opt out of media comment notifications.

http://api.newspark.ca/services/rest/users.updateUserInfo?id=1945997&newProperties[disable_media_notifications]=1&APIKEY=[APIKEY]

 

Below is an example API call to toggle user settings to opt out of thread comment notifications.

	http://api.newspark.ca/services/rest/users.updateUserInfo?id=1945997&newProperties[disable_thread_notifications]=1&APIKEY=[APIKEY]

Step 7: Optional - Dynamic redirect links in your email templates

You may need a way to dynamically create the redirect links in the email template, so that when the user views the email, the link that they click on should take them back to the correct URL every time. You can do this by saving the URL where the comment was made as the metadata to the comment.

Example:

http://api.newspark.ca/services/rest/media.insertTextFile?vhost=[VID]&fileData[title]=Comment test&fileData[message]=Message1&fileData[parentid]=[MEDIA_ID]	&fileData[context]=COMMENT&fileData[moderationstatus]=1&fileData[uid]=[USERID_OF_COMMENTER]&fileData[channel]= [CHANNELID_FOR_COMMENTS]&fileData[metadata][user][commenturl]=website.com&APIKEY=[APIKEY]

 

  • Where the metadata key = commenturl (this can be any value you want to use)
  • metadata value = website.com (this is the URL that will be saved and can be used in the email template to send the user back to the correct site)

 

Then to retrieve this value in the email template, use the syntax in bold below:

<table width="500" style="font-family:Arial;">
<tr>
<td style="border:1px solid #ccc; padding: 10px;">
             <table>
            <tr>
                <td>
                    <h2 style="font-size:14px;">{$$firstname},</h2>
                <p style="font-size:12px;">
                    {$$message}
                </p>
<table width="500">
                  <tr>
                    <td style="margin-top:10px; padding:10px; background-color:#e2e2e2;" width="318">
                        <p style=" font-size:14px;">
                        {$$comment}
                        </p>
                    </td>
                    </tr>
                </table>
</td>
           </tr>
             </table>
        </td>
        </tr>
        <tr>
        <td style="padding:10px; font-size:10px; color:#505050; text-align:center;">
             Check out all the entries at <a href="http://{$$comment_meta.user.commenturl}</a>
            </td>
        </tr>
        <tr>
            <td style="padding:10px; font-size:10px; color:#505050; text-align:center;">
OPT OUT FROM THE NOTIFICATIONS AT: <BR />
<a href="http://INSERT LINK TO USER PROFILE MANAGER HERE</a>
</td> </tr> </table>

  • Where commenturl is the key of your metadata being being used.

0 comments

Be the first to comment on Comment Notifications via API.

Add a Comment

  • captcha