首页 > 解决方案 > 发生 API 错误:在 slack 中打开模式时出现 invalid_arguments

问题描述

我正在尝试在我的 slack 应用程序中打开一个模式

我正在尝试关注模态部分的官方 github 页面,但出现错误

(node:20175) UnhandledPromiseRejectionWarning: Error: An API error occurred: invalid_arguments
    at Object.platformErrorFromResult (/node_modules/@slack/web-api/src/errors.ts:94:5)
    at WebClient.apiCall (/node_modules/@slack/web-api/src/WebClient.ts:159:13)
    at process.internalTickCallback (internal/process/next_tick.js:77:7)

我可以成功接收并开始处理 slack 发送的交互操作(在我的 slack 应用程序上,我注册了一个带有适当回调 id 的交互组件 > 操作)

然后,我尝试在处理此交互操作时打开一个模式,但它崩溃了

# In my app I build the message adapter 
const slackInteractions = createMessageAdapter(process.env.SLACK_SIGNING_SECRET)
slackInteractions.action({ callbackId: CALLBACK_IDS.MY_CALLBACK_ID }, myHandler)
# which is then mounted as an express middleware, no problem so far

# the handler supposed to open a modal
import { WebClient } from '@slack/web-api';

export default (payload, respond) => {
  try {
    console.info('Slack payload for my callback', payload);
    const trigger_id = payload.trigger_id;
    const web = new WebClient(process.env.SLACK_OAUTH_ACCESS_TOKEN)
    const openModalPayload = {
      trigger_id,
      view: {
        type: 'modal',
        callback_id: 'view_identifier',
        title: {
          type: 'plain_text',
          text: 'Modal title'
        },
        blocks: [
          {
            type: 'input',
            label: {
              type: 'plain_text',
              text: 'Input label'
            },
            element: {
              type: 'plain_text_input',
              action_id: 'value_indentifier'
            }
          }
        ]
      }
    };
    console.log(openModalPayload)
    web.views.open(openModalPayload) # <<- this async call seems to be crashing

标签: node.jsslack-api

解决方案


我打开了一个问题并修复了文档,基本上不可能在视图有效负载中没有提交按钮的情况下查看带有输入的视图

      submit: {
        type: 'plain_text',
        text: 'Submit'
      },

推荐阅读