【问题标题】:SendGrid spec differences between versions of Event Notification Webhook事件通知 Webhook 版本之间的 SendGrid 规范差异
【发布时间】:2014-03-22 19:45:25
【问题描述】:

我有一个现有的带有基于 SMTP 中继的 SendGrid 服务 集成的 rails3 应用程序,并订阅了 Event Notification Webhooks

我收到来自 Service 的提醒电子邮件,通知 SendGrid 的服务即将发生更改,我需要进行一些更改以匹配新版本的 Event Notification Webhooks v3。

我收到的电子邮件包含有关如何升级的说明:

  • 查看文档以了解如何使用此新版本的事件。
  • 实施更改以处理事件数据的新格式。
  • 在 SendGrid 的配置页面上进行更改

亲爱的,我现在需要在我的网站上实施哪些更改?我阅读了 v3 的手册,但没有关于新旧版本之间规格差异的信息。

【问题讨论】:

    标签: ruby-on-rails sendgrid


    【解决方案1】:

    之前,SendGrid 事件 webhook 发送了不正确的批处理 JSON,文档由换行符分隔:

    { "email": "john.doe@sendgrid.com", "timestamp": 1337197600, "smtp-id": "<4FB4041F.6080505@sendgrid.com>", "event": "processed" }
    { "email": "john.doe@sendgrid.com", "timestamp": 1337966815, "category": "newuser", "event": "click", "url": "http://sendgrid.com" }
    { "email": "john.doe@sendgrid.com", "timestamp": 1337969592, "smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>", "event": "processed" }
    

    今天,它使用v3 发送正确的 JSON:

    [
      {
        "email": "john.doe@sendgrid.com",
        "timestamp": 1337197600,
        "smtp-id": "<4FB4041F.6080505@sendgrid.com>",
        "event": "processed"
      },
      {
        "email": "john.doe@sendgrid.com",
        "timestamp": 1337966815,
        "category": "newuser",
        "event": "click",
        "url": "http://sendgrid.com"
      },
      {
        "email": "john.doe@sendgrid.com",
        "timestamp": 1337969592,
        "smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>",
        "event": "processed"
      }
    ]
    

    如果您之前一直在处理非批处理事件,则需要调整您的代码,以便它解释一个数组,而不仅仅是一个文档,然后循环遍历该数组。放入代码:

    # This
    consume_data(params)
    
    # Becomes this
    params.each { |doc|
      consume_data(doc)
    }
    

    【讨论】:

      猜你喜欢
      • 2015-12-13
      • 1970-01-01
      • 2017-12-31
      • 1970-01-01
      • 2012-12-07
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      相关资源
      最近更新 更多