Thursday, November 10, 2022
HomeHealthEasy methods to Use Presence Net Companies

Easy methods to Use Presence Net Companies


Presence of thoughts

Jabber is so final many years. Webex and its competitors are the perfect trendy technique of messaging. However Cisco IM&P, a companion server to Cisco Name Supervisor, remains to be one of the best ways to subscribe to person presence updates.

Suppose you have got a bunch of staff to whom you assign duties as they arrive in. In the event you can watch the presence of that group, you’ll know who is offered, who’s away, who’s on the cellphone, and many others. You’ll be able to construct an utility that mechanically assigns duties in keeping with the presence of the customers.

The Presence Net Companies (PWS) API, a function of Cisco IM&P, is good for this sort of utility. In my expertise as a former developer help engineer, I observed many builders don’t fairly perceive find out how to use PWS correctly. I hope that by the point you’re completed studying this, you’ll have an excellent grasp of every thing concerned in making PWS be just right for you.

Right here’s a condensed breakdown of the steps:

  1. Log in an utility person with app username and password
    a. This operation returns the appliance person session key
  2. Use the appliance person session key to log in an finish person
    a. This operation returns an finish person session key
  3. Create an internet service to deal with presence notifications
    a. Run this internet service to pay attention on a standard port, e.g., 8080
  4. Use the appliance person session key to register the URL of your internet service as an endpoint
    a. This returns an endpoint ID
  5. Use the top person session key to subscribe to a number of finish person contacts
    a. This returns a subscription ID
  6. Create a script to fetch the subscribed presence, utilizing the subscription ID
    a. For instance, get_subscribed_presence.py

In steps 1 and a couple of, there’s a alternative referred to as “power=”. In the event you set “power=true”, the server will return a brand new session key each time. I like to recommend you utilize “power=false”, in order that it retains re-using the identical session key. This covers a mess of programming sins.

In Step 3, it is very important use a standard port, like 80, 82, 8080, and many others. In case your internet service relies on Python and you utilize the Flask library, the default port for Flask is 5000, which is not going to work. It’s essential to inform flask to make use of one of many widespread ports, as a substitute.

Upon getting accomplished steps 1 by means of 5, any change within the presence of the contacts in your step 5 subscription will set off a REST GET operation on the endpoint. The GET will go two parameters: The subscription id which ought to at all times be 1 with these scripts, and etype, which ought to at all times be “PRESENCE_NOTIFICATION”.

Your utility ought to then use the subscription ID to fetch all of the presence adjustments for that subscription. The API for that’s getSubscribedPresence. The script that invokes getSubscribedPresence is, coincidentally, get_subscribed_presence.py.

The pattern scripts use REST, however it’s also possible to use SOAP.

No problemo!

A typical drawback happens once you run your endpoint after a contact’s presence already modified. The server will ship a presence notification to the endpoint, however the endpoint isn’t operating, in order that notification by no means will get to the endpoint, and the endpoint doesn’t fetch the subscribed presence info. It is a drawback as a result of, if for any motive you don’t fetch the presence values on that subscription, the server will cease sending future notifications till you do.

So, the script you create in Step 6 is a fail-safe. Suppose a contact, Carlotta Tendant, switches from AVAILABLE to AWAY. The server will notify the net service on the endpoint URL {that a} change in presence occurred. In case your endpoint isn’t energetic, or it doesn’t choose up the notification and fetch the presence info, the server will cease sending presence notifications till you fetch that presence info.

It is very important know that the presence notification doesn’t ship any contact info or the truth that Carlotta is now AWAY; it simply notifies the net service {that a} presence has modified for a number of contacts for that subscription. Your internet service should fetch the details about the contact and the contact’s presence.

To keep away from the potential of missed notifications, run the get_subscribed_presence.py script as soon as every thing is about up and prepared and your endpoint is operating. This grabs the data for the customers and their presence, and thus clears the queue for the server to ship new presence notifications.

There’s another excuse the net service might not obtain a notification. If the Cisco IM&P server CPU utilization reaches 80% or increased, the server stops sending notifications till the CPU utilization drops beneath 80%. Right here’s find out how to compensate for that chance. Write your app to carry out a get subscribed presence at an interval of each 10 minutes (or whichever appears greatest), simply to make it possible for if, for any motive, your utility didn’t act on a presence notification, the queue will clear, and notifications will proceed.

Scripts

WARNING: Don’t use my pattern scripts on a manufacturing server. These are for educational functions solely.

My pattern scripts are as follows:

pws-create.py

pws-delete.py

endpoint.py

get_subscribed_presence.py

And there are some information information the script makes use of to get details about the server, the host for the endpoint, app person, finish person, and the contacts on your presence subscription.

serverparams.json (factors to your Cisco IM&P server and the host IP handle for the endpoint)

appuser.json (has the appliance username and password)

enduser.json (has the top person identify. You utilize the session key out of your utility person login)

contacts.record (the record of contacts for which you’ll subscribe to get presence notifications)

Order Up

Right here’s the way you run the scripts, so as.

  1. python3 pws-delete.py
    1. This removes all endpoints and subscriptions so you can begin contemporary
  2. python3 pws-create.py
    1. This units up the endpoint and subscribes to the presence of contacts in record. It makes use of serverparams.json to establish your Cisco IM&P server and the IP handle of the host the place your endpoint will run.
  3. python3 endpoint.py
    1. That is the endpoint script. It makes use of the Flask Python library to work as an internet service.
  4. python3 get_subscribed_presence.py 1 BASIC_PRESENCE (or RICH_PRESENCE)
    1. You run this after the endpoint internet service is up and operating. This clears out any pending subscription updates and notifications in order that the queue is empty and future notifications will work.

In the event you take a look at the code within the pattern endpoint script, for the net service endpoint doesn’t embody the code to fetch the subscription presence. I put all that into the get_subscribed_presence.py script. My endpoint merely executes the script externally like so:

               subprocess.run("python3 get_subscribed_presence.py "+id+" "+etype, shell=True)

The endpoint will know the worth of id and etype and go the values when it runs get_subscribed_presence.py. If you wish to run the script your self, nevertheless, it's worthwhile to go values on the command line, for instance:

python3 get_subscribed_presence.py 1 BASIC_PRESENCE

It’s also possible to use RICH_PRESENCE as a substitute if that’s what you need. In the event you’re completed every thing accurately, the subscription id will at all times be 1, which is why you go the quantity 1 to the script on the command line.

The pattern script doesn’t do something with the presence info. It prints it to the console the place you run the endpoint internet service. Your utility should carry out your wanted activity, comparable to updating a show of contacts and their presence.

Assets


We’d love to listen to what you suppose. Ask a query or depart a remark beneath.
And keep related with Cisco DevNet on social!

LinkedIn | Twitter @CiscoDevNet | Fb | YouTube Channel

Share:



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments