Create a Stream Plugin
This guide describes how to create a stream plugin.
Step 1: Pre-Requisites
In order to complete this section, you will need to add a Twitter or Facebook account to your Hootsuite profile.
Note: in order to add a Twitter or Facebook account to your profile, take the following steps, or skip to Step 2: File Setup if you have already done so:
- In your Hootsuite dashboard, from the Streams view, click + Add Social Network
- Click Twitter or Facebook, then follow the on screen instructions to connect your targeted account with your Hootsuite profile.
Step 2: File Setup
Your sample app plugin will require the following new files to be hosted within your domain's root directory:
my_plugin.html - This file will be called when Hootsuite users interact with your plugin
my_handler.html - This file represents the external page that your plugin will interact with
Step 3: Create an App Plugin
To create a plugin for your App in My Apps:
- Click on your app's name
- Click New App Extension
- In the App Extension Type field, select Plugin
- In the App Extension Title field, insert a title for your plugin.
- Click Add
- Optional: provide an icon to serve as the image of the plugin:
- Store the desired image in the domain's root directory
- Navigate to your additional App extensions, then click Edit under the Actions heading for your plugin
- In the Icon URL (30x30) field, point to the absolute URL of the image you stored in your root directory
- To specify the URL used to load your app plugin, type it in the Service URL field (
ex. https://localhost/my_plugin.html) - Click Save
You have now created a stream plugin!
Step 4: App Plugin Installation
Inside your Hootsuite dashboard:
- On the Launch Bar, go to Tools > App Directory
- Click My Apps - your app should appear in the menu
- Click Install (next to your app name)
- Inside the 'App Plugins' tab, look for the plugin you created in Step 3 and click Install
Your plugin has now been successfully installed.
Step 5: JS Library Setup
Now you will edit your my_plugin.html file to enable the plugin to communicate with the Hootsuite dashboard. Just as in the Add an App Stream section, you will need to add a reference to the Hootsuite hosted portion of the App Directory SDK. The file is located here:
https://assets.hootsuite.com/jsapi/4-1/hsp.js
Note: Do not download the above javascript file to include in your app. Always use the above CDN to ensure your app is using the current SDK version.
Add opening and closing tags to the top of my_plugin.html, wrapping opening and opening and closing tags. Inside the tags add a reference to the hsp.js script. This is shown in the following HTML snippet:
<html>
<head>
</head>
<body>
<script src="https://assets.hootsuite.com/jsapi/4-1/hsp.js"></script>
</body>
</html>
Step 6: jQuery Setup
In order to use the communication layer we have built, we will use jQuery. Right after the hsp.js reference inside the section of my_plugin.html added in Step 3, add the following line:
<script>
$(document).ready(function() {
var hsp_params = {
};
hsp.init(hsp_params);
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
Step 7: App-Dashboard Event Setup
In my_plugin.html, initialize the JS API using the hsp.init function and set the hsp parameters.
Insert this code in between HTML script tags, in the bottom of the section of the file:
<script>
$(document).ready(function() {
var hsp_params = {
};
hsp.init(hsp_params);
});
</script>
Step 8: Plugin Menu Item Function Implementation
As mentioned in Step 3, we inserted 'Open popup' as our plugin's Menu Item Text. In this quickstart, we want our plugin to open a popup that will have information about the specific message selected in the dashboard.
First, we must create a function that will grab the message information for the popup and send it encoded in the URL to my_handler.html. Insert the following code inside my_plugin.html right before the .ready event inserted in Step 7 and taking into account that <YOUR DOMAIN> is your local domain:
function sendToAppHandler(message) {
var messageId = "messageId=" + encodeURIComponent(message.post.id);
var datetime = "&datetime=" + encodeURIComponent(message.post.datetime);
var message = "&message=" + encodeURIComponent(message.post.content.body);
var handler = 'https://<YOUR DOMAIN>/my_handler.html?' + messageId + datetime + message;
hsp.showCustomPopup(handler, 'App Plugin popup');
}
Step 9: App Handler Setup
In my_handler.html, we wish to display the message information received. To achieve this, we write a function to read the parameters being passed in the URL and then we print each. Thus, my_handler.html should look like this:
<html>
<head>
</head>
<body>
<script>
function getQuerystring (key) {
key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regex = new RegExp("[\\?&]"+key+"=([^]*)");
var qs = regex.exec(location.search);
return qs[1];
}
document.write('Message ID: ' + decodeURIComponent(getQuerystring('messageId')) + '<br />');
document.write('Date & Time: ' + decodeURIComponent(getQuerystring('datetime')) + '<br /><br />');
document.write('Message: ' + decodeURIComponent(getQuerystring('message')));
</script>
</body>
</html>
Step 10: Plugin-Handler Connection
To call the sendToAppHandler function created in Step 8, insert the following code in my_plugin.html inside the jQuery .ready event and right after the hsp.init call inserted in Step 7:
hsp.bind('sendtoapp', function(message){
sendToAppHandler(message);
});
Step 11: Using the App Plugin
As mentioned in Step 1, a Twitter or Facebook account will be needed to use the app plugin. From most available Streams, you can click the ellipsis to open up the "More Actions" menu, and locate your plugin. In Step 3, we inserted 'Open popup' as the plugin's menu item text.

Click Open popup and a popup will appear! See the JSON Payload example for Facebook from our Sample App below:
