提问人:Klinger 提问时间:11/3/2023 最后编辑:Brian Tompsett - 汤莱恩Klinger 更新时间:11/3/2023 访问量:22
Slack API:检索有关 slack 命令的信息
Slack API: Retrieve information about slack command
问:
我无法在我的 .NET Core 项目中获取有关松弛命令的信息。我在松弛网站上将命令注册为 /joinbot,并且有一个网站看起来像这样,我将其作为 URL 输入:https://somewebsites.azurewebsites.net/Slack/joinbot
API 控制器中的代码如下所示:
namespace SlackAPI.Controllers {
[ApiController]
public class SlackController : ControllerBase {
private readonly ISlackRequestHandler _requestHandler;
private readonly SlackEndpointConfiguration _endpointConfig;
private readonly ISlackApiClient _slack;
private readonly ILogger<SlackController> _logger;
private readonly IConfiguration _configuration;
public SlackController(ISlackRequestHandler requestHandler, SlackEndpointConfiguration endpointConfig, ISlackApiClient slack, ILogger<SlackController> loggerIConfiguration configuration) {
_requestHandler = requestHandler;
_endpointConfig = endpointConfig;
_slack = slack;
_logger = logger;
_configuration = configuration;
}
[HttpPost]
[Route("[Controller]/joinbot")]
public async Task<ActionResult> Joinbot([FromBody] SlashCommandPayloadDto payload) {
await _slack.Chat.PostMessage(new SlackNet.WebApi.Message() { Text = $"{payload.text} {payload.response_url} {payload.command} {payload.user_name}", Channel = _configuration.GetValue<string>("Slack:ChannelToSend")}, null);
return Ok();
}
}
}
public class SlashCommandPayloadDto {
public string? token { get; set; }
public string? team_id { get; set; }
public string? team_domain { get; set; }
public string? enterprise_id { get; set; }
public string? enterprise_name { get; set; }
public string? channel_id { get; set; }
public string? channel_name { get; set; }
public string? user_id { get; set; }
public string? user_name { get; set; }
public string? command { get; set; }
public string? text { get; set; }
public string? response_url { get; set; }
public string? trigger_id { get; set; }
}
API 控制器中的所有其他功能都工作正常(为了简单起见,我只是在这里删除了它们),swagger 告诉我存在该特定 URL,我可以运行它。
但是,当我将 /joinbot 发送到我的机器人时,我收到以下消息:
“/joinbot 失败,出现错误”dispatch_failed“”
有没有人看到这不起作用的明显原因?
答: 暂无答案
评论