aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-09-17 04:54:33 -0400
committerTeddy Wing2016-09-17 04:54:33 -0400
commitfec6b41579b88a8d2f23bab236d3c1e2e2d60e19 (patch)
tree45999c8e47163ea68355f14f64c4664ffae7c604
parent8cc23e783520f86ee0658a9538c69276215875d1 (diff)
downloadirssi-slack-profile-fec6b41579b88a8d2f23bab236d3c1e2e2d60e19.tar.bz2
update_user_profile: Allow updating of custom fields
Slack provides a set of default fields on a profile (relevant ones for editing are added to `@profile_fields`). Additionally, teams can add custom profile fields. These use unique ids that must be pulled from a profile object. This change maps an underscorized field name with a custom field id so that the id can be passed in the API call to change the field's value. The `@profile_fields` array is for now just to remind me what fields are available to change by default on profile. In the future, this will be used for key name completion.
-rw-r--r--slack_profile.pl15
1 files changed, 15 insertions, 0 deletions
diff --git a/slack_profile.pl b/slack_profile.pl
index 6cd4cbe..0163cce 100644
--- a/slack_profile.pl
+++ b/slack_profile.pl
@@ -175,6 +175,21 @@ sub update_user_profile {
# if $key is not a key in $user, then look for it in $user{fields}
# then set 'name' to the id of the custom field
+ my @profile_fields = qw(first_name last_name email phone skype title);
+
+ # If $key is a custom field, find the custom field's id and use
+ # that as the key instead.
+ unless ($key ~~ @profile_fields) {
+ # Find key in custom field labels
+ for my $custom_field (keys %{$user->{'fields'}}) {
+ if (underscorize($user->{'fields'}->{$custom_field}->{'label'})
+ eq $key) {
+ $key = $custom_field;
+ last;
+ }
+ }
+ }
+
my $resp = slack_api('users.profile.set', {
user => $user->{'id'},
name => $key,