Slack bot to control AirWatch via API. Current function includes changing the enrollment user on any computer.
-
Make a copy of this Google Sheet with the GAS project attached: https://docs.google.com/spreadsheets/d/1DkIUSqdDM5fnHMG7zd7hO0EVUcaw6z9AzpL0RRHeKtw/edit?usp=sharing
-
Open the Script Editor (Tools > Script Editor) and deploy the project as a web app (Publish > Deploy as web app...)
- Project version: New
- Execute the app as: Me
- Who has access to the app: Anyone, even anonymous
- Copy the web app URL and paste it into the
//URL
comment at the top of 1. Handler.gs for later use
- Navigate to File > Project properties > Script properties and set
scriptSecret
to a random password. ReplaceTOKEN
in the//URL
comment with this password
- Go to https://api.slack.com/apps and create a new app. Set an app name, description, color, and icon (use airwatch_square.png in the Images folder if you'd like)
- Add
users:read
andusers:write
to the Bot Token Scopes (OAuth & Permissions > Scopes > Bot Token Scopes > Add an OAuth Scope)
- Navigate to App Home and set Always Show My Bot as Online to ON, Home Tab to ON, and Messages Tab to OFF
-
Navigate to Interactive Components and turn on Interactivity
-
Copy your Web App URL from Step 3. and set the
app=
toslack
and thetype=
tointeraction
, then paste the link into the Request URL box
- Under Select Menus, paste the same URL into the Options Load URL but change
type=
tomenu
. Click Save Changes
-
Navigate to Event Subscriptions and set Enable Events to ON
-
In the Request URL box, paste the same link as Steps 9. and 10. but change the
type=
toevent
. Slack will then verify that your script succesfully returns the challenge token (see "//Slack one-time URL verification" section, around line 160 of 1. Handler.gs)
- Open the Subscribe to bot events section and add
app_home_opened
. Click Save Changes
-
Navigate to Install App and click Install App to Workspace
-
Copy the Bot User OAuth Access Token. Go back to the Script Editor and add it to Script Properties under
slackBotToken
-
Publish your web app as a new version to save changes (Publish > Deploy as web app...): Set Project version: to New and click Update
-
In Slack, open your new App (search for your app in the quick switcher). After a moment, the App Home tab should load with the AirWatch logo and the Change Enrollment User button
-
Create an API admin service account: In the AirWatch console, navigate to Accounts > Administrators > List View and click Add > Add Admin. Set name, password, etc. Make sure to assign to a permissions role that allows for read/write API access to any OGs you'd like the Slack App to be able to access.
-
In the Script Editor, navigate to Script properties and add API admin service account username as
airWatchUsername
and password asairWatchPassword
-
Navigate to Settings > System > Advanced > API > REST API and add an Admin API key
-
Add the AirWatch API key in Script properties as
airWatchTenantCode
-
Add your AirWatch tenant URL (e.g. "ds000.awmdm.com") in Script properties as
airWatchTenant
- Go back to your app in Slack and click the Change Enrollment User button!
To turn on logging, set var logging = true;
in 99. Logger.gs. I have various log()
functions scattered around the code currently. Due to the speed limitations of writing logs to Google Sheets, having too many logging entries can slow the script down to the point where it extends past the strict time limitations Slack has on it's API response requirements. Comment out any log()
entries you don't need.
Created by Ella for Ignition, Inc., a California corporation https://www.ignitionit.net