public async Task <EventHandledResponse> Handle(EventMetaData eventMetadata, MemberJoinedChannelEvent joinedEvent) { var team = await _teamRepo.GetTeam(eventMetadata.Team_Id); var slackClient = _slackClientService.Build(team.AccessToken); var userProfile = await slackClient.UserProfile(joinedEvent.User); if (userProfile.Profile.Api_App_Id == _slackAppId) { var introMessage = ":wave: Hi, I'm fplbot. Type `@fplbot help` to see what I can do."; var setupMessage = ""; if (team.FplbotLeagueId.HasValue) { try { var league = await _leagueClient.GetClassicLeague(team.FplbotLeagueId.Value); if (!string.IsNullOrEmpty(team.FplBotSlackChannel)) { setupMessage = $"I'm pushing notifications relevant to {league.Properties.Name} into {ChannelName()}. "; if (team.FplBotSlackChannel != joinedEvent.Channel) { setupMessage += "If you want to have notifications in this channel instead, use the `@fplbot follow` command in this channel."; } // Back-compat as we currently have a mix of: // - display names (#name) // - channel_ids (C12351) // Man be removed next season when we require updates to leagueids string ChannelName() { return(team.FplBotSlackChannel.StartsWith("#") ? team.FplBotSlackChannel : $"<#{team.FplBotSlackChannel}>"); } } } catch (HttpRequestException e) when(e.Message.Contains("404")) { setupMessage = $"I'm currently following no valid league. The invalid leagueid is `{team.FplbotLeagueId}`. Use `@fplbot follow` to setup a new valid leagueid."; } } else { setupMessage = "To get notifications for a league, use my `@fplbot follow` command"; } await _publisher.PublishToWorkspace(eventMetadata.Team_Id, joinedEvent.Channel, introMessage, setupMessage); return(new EventHandledResponse("OK")); } return(new EventHandledResponse($"IGNORED FOR {userProfile.Profile.Real_Name}")); }
public async Task <EventHandledResponse> Handle(EventMetaData eventMetadata, MemberJoinedChannelEvent joinedEvent) { _logger.LogInformation(JsonConvert.SerializeObject(joinedEvent)); _logger.LogInformation(JsonConvert.SerializeObject(eventMetadata)); var team = await _teamRepo.GetTeam(eventMetadata.Team_Id); var slackClient = _slackClientService.Build(team.AccessToken); var userProfile = await slackClient.UserProfile(joinedEvent.User); if (userProfile.Profile.Api_App_Id == FplBotProdAppId || userProfile.Profile.Api_App_Id == FplBotTestAppId) { var introMessage = ":wave: Hi, I'm fplbot. Type `@fplbot help` to see what I can do."; var league = await _leagueClient.GetClassicLeague((int)team.FplbotLeagueId); var setupMessage = $"I'm pushing notifications relevant to {league.Properties.Name} into {team.FplBotSlackChannel}"; await _publisher.PublishToWorkspace(eventMetadata.Team_Id, joinedEvent.Channel, introMessage, setupMessage); return(new EventHandledResponse("OK")); } return(new EventHandledResponse($"IGNORED FOR {userProfile.Profile.Real_Name}")); }
public Task <EventHandledResponse> Handle(EventMetaData eventMetadata, MemberJoinedChannelEvent slackEvent) { Console.WriteLine("Doing stuff from MemberJoinedChannelHandler: " + JsonConvert.SerializeObject(slackEvent)); return(Task.FromResult(new EventHandledResponse("Wrote stuff to log"))); }