为了能够使用自定义负载发送所需的响应,您应该首先添加 Dialogflow 向 slack 发送请求所需的格式。
{
"slack": {
"text": "Testing custom payloads",
"attachments": []
}
}
在附件中,添加块格式,然后它应该以 Slack 方式将消息发送到您的机器人。
最终消息如下所示:
{
"slack": {
"text": "",
"attachments": [{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Where should we order lunch from?* Poll by <fakeLink.toUser.com|Mark>"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":sushi: *Ace Wasabi Rock-n-Roll Sushi Bar*\nThe best landlocked sushi restaurant."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Vote"
},
"value": "click_me_123"
}
},
{
"type": "context",
"elements": [
{
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/profile_1.png",
"alt_text": "Michael Scott"
},
{
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/profile_2.png",
"alt_text": "Dwight Schrute"
},
{
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/profile_3.png",
"alt_text": "Pam Beasely"
},
{
"type": "plain_text",
"emoji": true,
"text": "3 votes"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":hamburger: *Super Hungryman Hamburgers*\nOnly for the hungriest of the hungry."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Vote"
},
"value": "click_me_123"
}
},
{
"type": "context",
"elements": [
{
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/profile_4.png",
"alt_text": "Angela"
},
{
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/profile_2.png",
"alt_text": "Dwight Schrute"
},
{
"type": "plain_text",
"emoji": true,
"text": "2 votes"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":ramen: *Kagawa-Ya Udon Noodle Shop*\nDo you like to shop for noodles? We have noodles."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Vote"
},
"value": "click_me_123"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "No votes"
}
]
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Add a suggestion"
},
"value": "click_me_123"
}
]
}
]
}]
}
}