typescript 在螺栓松动模式点击按钮后如何通过输入值?

cxfofazt  于 2023-02-17  发布在  TypeScript
关注(0)|答案(1)|浏览(102)

我试图通过模态输入框的值后,单击“提交”。但我不知道如何获得的值。我已经搜索了确认,身体,客户端,负载,但我找不到它。
我已经在松弛的API页面注册了快捷方式。
还有,我也不知道如何关闭模态。你能帮我吗?
这是我的密码。

import { App, BlockAction, ButtonAction, InputBlock } from "@slack/bolt";

const app = new App({
  appToken: SLACK_APP_TOKEN,
  token: SLACK_BOT_TOKEN,
  socketMode: true
});

// ....

app.action('update-today-attendance', async ({ ack, body, client, payload }) => {
  await ack();

  const values = (<ButtonAction>(<BlockAction>body).actions[0]).value.split(' / ');

  const result = await client.views.open({
    trigger_id: (<BlockAction>body).trigger_id,
    view: {
      type: "modal",
      callback_id: 'update-today-attendance-button-clicked',
      title: {
        "type": "plain_text",
        "text": "TITLE",
        "emoji": true
      },
      submit: {  // ⬅️ Here, Submit button
        "type": "plain_text",
        "text": "Submit",
        "emoji": true
      },
      "close": {
        "type": "plain_text",
        "text": "Cancel",
        "emoji": true
      },
      blocks: [
        {
          "type": "input",  // ⬅️ Here is input!
          "element": {
            "type": "plain_text_input",
            "action_id": "plain_text_input-action",
          },
          "label": {
            "type": "plain_text",
            "text": "memo",
            "emoji": true
          }
        }
      ]
    }
  });
});

app.view('update-today-attendance-button-clicked', async ({ ack, body, client, payload }) => {
  const userId = body.view.title.text.split(' - ')[1];

  const adminName = body.user.name;

  // ⬅️ Here, I want to get value of input

  const response = await axios.put(
    `${SERVER_URL}/today/${userId}`, 
    { adminName, memo: '????' }
  );  

  // ⬅️ Here, I want to close modal
})

app.start().catch((error) => {
  console.error(error);

  process.exit(1);
});
qv7cva1a

qv7cva1a1#

一旦你在app.view订阅中调用await ack(),模态将自动关闭。请记住,它应该在用户提交模态后3秒内完成。
并且用户提供的数据应该在view.state.values中找到,如果为空,检查你的modal的块类型是否为input

相关问题