繁体   English   中英

第三方服务整合

[英]Third party service integration

我正在处理应用程序中来自电子邮件功能的回复,并且正在使用mandrillapp.com。 现在如何运作:

1. User replies from their email to something@something.com
2. Mandril receives the mail and sends the POST request to preconfigured endpoint of my service
3. I process that post request (create internal app message)

关于步骤3,我基本上有一些代码,应该创建包装在begin/rescue中的内部应用程序消息。 因此,任何过去可能发生的错误都会报告给我。

但是,现在我遇到了一个声称已发送电子邮件的用户(步骤1),我联系了mandrill支持人员,他们说他们已经处理了该邮件并发送到我的端点(步骤2)。

这样一来,我只能查看步骤3中在特定时间范围内发生的情况。 我的应用程序在heroku上,我的日志存储在AWS上,我可以追溯到该特定时间,并且可以看到来自mandrill端的成功POST请求。

我应该怎么做才能赶上这个案件? 并修复它,因为我不知道现在发生了什么。

我当时正在考虑创建一个名为Mandrill hooks的模型,该模型具有params列,该列将是序列化的哈希值,并且将保存所有从mandrill到达端点的参数。

然后,我可以检查我的帐户收到的webhook和mandrill发送的webhook的计数,希望我发现具有不同计数的1,并且由于我将在数据库中存储params数据,因此可以重现该案例。

还是有更明智的方法,因为即使对我来说这看起来也很幼稚?

我认为可能有一种更明智的方法,使您可以对所有内容进行更多控制,这听起来与我最近完成的工作极为相似,我在这里回答了类似的问题 这是否有帮助,或者您还需要其他一些具体帮助?

** 编辑:下方链接的帖子/代码

我正在将Mandrill Webhook处理作为VS中的API项目运行,这就是我如何启动并运行它:

    [HttpPost]
    public string Post()
    {
        /* Every Mandrill webhook uses the same general data format, regardless of the event type. 
         * The webhook request is a standard POST request with a single parameter (currently) - 'mandrill_events'. */

        string validJson = HttpContext.Current.Request.Form["mandrill_events"].Replace("mandrill_events=", ""); //"mandrill_events=" is not valid JSON. If you take that out you should be able to parse it. //http://stackoverflow.com/questions/24521326/deserializing-mandrillapp-webhook-response
        List<MandrillEvent> mandrillEventList = JsonConvert.DeserializeObject<List<MandrillEvent>>(validJson);

        foreach (MandrillEvent mandrillEvent in mandrillEventList)
        {
            if (mandrillEvent.msg.email != null)
            {
                DataLayer.ReportingData.EmailSave(mandrillEvent); //Saves MandrillEvent email to database and sets a messageId for datalayer
            }
        } 

        foreach (MandrillEvent mandrillEvent in mandrillEventList)
        {
            DataLayer.ReportingData.MandrillEventSave(mandrillEvent); //Saves MandrillEvent object to database
        }

        return "DONE";
    }

然后,我获取了“ mandrill_event ”的已记录(和未记录)的JSON参数,并使用json2csharp.com生成了C#属性。 我创建了一个名为“ MandrillEvent.cs”的类,并将其放入:

public class SmtpEvent
    {
        public int ts { get; set; }
        public DateTime SmtpTs { get; set; }
        public string type { get; set; }
        public string diag { get; set; }
        public string source_ip { get; set; }
        public string destination_ip { get; set; }
        public int size { get; set; }
        public int smtpId { get; set; } //added for datalayer
    }

    public class Msg
    {
        public int ts { get; set; }
        public DateTime MsgTs { get; set; }
        public string _id { get; set; }
        public string state { get; set; }
        public string subject { get; set; }
        public string email { get; set; }
        public List<object> tags { get; set; }
        public List<object> opens { get; set; } //an array of containing an item for each time the message was opened. Each open includes the following keys: "ts", "ip", "location", "ua"
        public List<object> clicks { get; set; } //an array containing an item for each click recorded for the message. Each item contains the following: "ts", "url"
        public List<SmtpEvent> smtp_events { get; set; }
        public List<object> resends { get; set; } //not currently documented on http://help.mandrill.com/entries/58303976-Message-Event-Webhook-format
        public string _version { get; set; }
        public string diag { get; set; } //for bounced and soft-bounced messages, provides the specific SMTP response code and bounce description, if any, received from the remote server
        public int bgtools_code { get; set; } //Is it this? for bounced and soft-bounced messages, a short description of the bounce reason such as bad_mailbox or invalid_domain. (not currently documented but in JSON response)
        public string sender { get; set; }
        public object template { get; set; }
        public string bounce_description { get; set; }

        public Msg()
        {
            tags = new List<object>();
            opens = new List<object>();
            clicks = new List<object>();
            smtp_events = new List<SmtpEvent>();
            smtp_events.Add(new SmtpEvent());
            resends = new List<object>();
        }
    }

    public class MandrillEvent
    {
        public string @event { get; set; }
        public string _id { get; set; }
        public Msg msg { get; set; }
        public int ts { get; set; }
        public DateTime MandrillEventTs { get; set; }
        public int messageId { get; set; } //added for datalayer
        public List<string> SingleMandrillEventData { get; set; } //added for Reporting

        public MandrillEvent()
        {
            SingleMandrillEventData = new List<string>();
            msg = new Msg();
        }
    }

现在,您具有“ mandrill_events” JSON对象作为可运行的C#对象! 这是有帮助的还是您需要更多说明/帮助?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM