如何将输入值传递到松弛螺栓框架中模态的下一个视图?
How to pass the value of input to the next view of a modal in slack bolt framework?
我正在使用 bolt(出现故障)构建 Slack API。我对此很陌生,所以不确定如何做这个特定的想法。
我使用斜杠命令打开了一个模式,其中列出了三个单选输入,并且有一个操作按钮将使用 client.views.update 来呈现多行输入。
我希望选择的选项是多行代码的初始值。
// this is required: github.com/slackapi/bolt
app.command("/slashcommand", async ({ ack, payload, context }) => {
// Acknowledge the command request
ack();
try {
const result = app.client.views.open({
token: context.botToken,
// Pass a valid trigger_id within 3 seconds of receiving it
trigger_id: payload.trigger_id,
// View payload
view: {
type: "modal",
callback_id: 'modal_1',
title: {
type: "plain_text",
text: "Initiate Feedback",
emoji: true
}, /*
submit: {
type: "plain_text",
text: "Submit",
emoji: true
}, */
close: {
type: "plain_text",
text: "Cancel",
emoji: true
},
blocks: [
{
type: "context",
elements: [
{
type: "mrkdwn",
text:
"Modal first view"
}
]
},
{
type: "divider"
},
{
type: "section",
block_id: 'radio_block',
text: {
type: "mrkdwn",
text: "Select from one of the following options:"
},
accessory: {
type: "radio_buttons",
action_id: 'radio_input',
initial_option: {
text: {
type: "plain_text",
text: "One"
},
value: "one",
description: {
type: "plain_text",
text: "describe one"
}
},
options: [
{
text: {
type: "plain_text",
text: "One"
},
value: "one",
description: {
type: "plain_text",
text: "describe one"
}
},
{
text: {
type: "plain_text",
text: "Two"
},
value: "two",
description: {
type: "plain_text",
text: "describe two"
}
},
{
text: {
type: "plain_text",
text: "Three"
},
value: "three",
description: {
type: "plain_text",
text: "describe three"
}
}
]
}
},
{
type: "actions",
elements: [
{
type: "button",
text: {
type: "plain_text",
text: "Next",
emoji: true
},
action_id: "next_1"
}
]
}
]
}
});
console.log(result);
} catch (error) {
console.error(error);
}
});
// Listen for a button invocation with action_id `next_1` (assume it's inside of a modal)
app.action("next_1", async ({ ack, body, context }) => {
// VALUE FROM RADIO INPUT
// const val = Radio input value;
// Acknowledge the button request
ack();
try {
const result = app.client.views.update({
token: context.botToken,
// Pass the view_id
view_id: body.view.id,
// View payload with updated blocks
view: {
type: "modal",
// View identifier
callback_id: 'feed_1',
title: {
type: "plain_text",
text: "Share Feedback: message"
},
blocks: [
{
type: "section",
text: {
type: "plain_text",
text: 'You choose '
}
},
{
type: "input",
element: {
type: "plain_text_input",
// HERE IS WHERE THE RADIO OPTION GOES
initial_value: `One `,
multiline: true
},
label: {
type: "plain_text",
text: "Message",
emoji: true
}
}
],
submit: {
type: "plain_text",
text: "Submit"
}
}
});
console.log(result);
} catch (error) {
console.error(error);
}
});
好的,终于明白了!
1)确保您的单选按钮不在任何输入块中!
2) 使用 body.actions
在您的操作中输出您返回的有效载荷
一旦您看到返回的内容,就会更容易定位该值。
'''
app.action("next_1", async ({ ack, body, context }) => {
// Result of option selected
const val = JSON.stringify(body['actions'][0]);
// see the values
console.log(val);
// Acknowledge the button request
ack();
});
'''
更多详情:https://api.slack.com/reference/interaction-payloads/actions
我正在使用 bolt(出现故障)构建 Slack API。我对此很陌生,所以不确定如何做这个特定的想法。
我使用斜杠命令打开了一个模式,其中列出了三个单选输入,并且有一个操作按钮将使用 client.views.update 来呈现多行输入。
我希望选择的选项是多行代码的初始值。
// this is required: github.com/slackapi/bolt
app.command("/slashcommand", async ({ ack, payload, context }) => {
// Acknowledge the command request
ack();
try {
const result = app.client.views.open({
token: context.botToken,
// Pass a valid trigger_id within 3 seconds of receiving it
trigger_id: payload.trigger_id,
// View payload
view: {
type: "modal",
callback_id: 'modal_1',
title: {
type: "plain_text",
text: "Initiate Feedback",
emoji: true
}, /*
submit: {
type: "plain_text",
text: "Submit",
emoji: true
}, */
close: {
type: "plain_text",
text: "Cancel",
emoji: true
},
blocks: [
{
type: "context",
elements: [
{
type: "mrkdwn",
text:
"Modal first view"
}
]
},
{
type: "divider"
},
{
type: "section",
block_id: 'radio_block',
text: {
type: "mrkdwn",
text: "Select from one of the following options:"
},
accessory: {
type: "radio_buttons",
action_id: 'radio_input',
initial_option: {
text: {
type: "plain_text",
text: "One"
},
value: "one",
description: {
type: "plain_text",
text: "describe one"
}
},
options: [
{
text: {
type: "plain_text",
text: "One"
},
value: "one",
description: {
type: "plain_text",
text: "describe one"
}
},
{
text: {
type: "plain_text",
text: "Two"
},
value: "two",
description: {
type: "plain_text",
text: "describe two"
}
},
{
text: {
type: "plain_text",
text: "Three"
},
value: "three",
description: {
type: "plain_text",
text: "describe three"
}
}
]
}
},
{
type: "actions",
elements: [
{
type: "button",
text: {
type: "plain_text",
text: "Next",
emoji: true
},
action_id: "next_1"
}
]
}
]
}
});
console.log(result);
} catch (error) {
console.error(error);
}
});
// Listen for a button invocation with action_id `next_1` (assume it's inside of a modal)
app.action("next_1", async ({ ack, body, context }) => {
// VALUE FROM RADIO INPUT
// const val = Radio input value;
// Acknowledge the button request
ack();
try {
const result = app.client.views.update({
token: context.botToken,
// Pass the view_id
view_id: body.view.id,
// View payload with updated blocks
view: {
type: "modal",
// View identifier
callback_id: 'feed_1',
title: {
type: "plain_text",
text: "Share Feedback: message"
},
blocks: [
{
type: "section",
text: {
type: "plain_text",
text: 'You choose '
}
},
{
type: "input",
element: {
type: "plain_text_input",
// HERE IS WHERE THE RADIO OPTION GOES
initial_value: `One `,
multiline: true
},
label: {
type: "plain_text",
text: "Message",
emoji: true
}
}
],
submit: {
type: "plain_text",
text: "Submit"
}
}
});
console.log(result);
} catch (error) {
console.error(error);
}
});
好的,终于明白了! 1)确保您的单选按钮不在任何输入块中! 2) 使用 body.actions
在您的操作中输出您返回的有效载荷一旦您看到返回的内容,就会更容易定位该值。
'''
app.action("next_1", async ({ ack, body, context }) => {
// Result of option selected
const val = JSON.stringify(body['actions'][0]);
// see the values
console.log(val);
// Acknowledge the button request
ack();
});
'''
更多详情:https://api.slack.com/reference/interaction-payloads/actions