【问题标题】:Third party service integration第三方服务集成
【发布时间】:2014-10-09 06:44:30
【问题描述】:

我正在处理我的应用中的电子邮件回复功能,我正在使用 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 具有不同的计数,并且由于我的数据库中有参数数据,我将能够重现案例。

还是有更明智的方法,因为这在我看来也很幼稚?

【问题讨论】:

    标签: ruby-on-rails heroku integration mandrill


    【解决方案1】:

    我认为可能有一种更明智的方法可以让您更好地控制一切,这听起来与我最近完成的和I answered a similar question here 非常相似。这是否有帮助,还是您想要一些更具体的帮助?

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

    我在 VS 中将 Mandrill Webhook 处理作为 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# 对象!这是帮助还是您需要更多说明/帮助?

    【讨论】:

    • 嗨 Hopper,目前这个答案是一个濒临灭绝的物种,因为“仅链接答案”你可能会考虑让它能够独立存在,另外保留链接就可以了。跨度>
    猜你喜欢
    • 2019-01-02
    • 2018-06-12
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多