微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

来自应用程序教程的工作流生成器步骤:提供故障代码的服务器端问题

如何解决来自应用程序教程的工作流生成器步骤:提供故障代码的服务器端问题

我正在学习 Workflow Builder Steps from Apps 中的教程: https://api.slack.com/tutorials/workflow-builder-steps

故障模板: https://glitch.com/edit/#!/steps-from-apps

我无法在 Slack 中验证重定向 URL,我认为这是因为我在重新混合代码后立即在 glitch.com 上看到服务器端错误

错误信息:

ReferenceError: require is not defined

file:///app/index.js:1
const { App,WorkflowStep } = require("@slack/bolt");
ReferenceError: require is not defined
Jump Toat file:///app/index.js:1:31
at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
at async Loader.import (internal/modules/esm/loader.js:166:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)

故障: https://glitch.com/edit/#!/tarry-tremendous-walnut

知道发生了什么吗?

谢谢!

瑞克

index.js:

const { App,WorkflowStep } = require("@slack/bolt");

const app = new App({
  token: process.env.SLACK_BOT_TOKEN,signingSecret: process.env.SLACK_SIGNING_SECRET
});

// This code saves tasks to this object
// Tasks are stored in memory and not in a persistent database
// This object is refreshed each time your Glitch app restarts
// The result is that your App Home will be cleared with each restart
let TASKS_DB = {};

const ws = new WorkflowStep("copy_review",{
  edit: async ({ ack,step,configure }) => {
    await ack();

    const blocks = [
      {
        type: "section",block_id: "intro-section",text: {
          type: "plain_text",text:
            "Create a task in one of the listed projects. The link to the task and other details will be available as variable data in later steps.",emoji: true
        }
      },{
        type: "input",block_id: "task_name_input",element: {
          type: "plain_text_input",action_id: "name",placeholder: {
            type: "plain_text",text: "Write a task name"
          }
        },label: {
          type: "plain_text",text: "Task name",block_id: "task_description_input",action_id: "description",text: "Write a description for your task"
          }
        },text: "Task description",block_id: "task_author_input",action_id: "author",text: "Task author",emoji: true
        }
      }
    ];

    await configure({ blocks });
  },save: async ({ ack,update,view }) => {
    await ack();

    const {
      task_name_input,task_description_input,task_author_input
    } = view.state.values;

    const taskName = task_name_input.name.value;
    const taskDescription = task_description_input.description.value;
    const taskAuthorEmail = task_author_input.author.value;

    const inputs = {
      taskName: { value: taskName },taskDescription: { value: taskDescription },taskAuthorEmail: { value: taskAuthorEmail }
    };

    const outputs = [
      {
        type: "text",name: "taskName",label: "Task Name"
      },{
        type: "text",name: "taskDescription",label: "Task Description"
      },name: "taskAuthorEmail",label: "Task Author Email"
      }
    ];

    await update({ inputs,outputs });
  },execute: async ({ step,complete,fail,client }) => {
    try {
      const { taskName,taskDescription,taskAuthorEmail } = step.inputs;

      const outputs = {
        taskName: taskName.value,taskDescription: taskDescription.value,taskAuthorEmail: taskAuthorEmail.value
      };

      const user = await client.users.lookupByEmail({
        email: taskAuthorEmail.value
      });

      const userId = user.user.id;

      const newTask = {
        task_name: taskName.value,task_description: taskDescription.value
      };

      TASKS_DB[userId] = TASKS_DB[userId]
        ? [...TASKS_DB[userId],newTask]
        : [newTask];

      const taskBlocksItems = TASKS_DB[userId].map(task => {
        return [
          {
            type: "section",text: {
              type: "plain_text",text: task.task_name,emoji: true
            }
          },{
            type: "divider"
          }
        ];
      });

      const homeHeader = [
        {
          type: "header",text: {
            type: "plain_text",text: "Workflow Builder - Steps from Apps task list",emoji: true
          }
        },{
          type: "context",elements: [
            {
              type: "mrkdwn",text:
                "_This is a list of tasks generated by your example Workflow Builder Task creation step,found in this tutorial https://api.slack.com/tutorials/workflow-builder-steps. These tasks are stored in the Glitch client,not in a database and refresh every time your Glitch app is restarted. If you'd like to store these tasks in a database,please check out this Glitch page for more information https://glitch.com/@storage _"
            }
          ]
        },{
          type: "divider"
        }
      ];
      const taskBlocks = [].concat.apply([],taskBlocksItems);

      const blocks = homeHeader.concat(taskBlocks);

      // update app home
      let view = {
        type: "home",blocks
      };

      const usersTasks = TASKS_DB[userId];

      await client.views.publish({
        user_id: userId,view: JSON.stringify(view)
      });

      // If everything was successful,complete the step
      await complete({ outputs });
    } catch (e) {
      // Todo if something went wrong,fail the step ...
      app.logger.error("Error completing step",e.message);
    }
  }
});

app.step(ws);

(async () => {
  // Start your app
  const port = process.env.PORT || 3000;
  await app.start(port);

  console.log(`⚡️ index.js Bolt app is running on port ${port}!`);
})();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。