How to embed private messages on my site?

I know how to embed a feed with a specific id. I already did it. Now I would like to implement the following functions: if the user receives a private message, he will appear in the built-in feed. The best option, in my opinion, would be to embed the entire "chat window", but I did not find any sample code on the Internet. How can i do this?

+5
source share
1 answer

You cannot embed private messages as you can with feeds because the Yammer REST APIs (including private messages) require authentication through OAuth 2.0. This means that you need to create a Yammer API application that asks your users to log in and allow you to access their messages. The general concept described in their documentation here and here .

Yammer provides several SDKs that you can use, one of them is the Javascript SDK. I have put together a simple example of how you can ask users to log in and then display their private messages. Keep in mind, this is a very simple solution, I just checked it in one individual conversation.

<!DOCTYPE HTML> <html> <head> <script type="text/javascript" data-app-id="YOUR-APP-CLIENT-ID" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script> </head> <body> <span id="yammer-login"></span> <div id="messages"></div> <script> yam.connect.loginButton('#yammer-login', function (resp) { if (resp.authResponse) { document.getElementById('yammer-login').innerHTML = 'Welcome to Yammer!'; } }); var msgdiv = document.querySelector("#messages"); yam.getLoginStatus( function(response) { if (response.authResponse) { console.log("logged in"); var myId = response.authResponse.user_id; yam.platform.request({ url: "messages/private.json", method: "GET", success: function (response) { console.log("The request was successful."); var usernames = {}; response.references.forEach(function(ref){ if(ref.type === "user") { usernames[ref.id] = ref.full_name; } }); response.messages.forEach(function(message){ var msg = document.createElement("span"); msg.innerHTML = usernames[message.sender_id] + ": " + message.body.parsed + "<br/>"; msgdiv.appendChild(msg); }) }, error: function (response) { console.log("There was an error with the request."); console.dir(private); } }); } else { console.log("not logged in") } } ); </script> </body> </html> 

The API endpoint response messages/private.json is a JSON file that you can go through. It contains information about the message and the users participating in the conversation.

+2
source

All Articles