【发布时间】:2017-04-16 08:58:21
【问题描述】:
我目前正在尝试为我的软件团队创建一些非常定制的功能,并想出了一个使用 slack 事件订阅的绝佳解决方案。问题是,我在获取我所追求的事件信息时遇到问题......到目前为止,我已经设法配置 slack 来调用我的 WCF 服务,但是,包含我所追求的信息的“事件”参数总是空。
这是我目前所拥有的:
[ServiceContract]
public interface ISlackTrelloService
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "SlackPost", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
string SlackPost(string type, string token, string challenge, string team_id, SlackEvent slackEvent);
}
具体实现:
public class SlackTrelloService : ISlackTrelloService
{
public string SlackPost(string type, string token, string challenge, string team_id, SlackEvent slackEvent)
{
return challenge;
}
}
SlackEvent 类:
[JsonObject(Id = "event", Description = "event", Title = "event")]
public class SlackEvent
{
[JsonProperty(PropertyName = "type")]
public string Type { get; set; }
[JsonProperty(PropertyName = "event_ts")]
public string EventTimestamp { get; set; }
[JsonProperty(PropertyName = "user")]
public string User { get; set; }
[JsonProperty(PropertyName = "ts")]
public string Timestamp { get; set; }
[JsonProperty(PropertyName = "item")]
public string Item { get; set; }
}
现在,SlackEvent 对象是有问题的代码,因为我希望它包含 Slack 根据this 文档发送的信息。其他参数都被正确填充,而不是 slackEvent 对象:(
起初我以为是因为参数名称不完全匹配,但即使使用@event(因为 event 是 C# 中的关键字)似乎也不起作用。我不确定我是否错误地使用了 Newtonsoft JSON 库,或者我是否缺少其他东西。
编辑: 以正确格式捕获数据的新方法
string SlackPost(string token, string team_id, string api_app_id, SlackEvent slackEvent, string type, string[] authed_users, string event_id, string event_time);
SlackEvent 结构:
[JsonObject("event")]
public class Event
{
[JsonProperty(PropertyName = "type")]
public string Type { get; set; }
[JsonProperty(PropertyName = "channel")]
public string Channel { get; set; }
[JsonProperty(PropertyName = "user")]
public string User { get; set; }
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }
[JsonProperty(PropertyName = "ts")]
public string TimeStamp { get; set; }
}
【问题讨论】:
-
@spuriousGreek 你能告诉我你是如何针对请求 URL 编写操作方法来返回挑战参数的吗?我有点坚持。我正在使用 ASP.Net Core Mvc