Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed yammer private messages on my website?

I know how to embed a feed which has a certain ID. I already did it. Now I'd like to implement the following functionality: If a user receives a private message, it will appear on an embedded feed. The best option in my opinion would be to embed the whole "chat window", but I didn't find a single code sample on the web. How can I do that?

like image 246
Tomasz Kasperczyk Avatar asked May 06 '16 18:05

Tomasz Kasperczyk


People also ask

Can you embed Yammer?

To display feeds from Yammer in your HTML based application, Yammer provides embeddable iFrame widgets that display a snapshot of a specified feed and function as a scaled-down version of Yammer. To create, customize, and retrieve the code to embed, visit https://go.microsoft.com/fwlink/?linkid=2165796.

How do I get a Yammer Embed code?

Go to the group in Yammer, and under Access Options at the bottom of the left panel, select Embed this feed in your site. Copy the code.

How do I add a Yammer Web Part to SharePoint Online?

Add a Yammer Highlights web part to a SharePoint modern page, search for Yammer, and then select the Yammer icon labeled either Yammer or Highlights. If you are adding the Yammer web part to a site that has an associated Yammer community or group, the Yammer group will be detected and added automatically.

Can I integrate Yammer with SharePoint?

Yammer integration may be used in both on-premises and Office 365 SharePoint environments. You can use the remote provisioning pattern to create Yammer groups and/or Yammer OpenGraph objects to facilitate conversations when you create new SharePoint sites.


1 Answers

You cannot really embed private messages like you can with feeds, because Yammer's REST APIs (incl. private messages) require authentication via OAuth 2.0. That means you have to create a Yammer API application which will ask your users to log in and allow you to access their messages. The overall concept of that described in their documentation here and here.

Yammer provides several SDKs you can use, one of them is the Javascript SDK. I pieced togehter a simple example of how you can ask users to log in and then it will display their private messages. Mind you, this is a very simple solution, I just tested it on a single one-to-one 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 response from the messages/private.json API endpoint is a JSON file that you can go through. It includes information about the message and the users involved in the conversation.

like image 172
chrki Avatar answered Sep 28 '22 04:09

chrki