当用户使用斜杠命令时,我会向该用户发布一条短暂消息。当他们单击按钮时,我希望该短消息删除或更新。现在,我只是想让删除部分正常工作。
在Slack API文档中,它说将HTTP POST发送到response_url。用户单击按钮时获得的唯一response_url如下所示:https://hooks.slack.com/actions/XXXXXXXXX/YYYYYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ
当我将POST发送到该URL时,出现错误(我不确定错误是什么,我只知道我的代码在try / catch上失败)。
我发送到该URL的JSON看起来像这样:
{
"response_type" = "ephemeral",
"replace_original" = "true",
"delete_original" = "true",
"text" = ""
};
我在Slack API文档中看到它说我应该将JSON发送到以https://hooks.slack.com/services/开头的URL,但是我没有收到任何带有/ services /的response_url。
这是我用来发送响应的C#代码:
var replaceMsg = new NameValueCollection();
replaceMsg["delete_original"] = "true";
replaceMsg["replace_original"] = "true";
replaceMsg["response_type"] = "ephemeral";
replaceMsg["text"] = "";
var responseReplace = client.UploadValues(button.response_url, "POST", replaceMsg);
编辑:当我尝试发送该错误时,似乎出现404错误
Exception: System.Net.WebException: The remote server returned an error: (404) Not Found.
但是,当我将确切的URL粘贴到浏览器中时,却没有看到404,我看到了JSON。
有人可以引导我朝正确的方向发展吗?谢谢。
答案 0 :(得分:1)
不久前,我做了一些非常相似的事情,并且能够使它工作,尽管这很棘手。
这篇文章帮了我大忙:How to remove Ephemeral Messages
我会做两件事:
1)确保您知道POST响应失败是什么,因为它可能包含有用的信息。
2)好像您是在发送字符串"true"
而不是布尔值,我猜您可能想改为发送布尔值:
{
"response_type" = "ephemeral",
"replace_original" = true,
"delete_original" = true,
"text" = ""
};
答案 1 :(得分:0)
@theMayer和@Aaron是正确的。
设置标题可以解决此问题,就像这样:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}