Sunday, December 21, 2014


We have seen how to post messages using REST services in group and sending private messages to other user. In this article we will see how to reply a message.

This is very common operation which is required for any yammer feed components. If you use Yammer web part or App you got options to reply to messages. But in case of REST implementation you need to implement replying functionality so user can reply to messages.

You can use REST service which is used to post the messages to yammer. In case of reply you need to provide a message id to which you want to reply. Following is the REST URL and its required parameters. 

URL: “messages.json”

Required Parameters: 'replied_to_id'

Code Snippet:

    <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 Reply() {                             
var messageToPost = document.getElementById("txtMessage").value; 
yam.platform.request(
 { url: "messages.json"
 , method: "POST"
 , data: { body: messageToPost, replied_to_id: "478732307" }
 , success: function (msg) { 
 alert("{Replied Successfully!}: " + msg); 
 }
 , error: function (msg) { 
 alert("Post was Unsuccessful..." + msg); 
 }
 }
);  
}
</script>
    <div>
        <b>Reply to Message.</b>
    </div>
    <div style="width:500px;">
        <textarea id="txtMessage" style="height:100px;width:100%;"></textarea>
    </div>
    <div>&nbsp;</div>
    <div>
    <button onclick='Reply()'>Reply!</button>
    </div>

In this way you can implement replying functionality. To use above code use your data-app-id.

Happy Yamming.

0 comments:

Post a Comment