In a recent post we showed how to connect WinCC OA SCADA software to Slack. One reader asked if it was also possible to connect to Yammer, which is a similar collaboration too from Microsoft. As the reader stated so well, "Sometimes we just have to use the tool we have, not the best one." So to help make the most of a bad situation (just kidding) for this person, here is a follow-up post explaining the basics of connecting WinCC OA to Yammer.
The first step comes directly from Microsoft's documentation found at https://developer.yammer.com/docs/app-registration, because they do a very good job of explaining the finer details of the connection.
Go to https://www.yammer.com/client_applications. Click on the “Register new App” button. Please note, when you create an app, this app will be linked to the Yammer network related to your user account. This is the network you will use to access, edit, and test your application.
Consider using a service account when registering your app at https://www.yammer.com/client_applications. i.e. “email@example.com”. This will ensure your app continues to work if you or the app creator leaves the company.
For the redirect URI you will need to have an https enabled URL. I just used our company website because we really won’t be redirecting from inside of OA.
When you click continue, you will be given the following information. Keep these pieces of information available because they will be useful for the next few steps.
You will need to register an Admin with the account. You can do this by going to this url in a web browser
https://www.yammer.com/dialog/oauth?client_id= [ :client_id ].
Replace [:client_id] with the client id from the previous step and then click Allow.
Once you click allow you will be redirected to the Redirect URL you entered in the first step. In the URL in the web browser you will notice there is a code=xyz in the URL. Copy this down and keep it somewhere.
Stay in the web browser and navigate to
https://www.yammer.com/oauth2/access_token.json?client_id= [ :client_id ] &client_secret= [ :client_secret ] &code= [ :code ]
Again, replace [:client_id] , [:client_secret], and [:code] with the the client_id and client_secret with the values from the first step. Replace [:code] with the code that you copied down in Step 3.
Your will be redirected to a page that looks like this.
Most of this has been cut off to hide my information. Copy this page and store it somewhere SAFE and HIDDEN. This is the access token to your Yammer account. If someone gets a hold of this, they can access ALL of your Yammer. The piece you will need from this is the token attribute.
We can now open OA and go to a new or existing project. Open up a script and add in the following code. I attached this to a dpConnect so it will send any time a tag changes. The important pieces from this code are the mMappe needs to have a “body” piece. Also, the ‘headers’ mapping needs to have the Content-Type : application/json and the Authorization: Bearer YOUR TOKEN needs to be filled in.
workYammer(string dp, int a)
string s = "Hello from WinCC OA" ;
mapping mMappe = makeMapping("body","Hello from WinCC OA");
string s = jsonEncode(mMappe);
netPost("https://www.yammer.com/api/v1/messages.json", makeMapping("content",s, "headers", makeMapping("Content-Type", "application/json","Authorization", "Bearer YOUR TOKEN")),m);
And the end result will be...
This gets you connected. From here you can take this further to select the Yammer group, and do more automated things on the OA side to make this useful.
Learn more about Vertech's expertise with Siemens products and solutions here.