Looking for help with Slack actions and dialog API

Hi there!

I am trying to understand why my Slack bot app isn’t responding with a dialog when I use the dialog.open API.

Background: I have successfully built my project on Glitch using this sample project slack-clipit-simplified as a base.

I am currently trying to build the same using Cloudflare workers, but something seems to be off.

The two files in the project are:

First file: index.js

import lookup from './src/handlers/lookup'

const Router = require('./router')

/**
 * Example of how router can be used in an application
 *  */
addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
    const app = new Router();
    app.post('/lookup', lookup);
    
    let response = await app.route(request);

    if (!response) {
      response = new Response('Not found', { status: 404 })
    }
  
    return response
}

Second file: /src/handlers/lookup.js

import qs from 'qs'
import axios from 'axios'

export default async function(request) {
    try {
        const payload = JSON.parse(request.body.payload)
        const { type, user, submission } = payload;

        if (type === 'message_action') {
            const dialogData = {
                token: 'actual-token-goes-here',
                trigger_id: payload.trigger_id,
                dialog: JSON.stringify(
                    {
                        title: 'Publish to a P2',
                        callback_id: 'p2',
                        submit_label: 'P2',
                        state: payload.message.thread_ts || payload.message.ts,
                        elements: [
                            {
                                label: `Post title`,
                                type: `text`,
                                name: `post_title`,
                                value: ``
                            }
                        ]
                    }
                )
            }

            axios.post('https://slack.com/api/dialog.open', qs.stringify(dialogData))
                .then((result => {
                    if(result.data.error) {
                        return new Response({ status: 500 })
                    } else {
                        return new Response({ status: 200 })
                    }
                }))
                .catch((err => {
                    return new Response({ status: 500 })
                }))
        }
    } catch(err) {
        const errorText = `Uh-oh! Something went wrong.`
        return new Reponse(errorText)
    }
}

If anyone has any clues on what I might be doing wrong, that would be much appreciated. Thanks for taking a look!

I must add that I am new to programming and having access to a console (in the case of Glitch, it’s the Tools > Logs section) helps me figure out things I might be missing.

In the case of working with Cloudflare workers’ wrangler CLI tool, there is no console for me to dig in. Thus, I am not sure how to log the requests that my route/endpoint receives.