Sunday, December 21, 2014


In last post we saw how to post message to yammer using REST and its various options. In this article we will see how to broadcast message using same REST API.

This is common requirement where management personals or super administrator wants to send out important messages to everyone.

Following are the general scenarios where you can use this component:
1. Sending awareness messages to all.
2. Sending viruses awareness to all to avoid any disaster.
3. Sending change in policy and procedures to everyone.
4. Sending out software update information to everyone.
5. Making any important Announcements.

Such various official activities can be done by this component.

Following is the REST URL for posting the message as broadcast, this is same URL which we saw in last article. Only difference is you need to provide a parameter: 'broadcast=true ' to the REST API. To broadcast the message you must be verified admin otherwise it will fail.

URL: "messages.json"

Parameter: ‘broadcast’ and value ‘true’.

Required Role: Verified administrator

Following is the complete code snippet for broadcasting message.

<script type="text/javascript" data-app-id="[data-app-id]" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
<script type="text/javascript">

yam.getLoginStatus(
function (response) {
if (response.authResponse) {
}
else {
yam.platform.login(function (response) {
if (!response.authResponse) {
}
});
}
});
function post() {        
var messageToPost = document.getElementById("txtMessage").value; 
yam.platform.request(
 { url: "messages.json"
 , method: "POST"
 , data: { body: messageToPost, broadcast:true }
 , success: function (msg) { 
 alert("{Post was Successful!}: " + msg); 
 }
 , error: function (msg) { 
 alert("Post was Unsuccessful..." + msg); 
 }
 }
);  
}
</script>
    <div>
        <b>Broadcast.</b>
    </div>
    <div style="width:500px;">
        <textarea id="txtMessage" style="height:100px;width:100%;"></textarea>
    </div>
    <div>&nbsp;</div>
    <div>
    <button onclick='post()'>Send to All!</button>
    </div>

In above code replace [data-app-id] with your actual data-app-id while trying out this code.

Happy  Yamming.

0 comments:

Post a Comment