public async Task <bool> NotifyFailedPullRequestBuild(Build build, string identifier) { SlackUserResponse pullRequestOwner = null; try { pullRequestOwner = await _client.GetUserByEmail(build.PullRequest.AuthorEmail).ConfigureAwait(false); } catch (SlackClientException e) when("users_not_found".Equals(e.Message, StringComparison.OrdinalIgnoreCase)) { // When the user wasn't found we cannot notify them directly, // by leaving pullRequestOwner null the FormatFailedBuild will // create a generic message. } var payload = SlackMessageFormatter.FormatFailedBuild(build, _configuration.Channel, identifier, pullRequestOwner); var success = await _client.PostMessage(payload).ConfigureAwait(false); return(success.Ok); }