【问题标题】:How can I submit the results? Slack bolt-js, JavaScript如何提交结果? Slack bolt-js,JavaScript
【发布时间】:2021-07-22 09:15:25
【问题描述】:

问题是我有第一段代码,它向我发送了两个输入,一个用于添加约会,第二个用于删除约会。我在此代码下方留下了一张图片,以便您将其可视化。

@Command('/echo')
  async appontmentCommand({ ack, say }) {
    await ack();
    try {
      await say({
        type: 'home',
        blocks: [
          {
            type: 'section',
            text: {
              type: 'plain_text',
              text: 'Ici, vous pouvez ajouter ou supprimer votre rendez-vous manuellement.',
              emoji: true,
            },
          },
          {
            type: 'divider',
          },
          {
            type: 'section',
            text: {
              type: 'mrkdwn',
              text: 'Pour ajouter un rendez-vous.',
            },
            accessory: {
              type: 'button',
              text: {
                type: 'plain_text',
                text: 'Ajouter',
                emoji: true,
              },
              value: 'click_me_123',
              action_id: 'button-action-add',
            },
          },
          {
            type: 'section',
            text: {
              type: 'mrkdwn',
              text: 'Pour supprimer un rendez-vous',
            },
            accessory: {
              type: 'button',
              text: {
                type: 'plain_text',
                text: 'Supprimer',
                emoji: true,
              },
              value: 'click_me_123',
              action_id: 'button-action',
            },
          },
        ],
      });

      console.log('Works correctly $$¤¤$$');
    } catch (error) {
      console.error('error right here $$¤¤$$: ',error);
    }
  }

IMAGE WITH THE RESULT OF LAST PIECE OF CODE RIGHT HERE

当我点击图片中显示为“Ajouter”的添加按钮时,它会打开一个带有这些标签和输入的模式,这是允许我执行此操作的代码。

@Action('button-action-add')
  async addAppointmentAction({ ack, body }) {
    await ack();
    try {
      const result = await this.app.client.views.open({
        token: process.env.SLACK_BOT_TOKEN,
        trigger_id: body.trigger_id,
        view: {
          type: 'modal',
          callback_id: 'view_1',
          title: {
            type: 'plain_text',
            text: 'Add rdv',
          },
          submit: {
            type: 'plain_text',
            text: 'Add',
          },
          close: {
            type: 'plain_text',
            text: 'Cancel',
            emoji: true,
          },

          blocks: [
            {
              type: 'input',
              element: {
                type: 'datepicker',
                initial_date: '' + format(new Date(), 'yyyy-MM-dd'),
                placeholder: {
                  type: 'plain_text',
                  text: 'Select a date',
                  emoji: true,
                },
                action_id: 'datepicker-action',
              },
              label: {
                type: 'plain_text',
                text: 'Day appointment',
                emoji: true,
              },
            },
            {
              type: 'input',
              element: {
                type: 'plain_text_input',
                action_id: 'plain_text_input-action',
                placeholder: {
                  type: 'plain_text',
                  text: 'Select a hour, ex: 14:30',
                  emoji: true,
                },
              },
              label: {
                type: 'plain_text',
                text: 'Time of appointment',
                emoji: true,
              },
            },
            {
              type: 'input',
              element: {
                type: 'plain_text_input',
                action_id: 'plain_text_input-action',
                placeholder: {
                  type: 'plain_text',
                  text: 'Issue',
                  emoji: true,
                },
              },
              label: {
                type: 'plain_text',
                text: 'Issue ',
                emoji: true,
              },
            },
          ],
        },
      });
      console.log(body.trigger_id);
    } catch (error) {
      console.error(error);
    }
  }

IMAGE WITH THE RESULT OF LAST PIECE OF CODE RIGHT HERE

但是当我单击提交按钮(那里显示添加,但它是一个 sumbit 按钮)以在后端获取结果时,我收到此错误:ERROR THAT I GET

我知道你必须推动才能使用 view.sumbition 方法,但我不知道该怎么做,有人可以帮助我。

【问题讨论】:

    标签: javascript bots slack-api slack-block-kit


    【解决方案1】:

    要读取模态提交的payload,需要处理view_submission

    // Listen for view_submission modal events
    app.view(callbackId, fn);
    

    看看这个:https://slack.dev/bolt-js/concepts#view_submissions

    技术细节: https://github.com/slackapi/bolt-js#listening-for-events

    【讨论】:

    • 但我必须先推,不是吗?
    • 如果您的模态窗口显示在 UI 上,则表示已处理好推送。现在您需要在单击“添加”提交按钮后接受该值。试试这个,让我知道它是否有效。
    • 我找不到办法,所以我一直在努力,直到你的最后一条消息......你会怎么做的
    • 您的函数将如下所示: app.view('view_1', async ({ ack, body, view, client }) => { } 。您还需要在视图中添加 block_id。然后你可以使用类似的东西: const val = view['state']['values']['block_id']['datepicker-action']
    猜你喜欢
    • 1970-01-01
    • 2023-01-04
    • 2022-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    相关资源
    最近更新 更多