- The Challenge and suggested solution
- Script Initialization
- Tools & Frameworks
- Getting help & involved
- Authors & Maintainers
- Licensing info
Do you know/remember this GREAT feature in the Jabber chat menu?
If not, a quick recap.. that option configures Jabber to notify you when your contacts are available (i.e., online).
This makes it easier to know if other people are available to respond to your messages.
Well, for some reason, this option is missing from the WebEx Teams chat menu.
So, without getting into a “Jabber vs. WebEx Teams” discussion... I was wondering, how can I add that missing functionality? I’m not a WebEx Teams developer…
What can we do.. what can we do.. let’s think…
- Does WebEx Teams expose its API? YES! 👍
- Is there an API call to check a user connection status? YES! 👍
- Can I use a CLI command to trigger an API call? YES! 👍
Interesting! But...
- How can I add a new option to the WebEx Teams chat menu?
- What about the WebEx Teams API tokens limitation?
- The personal token is limited for 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
- The personal token is limited for 12 hours
- True, I cannot modify the WebEx Teams chat menu… but, can AppleScript execute a CLI (cURL) command? YES! 👍
- Since a WebEx Teams Bot is part of the organization, can I create a new Bot and use its (permanent) API token? YES! 👍
I created a:
- New WebEx Teams Bot (for an “inside-org-permanent” API token)
Procedure
- Click on the Hyperlink- Log in to Cisco WebEx Developer site
- Under the "Bots" main section, click on "Create a Bot"
- Enter the required information (e.g. Bot name, username). Note: make sure that the Bot username is valid and available)
- Once done, click on "Add Bot"
- The next window will include the following: "Bot's Access Token" and "Bot ID" (You will need the Token ID for step #8)
- cURL command & parsing statement to retrieve the user status
Sample Command
curl -s --request GET --url 'https://api.ciscospark.com/v1/people?email=ymeloch%40cisco.com' --header 'Authorization: Bearer [TOKEN]' | json_pp | grep status | awk '{print $3}' | tr -dc '[:alnum:]'
- AppleScript to:
- Query (via dialog box) for the user CEC ID
- Execute (10 sec. loop) in the background the cURL command
- Notify when the user becomes active 😃
- Query (via dialog box) for the user CEC ID
Sample Command
set userName to text returned of (display dialog "Enter a CEC User Name (e.g., ymeloch)" default answer "" with title "WebEx Teams - Active User Notification" with icon note)
set theAlertText to "WebbEx Teams - Active User Notification"
set theAlertMessage to "" & userName & " User is now active"
set n to 1
repeat
delay 10
set theName to do shell script "curl -s --request GET --url 'https://api.ciscospark.com/v1/people?email=" & userName & "%40cisco.com' --header 'Authorization: Bearer [TOKEN]' | json_pp | grep status | awk '{print $3}' | tr -dc '[:alnum:]'"
if theName = "active" then (display dialog theAlertMessage with title "WebEx Teams - Active User Notification" with icon stop buttons {"Exit"} default button "Exit" cancel button "Exit")
end repeat
-
Open a Terminal window (Press CMD + Space, type "Terminal" and hit return).
-
Clone the code to your workstation (Copy & Paste the commands below).
cd /tmp git clone https://github.com/CiscoDevNet/webexTeams-ContactAlertWhenAvailable.git cd webexTeams-ContactAlertWhenAvailable
-
Using your preferred editor, edit the "userActiveNotification.scpt" file and replace the [TOKEN] entry with your WebEx Teams Bot Token ID (Note: For Token information, please check above under the "New WebEx Teams Bot (for an “inside-org-permanent” API token) section").
-
Save the file.
-
Copy the modified file to AppleScript scripts folder (
/Users/[user-ID]/Library/Scripts
). -
Run the script (If the "Show Script menu in menu bar" option is enabled, you can run the script from the menu bar).
- This code requires a Mac OS
Need help with the code? Got questions/concerns? Want to provide feedback?
Please contact Yossi Meloch
This project is licensed to you under the terms of the Cisco Sample Code License