在本地测试 Slack 交互式消息
Testing Slack Interactive Messages Locally
我目前正在使用 SlackConnector Repo https://github.com/noobot/SlackConnector。我创建了一个机器人,它会向我的聊天室发送交互式消息。我想为我的交互式按钮添加功能,但单击它们后我得到了这个响应。 Darn – that didn’t work. Only Slack Apps can add interactive elements to messages. Manage your apps here: https://api.slack.com/apps/
所以看起来我需要一个请求 URL 来克服我当前的障碍。有没有办法在本地测试交互式消息按钮?
List<SlackAttachment> attachments = new List<SlackAttachment>();
List<SlackAttachmentAction> actions = new List<SlackAttachmentAction>();
actions.Add(new SlackAttachmentAction
{
Name = "game",
Text = "chess",
Type = "button",
Value = "Chess"
});
actions.Add(new SlackAttachmentAction
{
Name = "game",
Text = "Falken's Maze",
Type = "button",
Value = "Maze"
});
actions.Add( new SlackAttachmentAction
{
Name = "game",
Text = "Thermonuclear War",
Type = "danger",
Value = "war"
});
attachments.Add(new SlackAttachment
{
Text = "Choose a game to play",
Fallback = "You are unable to choose a game",
CallbackId = "wopr_game",
ColorHex = "#3AA3E3",
Actions = actions
});
connection.Say(new BotMessage
{
ChatHub = chatHub,
Text = "Usage: !talk <user>",
Attachments = attachments
});
return Task.CompletedTask;
我试过的一件事是我将请求 URL 设置为使用从 https://webhook.site/#/ 生成的 url 并且在单击
时我仍然得到相同的响应
在我看来你有两个问题。
您没有 Slack 应用程序
交互式消息仅在您注册了 Slack 应用程序时才有效。这就是您收到该错误消息的原因。但是您可以轻松创建一个。只需转到 here 并单击 "Create a new app"。您需要一个的原因之一是您需要在用户单击按钮后告诉 Slack 向哪个 URL 发送请求。
Slack 无法访问您的本地应用程序
Slack 的交互式消息仅适用于可从 public Internet 访问的应用程序。因此,如果您想在本地开发您的应用程序,您需要向互联网开放您的 Web 服务器。有很多方法可以做到这一点,一种安全的方法是使用 VPN 隧道服务。此类服务的提供者之一是 ngrok,官方 Slack 教程中也推荐了它。我自己用过,效果很好。
我目前正在使用 SlackConnector Repo https://github.com/noobot/SlackConnector。我创建了一个机器人,它会向我的聊天室发送交互式消息。我想为我的交互式按钮添加功能,但单击它们后我得到了这个响应。 Darn – that didn’t work. Only Slack Apps can add interactive elements to messages. Manage your apps here: https://api.slack.com/apps/
所以看起来我需要一个请求 URL 来克服我当前的障碍。有没有办法在本地测试交互式消息按钮?
List<SlackAttachment> attachments = new List<SlackAttachment>();
List<SlackAttachmentAction> actions = new List<SlackAttachmentAction>();
actions.Add(new SlackAttachmentAction
{
Name = "game",
Text = "chess",
Type = "button",
Value = "Chess"
});
actions.Add(new SlackAttachmentAction
{
Name = "game",
Text = "Falken's Maze",
Type = "button",
Value = "Maze"
});
actions.Add( new SlackAttachmentAction
{
Name = "game",
Text = "Thermonuclear War",
Type = "danger",
Value = "war"
});
attachments.Add(new SlackAttachment
{
Text = "Choose a game to play",
Fallback = "You are unable to choose a game",
CallbackId = "wopr_game",
ColorHex = "#3AA3E3",
Actions = actions
});
connection.Say(new BotMessage
{
ChatHub = chatHub,
Text = "Usage: !talk <user>",
Attachments = attachments
});
return Task.CompletedTask;
我试过的一件事是我将请求 URL 设置为使用从 https://webhook.site/#/ 生成的 url 并且在单击
时我仍然得到相同的响应在我看来你有两个问题。
您没有 Slack 应用程序
交互式消息仅在您注册了 Slack 应用程序时才有效。这就是您收到该错误消息的原因。但是您可以轻松创建一个。只需转到 here 并单击 "Create a new app"。您需要一个的原因之一是您需要在用户单击按钮后告诉 Slack 向哪个 URL 发送请求。
Slack 无法访问您的本地应用程序
Slack 的交互式消息仅适用于可从 public Internet 访问的应用程序。因此,如果您想在本地开发您的应用程序,您需要向互联网开放您的 Web 服务器。有很多方法可以做到这一点,一种安全的方法是使用 VPN 隧道服务。此类服务的提供者之一是 ngrok,官方 Slack 教程中也推荐了它。我自己用过,效果很好。