【问题标题】:R Plumber Slack Bot ResponseR Plumber Slack 机器人响应
【发布时间】:2021-02-03 15:31:53
【问题描述】:

我正在尝试使用 Plumber 创建对 slack 的机器人响应,并且在从命令行查询或从 swagger 进行测试时,我可以使模型正常工作并获得文本响应。当我使用来自 Slack 的斜杠命令时,虽然响应回来了,但通道中只显示了一个空响应。我已经尝试了一些小的调整,但它对我不起作用,所以希望拥有 Slack Plumber 机器人的人可以看到我做错了什么。

    #' return chatbot response
#' @param text the message used for analysis
#' @post /response
function(text=" ", res) {
  
  # turn parsed message into tidy dataframe
  msg_df <- tibble(line = 1:1, text = text)
  
  # unnest words in dataframe and create response
  msg_df <<- msg_df %>% unnest_tokens(word, text)
  body <- pred(msg_df)
  my_message <- list(response_type = unbox("in_channel"),
                     text=unbox(body))

  return(my_message)
}

这就是我在 slack 停靠并运行后从 slack 中得到的结果。

返回的响应如下所示,这是我在 Slack 教程中看到的

响应正文

{
  "response_type": "in_channel",
  "text": "some text information"
}

非常感谢任何想法!

【问题讨论】:

  • 在您的管道工函数中添加browser() 语句,在res 之后添加参数req 并检查您在req 环境中从slack 收到的内容。

标签: r slack slack-api plumber slack-commands


【解决方案1】:

最初的解决方案是 Plumber 序列化程序可以更改为:

@serializer contentType list(type="text/plain") #提供简单的文本响应

如果您需要的只是没有格式的纯文本(在我的情况下可以),则此方法有效

【讨论】:

    猜你喜欢
    • 2021-08-31
    • 2017-08-28
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    • 2018-04-01
    • 2016-03-02
    • 2017-07-27
    相关资源
    最近更新 更多