【问题标题】:SlackBot OpenModal Error: "Missing Charset"SlackBot OpenModal 错误:“缺少字符集”
【发布时间】:2020-08-23 17:29:13
【问题描述】:

我想通过 Zapier 进行 api 调用以在 Slack 中打开一个 Modal。

但我总是得到错误:

ok: false
error:  invalid_json
warning:    missing_charset
response_metadata:
warnings:
1:  missing_charset

这是我的请求正文:

{
"token":"XXXXXXXXX",
"trigger_id":"XXXXXXXXXX",
"dialog": {
  "callback_id": "projekt-verantwortliche",
  "title": "Projektverantwortliche auswählen",
  "submit_label": "Request",
  "state": "Limo",
  "elements": [
    {
      "type": "users_select",
      "action_id": "projekt-projektleiter",
      "placeholder": {
         "type":"plain_text",
         "text":"Projektleiter auswählen"
        },
    },
     {
      "type": "users_select",
      "action_id":"projekt-berater",
      "placeholder": {
         "type":"plain_text",
         "text":"Berater auswählen"
        }
    }
  ]
}
}

我做错了什么?

这里是整个通话的屏幕截图:

【问题讨论】:

    标签: slack slack-api slack-dialog


    【解决方案1】:

    解决方法可以在这个documentation:

    您在 POST 正文中包含的 JSON 无法解析。这可能是因为它实际上不是 JSON,或者您没有正确设置 HTTP Content-type 标头。确保您的 JSON 属性键是用双引号 (") 字符包裹的字符串。

    您只需要删除一个逗号,然后它应该可以工作:

    {
       "token":"XXXXXXXXX",
       "trigger_id":"XXXXXXXXXX",
       "dialog":{
          "callback_id":"projekt-verantwortliche",
          "title":"Projektverantwortliche auswählen",
          "submit_label":"Request",
          "state":"Limo",
          "elements":[
             {
                "type":"users_select",
                "action_id":"projekt-projektleiter",
                "placeholder":{
                   "type":"plain_text",
                   "text":"Projektleiter auswählen"
                }
             },
             {
                "type":"users_select",
                "action_id":"projekt-berater",
                "placeholder":{
                   "type":"plain_text",
                   "text":"Berater auswählen"
                }
             }
          ]
       }
    }
    

    如果您对 content-type 标头使用 set the charset,则可以删除警告 missing_charset。例如:

    Content-type: application/json; charset=utf-8
    

    【讨论】:

    • 谢谢!现在我收到另一个错误:[ERROR] 元素 0 的 type 无效。难道不能在模态中使用“users_select”类型吗?
    • 对话框的一个元素只有三个different types:文本、文本区域和选择。
    • 但是如果你想使用模态,我认为给定的请求不能工作。您可以在documentation 中找到一个很好的示例。
    • 我认为这不能与请求一起使用。您必须将逻辑放入您自己的代码中。然后,您可以例如编写以下 code in Kotlin 以在请求中使用 ID:val id = data.id ?: default_id。 Slack 只有一些默认值,例如users.list:limit = 0.
    • 我不知道您收到的请求是哪个 url,但在 documentation 中您可以找到关闭视图的说明。
    猜你喜欢
    • 2021-10-16
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2016-10-04
    • 2017-02-26
    相关资源
    最近更新 更多