@@ -36,6 +36,7 @@ switch_repo_addin <- function()
3636# ' @importFrom svMisc assign_temp get_temp
3737# ' @importFrom rstudioapi sendToConsole
3838# ' @importFrom utils ? methods
39+ # ' @importFrom httr2 request req_body_json req_headers req_perform
3940.sdd_help_addin <- function () {
4041
4142 get_help <- function (message ) {
@@ -108,12 +109,17 @@ switch_repo_addin <- function()
108109 l <- length(fun_env_names )
109110 if (! l ) {# Function not found
110111 # Ask help system directly
111- cmd <- parse(text = paste0(" ?" , cur_fun ))
112- if (length(eval(cmd ))) {# Help page found
113- fun <- cur_fun
114- ns <- " " # Unknown
115- alt_fun_msg <- " "
116- } else {# Not found
112+ if (cur_fun != " " ) {
113+ cmd <- parse(text = paste0(" ?" , cur_fun ))
114+ if (length(eval(cmd ))) {# Help page found
115+ fun <- cur_fun
116+ ns <- " " # Unknown
117+ alt_fun_msg <- " "
118+ } else {# Not found
119+ fun <- " "
120+ ns <- " "
121+ }
122+ } else {# No function?
117123 fun <- " "
118124 ns <- " "
119125 }
@@ -396,6 +402,26 @@ switch_repo_addin <- function()
396402 # message(help_code)
397403 rstudioapi :: sendToConsole(help_code , execute = TRUE , echo = TRUE ,
398404 focus = FALSE )
405+
406+ # If help page (not chatbot), record the data in the database
407+ if (context $ engine == " SciViews Chatbot" )
408+ return (invisible (help_code ))
409+
410+ chat_url <- getOption(" SciViews.chatbot.url" ,
411+ Sys.getenv(" SCIVIEWS_CHATBOT_URL" , " " ))
412+ api_key <- Sys.getenv(" CONNECT_API_KEY" , " " )
413+ if (chat_url != " " && api_key != " " ) {
414+ help_url <- paste0(dirname(chat_url ), " /help" )
415+ request <- httr2 :: request(help_url ) | >
416+ httr2 :: req_headers(" Accept" = " application/json" ,
417+ " Authorization" = paste(" Key" , api_key ))
418+ context $ code <- help_code
419+ request <- request | >
420+ httr2 :: req_body_json(context )
421+ res <- try(httr2 :: req_perform(request ), silent = TRUE )
422+ svMisc :: assign_temp(" sdd_help_result" , res , replace.existing = TRUE )
423+ }
424+
399425 invisible (help_code )
400426}
401427
0 commit comments