Opening a new Modal after form submission Slack Bot

Viewed 472

So I've created a slack bot that opens a modal with a form on it. When the form is submitted, I want another modal to open or the same modal to update saying

form submitted successfully!

For some reason the second modal doesn't open up. I've tried using views.push, views.open and views.update, but it's not working. Maybe I'm using the wrong parameters? I've included my code below.

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))
}

Here are my JSON code blocks:

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": [
        {
         ...
        }
    ]
}
0 Answers
Related