我使用web-hook在Slack频道中发布了一条模式交互消息,但该消息没有显示在Slack频道中。
Slack文档中有一些关于触发器id的信息,但这些信息非常混乱。
下面是我的JSON有效负载,我正在使用来自Slack的预构建模板,并使用web-hook将消息发送到Slack通道。
var message={};
var attachments = [];
var attachment = {
"type": "modal",
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"title": {
"type": "plain_text",
"text": "Your accommodation",
"emoji": true
},
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Please choose an option where you'd like to stay from Oct 21 - Oct 23 (2 nights).",
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Airstream Suite*\n*Share with another person*. Private walk-in bathroom. TV. Heating. Kitchen with microwave, basic cooking utensils, wine glasses and silverware."
},
"accessory": {
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/Streamline-Beach.png",
"alt_text": "Airstream Suite"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "1x Queen Bed"
},
{
"type": "mrkdwn",
"text": "|"
},
{
"type": "mrkdwn",
"text": "$220 / night"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Choose",
"emoji": true
},
"value": "click_me_123"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Details",
"emoji": true
},
"value": "click_me_123"
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Redwood Suite*\n*Share with 2 other person*. Studio home. Modern bathroom. TV. Heating. Full kitchen. Patio with lounge chairs and campfire style fire pit and grill."
},
"accessory": {
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/redwoodcabin.png",
"alt_text": "Redwood Suite"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "1x King Bed"
},
{
"type": "mrkdwn",
"text": "|"
},
{
"type": "mrkdwn",
"text": "$350 / night"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "✓ Your Choice",
"emoji": true
},
"style": "primary",
"value": "click_me_123"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Details",
"emoji": true
},
"value": "click_me_123"
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Luxury Tent*\n*One person only*. Shared modern bathrooms and showers in lounge building. Temperature control with heated blankets. Lights and electrical outlets."
},
"accessory": {
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/tent.png",
"alt_text": "Redwood Suite"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "1x Queen Bed"
},
{
"type": "mrkdwn",
"text": "|"
},
{
"type": "mrkdwn",
"text": "$260 / night"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Choose",
"emoji": true
},
"value": "click_me_123"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Details",
"emoji": true
},
"value": "click_me_123"
}
]
},
{
"type": "divider"
}
]
};
attachments.push(attachment);
message.attachments = attachments;
print(JSON.stringify(message));
发布于 2020-09-17 09:51:09
你需要一个trigger_id来打开一个模式。基本上,只有当用户说“显示模式!”时,Slack才会让你显示模式!这可以防止开发人员向毫无戒心的用户发送恼人的、不想要的模态。您可以在用户与其中一个应用程序“entry points”交互时获取trigger_id:
当用户与其中一个入口点进行交互时,他们告诉您他们想要查看该模式,因此Slack将向您发送一个带有trigger_id的interaction payload。对于全局快捷方式,该有效负载可能类似于this
{
"type": "shortcut",
"token": "XXXXXXXXXXXXX",
"action_ts": "1581106241.371594",
"team": {
"id": "TXXXXXXXX",
"domain": "shortcuts-test"
},
"user": {
"id": "UXXXXXXXXX",
"username": "aman",
"team_id": "TXXXXXXXX"
},
"callback_id": "shortcut_create_event",
"trigger_id": "944799105734.773906753841.38b5894552bdd4a780554ee59d1f3638"
}所以基本上,你需要首先创建一个,并设置你的应用程序来接收来自Slack的POST请求。
一旦你知道用户想要显示模式,你可以告诉Slack打开模式。创建一个view payload (代码中的附件),并包含您收到的trigger_id。将此有效负载发送到views.open端点。请注意,您并没有像在代码中那样发送消息有效负载,请记住,trigger_id将在3秒内过期。
var payload = {
trigger_id: "944799105734.773906753841.38b5894552bdd4a780554ee59d1f3638",
view: {
"type": "modal",
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"title": {
"type": "plain_text",
"text": "Your accommodation",
"emoji": true
},
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Please choose an option where you'd like to stay from Oct 21 - Oct 23 (2 nights).",
"emoji": true
}
}
]
}
};下面是描述谁做什么以及按什么顺序做的整个流程:
┌────────────────────────────────────────────────────────────────────────────────────────┐
│◜◜◜◜◜◜◜◜◜◜◜◜◜◜┌─────────────┐◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜┌─────────────┐◜│
│◜┌─────────┐◜◜│ Selects a │◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│ Sees the │◜│
│◜│ USER │◜◜│ shortcut │─┐◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜┌─▶│ modal │◜│
│◜└─────────┘◜◜│ │◜│◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│◜◜│ │◜│
│◜◜◜◜◜◜◜◜◜◜◜◜◜◜└─────────────┘◜│◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│◜◜└─────────────┘◜│
├──────────────────────────────▼──────────────────────────────────────┴──────────────────┤
│ ┌─────────────┐ ┌─────────────┐ │
│ ┌──────────┐ │ Generates │ │ Opens the │ │
│ │ SLACK │ │ interaction │ │ modal │ │
│ └──────────┘ │ payload │ │ │ │
│ └─────────────┘ └─────────────┘ │
├──────────────────────────────┬──────────────────────────────────────▲──────────────────┤
│◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│◜◜◜┌─────────────┐◜◜◜┌─────────────┐◜◜│◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│
│◜┌──────────┐◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│◜◜◜│ Extracts │◜◜◜│ Sends modal │◜◜│◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│
│◜│ YOUR APP │◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜└──▶│ trigger_id │──▶│ data with │──┘◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│
│◜└──────────┘◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│ │◜◜◜│ trigger_id │◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│
│◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜└─────────────┘◜◜◜└─────────────┘◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜◜│
└────────────────────────────────────────────────────────────────────────────────────────┘https://stackoverflow.com/questions/63929599
复制相似问题