Enhancing Webex Messaging Using Webex APIs & AppleScript


Do you remember the “Alert When Available” feature in the (old) Cisco Jabber chat menu? If not, here is a quick recap. The “Alert When Available” option configured Cisco Jabber to notify you when your contacts are available (i.e., online/active). This makes it easier to know if other people are available to respond to your messages.

For some reason, this option is missing from the Webex chat menu 🙄. So, without getting into a Jabber vs. Webex discussion, I wondered how I can enhance the Webex user experience and add that missing functionality?

What can we do.. Let’s think… 🤔

  1. Does Webex expose its API?… YES!
  2. Is there an API call to check the user connection status?… YES!
  3. Can I use a CLI command to trigger an API call?… YES!

Interesting! But…

  • How can I add a new option to the Webex chat menu?
  • What about the Webex API tokens limitation?
    • The personal access token is limited to 12 hours.
    • The guest user token cannot access the “status” data as it isn’t part of the organization.
    • The integration token (OAuth grant using a web browser) isn’t applicable for a simple script.

I got it! 💡

  1. True, I cannot modify the Webex chat menu… but, can AppleScript execute a CLI (cURL) command?… YES!
  2. Since a WebEx Bot is part of the organization, can I create a new Bot and use its (permanent) API token?… YES!

Problem Solved! 👍

So… I created a:

  1. cURL command & parsing statement to get the user status.
  2. New Webex Bot (for an “inside-org-permanent” API token).
  3. AppleScript to:
    1. Query (via dialog box) for the user CEC ID.
    2. Set a five seconds loop for the cURL command.
    3. Display a dialog box to notify when the user becomes active.

The Code (Mac OS only) 👨‍💻

1  set userName to text returned of (display dialog "Enter a CEC User Name (e.g., ymeloch)" default answer "" with title "Webex - Active User Notification" with icon file "Applications:Webex.app:Contents:Resources:webexteams.icns")
2  set theAlertText to "WebbEx Teams - Active User Notification"
3  set theAlertMessage to "" & userName & " User is now active"
4  ​
5  set n to 1
6  repeat
7     delay 5
8     set theName to do shell script "curl -s --request GET --url 'https://api.ciscospark.com/v1/people?email=" & userName & "%40cisco.com' --header 'Authorization: Bearer [webex-bot-token]' | json_pp | grep status | awk '{print $3}' | tr -dc '[:alnum:]'"
9  if theName = "active" then (display dialog theAlertMessage with title "Webex - Active User Notification" with icon file "Applications:Webex.app:Contents:Resources:webexteams.icns" buttons {"Exit"} default button "Exit" cancel button "Exit")
10 end repeat

The Code Explained

  • Line #1 – Define the “userName” variable (== AppleScript display dialog with an “userName” input request). BTW, see below for more information about the Webex icon path.
  • Line #2 – Define the “theAlertText” variable (== Fixed text, will be used in the main method).
  • Line #3 – Define the “theAlertMessage” variable (Includes the “userName” response and fixed text).
  • Line #5 & #6 – Start loop.
  • Line #7 – Define delay interval.
  • Line #8 – Define the “theName” variable (== The cURL command). Note the cURL GET command and parsing 👉
curl -s --request GET --url 'https://api.ciscospark.com/v1/people?email=" & userName & "%40cisco.com' --header 'Authorization: Bearer [webex-bot-token]' | json_pp | grep status | awk '{print $3}' | tr -dc '[:alnum:]'
  • cURL Command Explained:
    • [REST API Call] -s – Silent operation (no cURL command output printouts).
    • [REST API Call] –request GET – Send a GET request.
    • [REST API Call] –url – The URL of the GET request.
      • Note the “& userName &” in the URL. That is where we leverage the “userName” variable from line #1.
      • Note the “%40cisco.com” string in the URL (I replaced the “@cisco.com” string with a parseable string “%40cisco.com”).
    • [REST API Call] –header ‘Authorization: Bearer [webex-bot-token]’ – The authorization method (Bearer) to execute the API call.
    • [Parsing Statment] | json_pp – Converert the API call output to a JSON format.
    • [Parsing Statment] | grep status – Search for (only) a line with the word “status”.
    • [Parsing Statment] | awk ‘{print $3}’ – If a line with the word “status” is found, print (only) the third word.
    • [Parsing Statment] | tr -dc ‘[:alnum:]’ – Remove non-alphanumeric characters from the previous output (“active”, 👉 active).
    • Line #9 – “If” statement (looking for “active” status).
    • Line #10 – End loop (once execution completed).

❗️Note: To add the Webex icon to the AppleScript dialog, I extracted the webex.app file, and located the ​​​​​​​”webexteams.icns” file.

Demo 🎥

Disclaimers

  • In order to tweak the Webex status, I used internal API’s which are always subject to change.
  • The above code is “POC (Proof of Concept) Grade” as I am polling for the user status every 5 seconds until it changes. A more scalable way will be to subscribe for notification through Webex internal API (I still need to find these calls 😉).

Final thoughts

  • The power of automation, innovation, and integration – Cool, right! 😎
  • What is your challenge? Can you leverage automation/different technologies/programming languages to mitigate it?
  • Want to learn more about APIs (== integration glue), automation, and Integration? What about cURL and AppleScript programming? Check the AIDE User Guide or get in touch with the Cross-Domain TAB team.

Special thanks to Paul Giralt for his review and feedback! 🙏

Related developer resources


We’d love to hear what you think. Ask a question or leave a comment below.
And stay connected with Cisco DevNet on social!

Twitter @CiscoDevNet | Facebook | LinkedIn

Visit the new Developer Video Channel

Share:





Source link