From 1f106bcc16cfb46e82100919a5771a40dd485723 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Tue, 9 Apr 2024 06:13:02 -0500 Subject: [PATCH] Update for shinyslack 0.0.0.9010 --- DESCRIPTION | 7 +++++-- R/app_server.R | 31 +++++++++++++++++++++++-------- app.R | 10 +++++++++- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 459c443..c71f60b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,7 +5,8 @@ Authors@R: c( person("Jon", "Harmon", , "jonthegeek@gmail.com", role = c("cre", "aut")), person("Tan", "Ho", , "tan@tanho.ca", role = "ctb") ) -Description: This is a golem shiny app for the Data Science Learning Community. +Description: This is a golem shiny app for the Data Science Learning + Community. License: MIT + file LICENSE URL: https://github.com/r4ds/mentordash BugReports: https://github.com/r4ds/mentordash/issues @@ -23,7 +24,8 @@ Imports: scenes (>= 0.0.0.9003), shiny (>= 1.5.0), shinydashboard, - shinyslack (>= 0.0.0.9006), + shinyslack (>= 0.0.0.9010), + slackcalls, slackteams (>= 0.4.3), slackthreads (>= 0.1.0), stringr, @@ -33,6 +35,7 @@ Suggests: testthat Remotes: r4ds/shinyslack, + yonicd/slackcalls, yonicd/slackteams, yonicd/slackthreads Encoding: UTF-8 diff --git a/R/app_server.R b/R/app_server.R index d8229b7..4d3611b 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -91,8 +91,12 @@ }) } -.get_question_channels <- function() { - channels <- slackteams::get_conversations_list(type = "public_channel") +.get_question_channels <- function(session = shiny::getDefaultReactiveDomain(), + slack_api_key = session$userData$shinyslack_api_key) { + channels <- slackteams::get_conversations_list( + type = "public_channel", + token = slack_api_key + ) question_channels_df <- dplyr::filter( channels, stringr::str_starts(.data$name, "help-") ) @@ -104,10 +108,12 @@ return(question_channels) } -.get_mentors <- function() { +.get_mentors <- function(session = shiny::getDefaultReactiveDomain(), + slack_api_key = session$userData$shinyslack_api_key) { mentors <- slackcalls::post_slack( "conversations.members", - channel = "GAJ8D7YKA" + channel = "GAJ8D7YKA", + token = slack_api_key ) if (mentors$ok && "members" %in% names(mentors)) { @@ -123,7 +129,9 @@ #' #' @return A tidy tibble of question information. #' @keywords internal -.get_questions <- function(question_channels) { +.get_questions <- function(question_channels, + session = shiny::getDefaultReactiveDomain(), + slack_api_key = session$userData$shinyslack_api_key) { ## Read in Conversations ---- total_results <- 100L @@ -131,7 +139,8 @@ question_channels, slackthreads::conversations, max_results = total_results, - limit = min(total_results, 1000L) + limit = min(total_results, 1000L), + token = slack_api_key ) ## Response to Tibble ---- @@ -333,7 +342,9 @@ users, reply_userses, channel_ids, - tses) { + tses, + session = shiny::getDefaultReactiveDomain(), + slack_api_key = session$userData$shinyslack_api_key) { # We need to return a logical vector indicating whether this question is # "answerable", meaning the thread hasn't been tagged as needing more info OR # there isn't a reply OR the latest reply was by the user. To determine the @@ -361,7 +372,11 @@ ), .f = function(ts, channel_id, user, reply_users) { if (user %in% reply_users) { - last_reply_user <- slackthreads::replies(ts, channel_id) |> + last_reply_user <- slackthreads::replies( + ts, + channel_id, + token = slack_api_key + ) |> tibble::enframe() |> tidyr::hoist(.data$value, "ts", "user") |> dplyr::arrange(dplyr::desc(ts)) |> diff --git a/app.R b/app.R index 933813e..0f884b7 100644 --- a/app.R +++ b/app.R @@ -9,5 +9,13 @@ pkgload::load_all( quiet = TRUE ) -options("golem.app.prod" = TRUE) +# options("golem.app.prod" = TRUE) +options("golem.app.prod" = FALSE) run_app() # add parameters here (if any) + +# Debug just the UI without login: + +# shiny::shinyApp( +# ui = .app_ui, +# server = .app_server +# )