gpt4 book ai didi

javascript - 如何使用 Slack 模态输入的数据发送 channel 消息

转载 作者:行者123 更新时间:2023-12-02 20:52:26 25 4
gpt4 key购买 nike

我正在尝试构建一个 Slack 应用程序,该应用程序将在填写表单后启用发布 channel 消息。为此,我创建了一个调用模式的斜杠命令。现在我遇到一个问题,如何访问此输入数据并使用它来撰写将发送到所选 channel 的消息。

    app.command('/spotkanie', async ({ ack, body, context }) => {
// Acknowledge the command request
await ack();

try {
const result = await app.client.views.open({
token: context.botToken,
// Pass a valid trigger_id within 3 seconds of receiving it
trigger_id: body.trigger_id,
// View payload
view_id: "view_spotkanie",
user_id: "user",
view: {
"type": "modal",
"callback_id": "zaplanuj-spotkanie",
"title": {
"type": "plain_text",
"text": "Zaplanuj spotkanie",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Wyślij",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Anuluj",
"emoji": true
},
"blocks": [
{
"type": "input",
"element": {
"type": "datepicker",
"action_id": "data",
"placeholder": {
"type": "plain_text",
"text": "To wspaniały dzień na spotkanie!",
"emoji": true
}
},
"label": {
"type": "plain_text",
"text": "Data",
"emoji": true
}
},
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "godzina",
"placeholder": {
"type": "plain_text",
"text": "O której godzinie będzie spotkanie?",
"emoji": true
}
},
"label": {
"type": "plain_text",
"text": "Godzina",
"emoji": true
}
},
{
"type": "input",
"element": {
"type": "static_select",
"action_id": "rodzaj",
"placeholder": {
"type": "plain_text",
"text": "Jaki jest rodziaj spotkania?",
"emoji": true
},
"options": [
{
"text": {
"type": "plain_text",
"text": "spotkanie ogólne",
"emoji": true
},
"value": "value-0"
},
{
"text": {
"type": "plain_text",
"text": "spotkanie projektowe",
"emoji": true
},
"value": "value-1"
},
{
"text": {
"type": "plain_text",
"text": "spotkanie integracyjne",
"emoji": true
},
"value": "value-2"
}
]
},
"label": {
"type": "plain_text",
"text": "Rodzaj spotkania",
"emoji": true
}
},
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "miejsce",
"placeholder": {
"type": "plain_text",
"text": "Gdzie odbędzie się spotkanie?",
"emoji": true
}
},
"label": {
"type": "plain_text",
"text": "Miejsce",
"emoji": true
}
},
{
"type": "input",
"optional": true,
"element": {
"type": "plain_text_input",
"action_id": "dodatkowe info",
"placeholder": {
"type": "plain_text",
"text": "Wpisz dodatkowe informacje, takie jak agenda, link do spotkania itp",
"emoji": true
},
"multiline": true
},
"label": {
"type": "plain_text",
"text": "Więcej informacji",
"emoji": true
}
},
{
"block_id": "my_block_id",
"type": "input",
"label": {
"type": "plain_text",
"text": "Wyślij do",
},
"element": {
"action_id": "channel_id",
"type": "channels_select",
"response_url_enabled": true,
"placeholder": {
"type": "plain_text",
"text": "Gdzie wysłać powiadomienie o spotkaniu?",
"emoji": true
}
}
}
]

}
});
console.log(result);
}
catch (error) {
console.error(error);
}
});

app.view('zaplanuj-spotkanie', async ({ ack, body, view, context, say }) => {

现在,根据 Slack 说明,这个 app.view 应该可以让我访问输入数据,但我仍然不知道如何使用它。

最佳答案

要从模态接收输入文本,您应该使用 Slack 交互式消息。

// Example of handling a simple view submission
slackInteractions.viewSubmission('simple_modal_callback_id', (payload) => {
// Log the input elements from the view submission.
console.log(payload.view.state);

// The previous value is an object keyed by block_id, which contains objects keyed by action_id,
// which contains value properties that contain the input data. Let's log one specific value.
console.log(payload.view.state.my_block_id.my_action_id.value);

// Validate the inputs (errors is of the shape in https://api.slack.com/surfaces/modals/using#displaying_errors)
const errors = validate(payload.view.state);

// Return validation errors if there were errors in the inputs
if (errors) {
return errors;
}

// Process the submission
doWork();
});

这是一个链接https://slack.dev/node-slack-sdk/interactive-messages ,还可以使用聊天帖子方法向用户发送任何信息。这是一个链接https://api.slack.com/methods/chat.postMessage

关于javascript - 如何使用 Slack 模态输入的数据发送 channel 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61575407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com