Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 松弛事件订阅_C#_Wcf_Slack Api_Slack - Fatal编程技术网

C# 松弛事件订阅

C# 松弛事件订阅,c#,wcf,slack-api,slack,C#,Wcf,Slack Api,Slack,我目前正试图为我的软件团队创建一些非常定制的功能,并想到了一个使用slack事件订阅的伟大解决方案。问题是,我在获取我所关注的事件信息时遇到问题…到目前为止,我已成功配置slack以调用我的WCF服务,但是,包含我所关注的信息的“event”参数始终为空 以下是我到目前为止的情况: [ServiceContract] public interface ISlackTrelloService { [OperationContract] [WebInvoke(Method = "PO

我目前正试图为我的软件团队创建一些非常定制的功能,并想到了一个使用slack事件订阅的伟大解决方案。问题是,我在获取我所关注的事件信息时遇到问题…到目前为止,我已成功配置slack以调用我的WCF服务,但是,包含我所关注的信息的“event”参数始终为空

以下是我到目前为止的情况:

[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;
    }
}
松弛类:

[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根据文档发送的信息。其他参数都正确填充,但不是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);
松弛结构:

[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; }
}
By C#有点生疏,但据我所知,您的
SlackTrelloService
类实现似乎不完整

Slack发送两种不同的事件请求:验证握手和实际事件。您的类的目标是在一个类中覆盖这两种类型,我认为这与当前实现的方式不一样

验证握手仅在事件订阅期间使用一次,不包含任何事件信息

您的应用程序需要正确响应验证握手才能成功订阅事件

稍后发送的实际事件如下所示:(同样来自官方文档)

正如您所看到的,它没有
challenge
属性,而是许多其他属性

您还可以只返回类中的
挑战
,而不返回实际的事件信息

因此,以下是我的建议:

  • 确保您已成功订阅Slack应用程序中的事件。如果不是,您当前获得的只是验证握手,但不包括该事件

  • 分别实现以处理验证握手和事件请求


  • 我的类是非常不完整的,我认为(我需要另一个方法来接受方法信息)…但是,我找不到有关如何实际触发事件请求的任何信息,即如何告诉Slack调用单独的方法?现在正在调用的方法正在工作,因为Slack中有一个配置选项,允许我为验证指定特定的URL。好的,酷。我想我们走对了。Slack将两种请求类型发送到同一url,即您在配置窗口中指定的url。验证握手完成后,您将收到事件请求(您将在配置窗口中看到)您订阅的事件发生了。我建议您先订阅,然后在频道中设置某个位置来触发它。我编辑了原始帖子,以反映我为捕获正在触发的事件数据所做的更改。我现在正确地接收到所有数据,但事件信息除外(我真正想要的是!)。我正在使用Newtonsoft JSON库尝试捕获事件对象,但可能我误解了一些事情,因为slackEvent总是空的。可能是我必须映射到确切的“事件”,但由于它是一个关键字,我尝试设置我创建的数据结构的id,即[JsonObject](“event”)]@spusiouseGreek您能告诉我您是如何针对请求Url编写操作方法以返回质询参数的吗?我有点被卡住了。我正在使用ASP.Net Core Mvc
    {
        "token": "Jhj5dZrVaK7ZwHHjRyZWjbDl",
        "challenge": "3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P",
        "type": "url_verification"
    }
    
     {
            "token": "z26uFbvR1xHJEdHE1OQiO6t8",
            "team_id": "T061EG9RZ",
            "api_app_id": "A0FFV41KK",
            "event": {
                    "type": "reaction_added",
                    "user": "U061F1EUR",
                    "item": {
                            "type": "message",
                            "channel": "C061EG9SL",
                            "ts": "1464196127.000002"
                    },
                    "reaction": "slightly_smiling_face"
            },
            "event_ts": "1465244570.336841",
            "type": "event_callback",
            "authed_users": [
                    "U061F7AUR"
            ]
    }