@@ -36,6 +36,7 @@ switch_repo_addin <- function()
36
36
# ' @importFrom svMisc assign_temp get_temp
37
37
# ' @importFrom rstudioapi sendToConsole
38
38
# ' @importFrom utils ? methods
39
+ # ' @importFrom httr2 request req_body_json req_headers req_perform
39
40
.sdd_help_addin <- function () {
40
41
41
42
get_help <- function (message ) {
@@ -108,12 +109,17 @@ switch_repo_addin <- function()
108
109
l <- length(fun_env_names )
109
110
if (! l ) {# Function not found
110
111
# 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?
117
123
fun <- " "
118
124
ns <- " "
119
125
}
@@ -396,6 +402,26 @@ switch_repo_addin <- function()
396
402
# message(help_code)
397
403
rstudioapi :: sendToConsole(help_code , execute = TRUE , echo = TRUE ,
398
404
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
+
399
425
invisible (help_code )
400
426
}
401
427
0 commit comments