Monday, December 15, 2014


In last article we saw how to broadcast a messages using REST API. But sometimes it is required that you need to send a message to a person in private so others cannot see it. It could be one to one feedback, any personal update. Or something confidential information.

In this article we will see how to post private message to user using REST service. The REST URL remains same which we used for posting message, the only difference is the parameter. In case of private sending private messages use  parameter 'direct_to_id' of user.

URL: "messages.json"

Required parameters: ‘direct_to_id’

Complete code snippet:

<script type="text/javascript">
function post() {                             
                var messageToPost = document.getElementById("txtMessage").value; 
yam.getLoginStatus( function(response) {
if (response.authResponse) {
yam.platform.request(
 { url: "messages.json"
 , method: "POST"
 , data: { "body": messageToPost, "direct_to_id": "1518699585" }
 , success: function (msg) {
 alert("{Post was Successful!}: " + msg); 
 }
 , error: function (msg) { 
 alert("Post was Unsuccessful..." + msg); 
 }
 }
)
} else {
yam.platform.login( function (response) {
 if (!response.authResponse) {
yam.platform.request(
 { url: "messages.json"
 , method: "POST"
 , data: { body: messageToPost, direct_to_id: "1518699585" }
 , success: function (msg) { alert("{Post was Successful!}: " + msg); }
 , error: function (msg) { 
 alert("Post was Unsuccessful..." + msg); 
 }
 }
);
 }
});
}
});
}
</script>
    <div>
        <b>Send Private Message.</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 Friend!</button>
    </div>


Happy SharePoint coding.

2 comments:

  1. Hi! I found your blog while looking for a solution to my business problem. I'm wondering if you can help. I need to create an easy way for a compliance supervisory person to be able to review a network's private messages (regulatory requirement). The view has to be threaded and simple. We're using Yammer and SharePoint 2010.

    I'm not a technical person, so I'm wondering if you can offer a suggestion that I could take back to my project team?

    ReplyDelete
    Replies
    1. Hi Diane K,

      If I understand correctly then what your requirement is you want to show all private messages or private chat happened between network users to Supervisor. In this case could you please check whether this REST URL: 'https://www.yammer.com/api/v1/messages/private.json' can help you. You must be Verified Admin to check this REST URL. As I know basic '/messages.json' REST URL returns only public messages and not private chat. So ask your team to try and check whether above mentioned REST URL helps to get all private conversation.

      Another way to get private messages is 'Data Export' option which is available to yammer admin. It returns all messages within yammer network including private in csv files. This does not give threaded view but with some excel sheet tweaks you can achieve it.

      Thank you.

      Regards,
      Rahul Shinde

      Delete