Closed martyychang closed 7 years ago
My guess is that Java's TimeZone.getAvailableIDs()
function will give the master list of recognized IDs. The list that I took from Salesforce is just fine, though, and I just need to create some kind of documentation page to explain all of the values.
I'm thinking about the /clock zone
command I'm planning to create. For user experience, I think the optimal steps would be as follows.
/clock zone
to see current time zone. The response instructs the user to types /clock help zone
to get more info on the "zone" operation./clock help zone
. All available time zone IDs are listed along with the current offset, ordered by the current offset and then alphabetically./clock zone America/New_York
to select her new time zoneAlthough Slack does offer other ways of interacting with users, which may be worth exploring for a better UX with less code complexity.
Or better yet, the user's time zone should simply be set to match the user's configuration in Slack. How easy is that? For an interactive UX, I think perhaps a message menu would be best. But I want to see whether I can simply find the user's time zone with an API call to Slack.
The users.info method seems to be exactly what I want... but I need to figure out how to make the necessary calls. Also, it seems the UX for a user installing an app from the public App Directory vs. installing an unlisted Slack app is different. Installing an app from the public directory does not redirect the user to the redirect_uri
as in the OAuth 2.0 flow.
The steps below are the high-level steps in the process.
oauth.access
users.info
Very cool... with Postman I was able to get the access token in a response body that looks like this.
{
"ok": true,
"access_token": "...",
"scope": "identify,commands",
"user_id": "...",
"team_name": "...",
"team_id": "..."
}
It appears that upon exchanging the authorization code for an access token, the app is considered to be "installed" and the commands become available to users in the workspace
The cURL command illustrating the simple command I need to use to get the access token is below. However... I'm left in a strange place where I don't know how to take the user back to Slack...? I may need help from Slack here.
curl -X GET \
'https://slack.com/api/oauth.access?client_id=...&client_secret=...&code=...' \
-H 'cache-control: no-cache' \
-H 'postman-token: bd6547b4-4f74-8bb4-091c-9a6ad1df189f'
The following works in the action
action method to take the user to another page after the controller does its thing.
// Redirect to https://api.slack.com
PageReference nextPage = new PageReference('https://api.slack.com');
// Use Slack to get the
return nextPage;
/api/team.info to get the team's domain for constructing the final URL
I need a better strategy for handling HTTP errors, timeouts and other error conditions when invoking the API
Interesting... looks like the problem is that I am making DML operations while still making web service callouts.
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
My current order of operations is as follows.
Looks like the /team.info call is failing, coming back with "ok": false
. Trying the call out in Postman, it seems the problem is that I need to request the "team:read" scope.
{
"ok": false,
"error": "missing_scope",
"needed": "team:read",
"provided": "identify,commands"
}
Interesting... the scope request in the app currently is driven by the installation URL's scope
parameter. When I change the requested scopes in the app configuration, it changes the URL. But until I started using the new URL vs. my bookmarked URL, the scope requests never changed.
Hmm... how can I smartly look up the user's time zone without expending an API call on every single command???
From the user's perspective, the UX should be as follows.
I confirmed based on the Slack docs that the time zone looks to require manual management by the user.
I can't think of a better way to handle this right now except to check the time zone every time the user invokes a command that uses an implicit time. Right now this means /clock in
and /clock out
would be impacted.
As a Slack user, I want to specify a time zone, so my time entries are accurately reported for the correct days of the week.
Solution design
Time entries should be linked to standard
Contact
records, based on theSlackUserId__c
value. Every contact will have a customTimeZoneSidKey__c
picklist field that stores the same values as what would be expected ofUser.TimeZoneSidKey
.