2

所以我创建了一个 slack 机器人,它可以打开一个带有表单的模式。提交表单后,我希望打开另一个模式或更新相同的模式

表单提交成功!

由于某种原因,第二个模式没有打开。我已经尝试使用views.push,views.openviews.update,但它不起作用。也许我使用了错误的参数?我在下面包含了我的代码。

slackInteractions.shortcut({ callback: 'devsquibby', type: 'shortcut'  }, async (payload) => {
    if (payload.type=='shortcut') {
      console.log('we have action', payload)
      try {
            await webClient.views.open({
                trigger_id: payload.trigger_id,
                token: token,
                view: modalJsonBlock
            })
            // respond({
            //  text: 'Processing...',
            // });
        } catch (e) {
            'error',
            console.log(JSON.stringify(e))
        }

         // The return value is used to update the message where the action occurred immediately.
         // Use this to items like buttons and menus that you only want a user to interact with once.
    }

 if (payload.type=="view_submission") {

    try {
        console.log('success', payload.view.id)
        await webClient.views.update({
            view_id: payload.view.id,
            token: token,
            view: sampleJsonBlock
        })
        const blockData = payload.view.state
        // console.log('SUBMISSION THOURHG ACTION', blockData.values.type_block)

        // const user = payload.user.username
        // const classSelection = blockData.values.class_block.class_input.selected_option.text.text
        // const assignmentSelection = blockData.values.assignment_block.assignment_input.selected_option.text.text
        // const question = blockData.values.question_block.question_input.value
        const form = {
                    user: payload.user.username,
                    classSelection: blockData.values.class_block.class_input.selected_option.text.text,
                    assignmentSelection: blockData.values.assignment_block.assignment_input.selected_option.text.text,
                    question: blockData.values.question_block.question_input.value,
                    type: blockData.values.type_block.type_input.selected_option.text.text,
                    repo_url: blockData.values.repo_block.repo_input.value
            
        }
        console.log('submission', form)
        await postAirTable(form);
    }
  catch (e) {
    'error',
    console.log(JSON.stringify(e))
}

这是我的 JSON 代码块:

const sampleJsonBlock = {
    "type": "modal",
    "close": {
        "type": "plain_text",
        "text": "Close",
        "emoji": true
    },
    "title": {
        "type": "plain_text",
        "text": "Success!",
        "emoji": true
    },
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Submission Successful!"
            }
        },
        {
            "type": "image",
            "title": {
                "type": "plain_text",
                "text": "Success!"
            },
            "image_url": "https://media.giphy.com/media/nXxOjZrbnbRxS/giphy.gif",
            "alt_text": "success submission"
        }
    ]
}
const modalJsonBlock = {
    "type": "modal",
    "callback_id": ...,
    "submit": {
        "type": "plain_text",
        "text": "Submit",
        "emoji": true
    },
    "close": {
        "type": "plain_text",
        "text": "Cancel",
        "emoji": true
    },
    "title": {
        "type": "plain_text",
        "text": "Student Question Bot!",
        "emoji": true
    },
    "blocks": [
        {
         ...
        }
    ]
}
4

0 回答 0