public static async Task <List <ListenerTrack> > Run( [ActivityTrigger] List <string> listenerIds, ILogger log ) { return(await SpotifyHelper.GetListenerTracks(listenerIds, log)); }
public static async Task <List <ListenerTrack> > Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "listeners")] HttpRequest req, [Table( TableConstants.UserTable, Connection = Constants.StorageConnection )] CloudTable userTable, ILogger log) { log.LogInformation("Retrieving non-hidden users"); await userTable.CreateIfNotExistsAsync(); var repo = new UserRepository(userTable); var entities = await repo.GetUsersAsync(); var nonHiddenUserIds = entities .Where(e => e.Active) .Select(e => e.RowKey) .ToList(); log.LogInformation("Found these users: {Users}", string.Join(", ", nonHiddenUserIds)); return(await SpotifyHelper.GetListenerTracks(nonHiddenUserIds, log)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "slack")] HttpRequest req, [Table( TableConstants.UserTable, Connection = Constants.StorageConnection )] CloudTable userTable, ILogger log) { await userTable.CreateIfNotExistsAsync(); var bodyString = await req.ReadAsStringAsync(); var slackPayload = HttpUtility.ParseQueryString(bodyString); var token = slackPayload["token"]; if (!string.Equals(token, Config.SlackToken)) { throw new System.Exception("Not allowed"); } var args = slackPayload["text"]?.Trim(); if (string.Equals("list", args)) { var repo = new UserRepository(userTable); var entities = await repo.GetUsersAsync(); var nonHiddenUserIds = entities .Where(e => e.Active) .Select(e => e.RowKey) .ToList(); log.LogInformation("Found these users: {Users}", string.Join(", ", nonHiddenUserIds)); var listenerTracks = await SpotifyHelper.GetListenerTracks(nonHiddenUserIds, log); return(new JsonResult(new { blocks = new { type = "section", block_id = "listeners", fields = listenerTracks.Select(lt => new { type = "mrkdwn", text = $"- {lt.userId}: {lt.currentTrack}" }).ToArray <object>() } })); } return(new JsonResult(new { blocks = new object[] { new { type = "section", block_id = "help_text_commands", fields = new [] { new { type = "mrkdwn", text = "*Hey! Welcome to now playing* \n Press the button below to go to the website, or register with Now Playing:" } } }, new { type = "actions", elements = new object[] { new { type = "button", action_id = "dashboard_nowplaying", url = Config.HostUrl, text = new { type = "plain_text", text = "Dashboard website", } }, new { type = "button", action_id = "register_nowplaying", url = $"{Config.HostUrl}api/authorize", text = new { type = "plain_text", text = "Register with Now Playing", } } } } } })); }