Skip to content

Commit

Permalink
Zendesk reactor: skip getting zendesk tickets if user has no zendesk …
Browse files Browse the repository at this point in the history
…account
  • Loading branch information
Rasha Moumneh authored and wolfsage committed Aug 31, 2023
1 parent 7c00a4d commit 6b167f4
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lib/Synergy/Reactor/Zendesk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use Synergy::Logger '$Logger';
use Time::Duration qw(ago);
use Try::Tiny;
use Zendesk::Client;
use Synergy::Logger '$Logger';

__PACKAGE__->add_preference(
name => 'staff-email-address',
Expand Down Expand Up @@ -253,15 +254,32 @@ async sub ticket_report ($self, $who, $arg = {}) {
return [ $text, { slack => $text } ];
}

# Return if $email has no associated Zendesk account
my $user = eval {
await $self->zendesk_client->user_api->get_by_email_f($email);
};

if ($@) {
my $error = $@;
$error =~ /Expected 1 user, got 0/
? $Logger->log([
"No Zendesk user found for %s",
$email,
])
: $Logger->log([
"Unknown error trying to get Zendesk user for %s: %s",
$email,
$error,
]);
return;
};

my $res;
my $ok = eval {
$res = await $self->zendesk_client
->user_api
->get_by_email_no_fetch($email)
->scoped_client
$res = await $user->scoped_client
->make_request_f(
GET => "/api/v2/users/me.json?include=open_ticket_count"
);
GET => "/api/v2/users/me.json?include=open_ticket_count"
);
1;
};

Expand Down

0 comments on commit 6b167f4

Please sign in to comment.