我想创建一个 slack 应用程序来侦听用户发布的消息,然后在频道中使用一些建议和按钮为该用户回复一条短暂的消息。我有一个订阅事件 API 的 lambda,它正在接收发布的每条消息。我设置了另一个 lambda 来发布临时消息,当我从邮递员(通过 API 网关)调用它时,它成功了,但是当我尝试按下按钮时出现错误:this app responded with a 400 status code
我已经在我的 slack 应用程序的交互部分中指定了请求 URL,该 URL 与用于调用首先发送消息的 Lambda 的 URL 相同。当我检查日志时,我得到了邮递员的第一次点击,但在按下按钮后,我不再收到任何 ping。
我很茫然,不知道从哪里开始,我阅读并重新阅读了 slack 文档并检查了许多堆栈溢出帖子,但没有一个帮助我找到答案。任何帮助将不胜感激。
发送消息的 Lambda:
const axios = require('axios')
exports.handler = async (event) => {
// TODO implement
console.log("Request: ", event)
const response = {
statusCode: 200,
};
let params = {
"channel": "hardcoded_channelID",
"user": "hardcoded_userID",
"text": "Hello World",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Suggestion 1"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Helpful"
},
"value": "helpful",
"action_id": "1_helpful"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Not Helpful"
},
"value": "notHelpful",
"action_id": "1_nothelpful"
},
{
"type": "button",
"style": "danger",
"text": {
"type": "plain_text",
"text": "Dismiss"
},
"value": "dismiss",
"action_id": "1_dismiss"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Suggestion 2"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Helpful"
},
"value": "helpful",
"action_id": "2_heplful"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Not Helpful"
},
"value": "notHelpful",
"action_id": "2_nothelpful"
},
{
"type": "button",
"style": "danger",
"text": {
"type": "plain_text",
"text": "Dismiss"
},
"value": "dismiss",
"action_id": "2_dismiss"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Suggestion 3"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Helpful"
},
"value": "helpful",
"action_id": "3_helpful"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Not Helpful"
},
"value": "notHelpful",
"action_id": "3_nothelpful"
},
{
"type": "button",
"style": "danger",
"text": {
"type": "plain_text",
"text": "Dismiss"
},
"value": "dismiss",
"action_id": "3_dismiss"
}
]
}
]
}
let config = {
method: 'post',
url: 'https://slack.com/api/chat.postEphemeral',
headers: {
'Authorization': 'Bearer xoxb-token',
'Content-Type': 'application/json'
},
data: params
};
const res = await axios(config);
console.log(res);
return response;
};