针对requests.status_changed未触发的Uber API Webhooks,request.receipt_ready的webhooks为

时间:2017-07-20 00:48:00

标签: webhooks uber-api

我有一个用Ruby on Rails编写的测试应用程序,可以看到ngrok IP。我创建了一个沙盒控制器,只需单击一下按钮即可更改沙箱行程的状态。

直到今天(在一个演示过程中,它已经提前25分钟工作),它发布了webhook事件给我的ngrok IP,用于每个状态更改,类型为requests.status_changed。目前,如果我将处理过程更改为“接受”,“到达”或“in_progress”,我会从沙箱中获得相应的响应,但不会创建任何webhook。如果我将行程更改为“driver_canceled”或“completed”,我会收到requests.receipt_ready webhook事件。

我很乐意展示代码,如果这会有所帮助(编辑:我在下面显示代码),但是因为a)我在状态更改时从沙盒中得到正确的答案(尽管没有webhook) post),和b)我收到了收据通知的webhook帖子,我认为:

  • 我正在正确地与沙箱交谈
  • 我没有网络或防火墙问题阻止webhook到达我的服务器

我依赖于status_changed webhooks给我通知我需要采取额外的行动。是否有任何事情继续发生或是否有一些我应该关注的事情来确定那些失败的原因?

<小时/> 更新:

我在Rails中这样做。我使用一个名为UberConnection的类来连接,它基本上是HTTParty:

class UberConnection
  include HTTParty
  base_uri 'https://sandbox-api.uber.com/v1.2'
  headers "Accept-Language" => "en_US", "Content-Type" => 
  "application/json"
  debug_output $stdout
end 

我使用ngrok获取webhook的公开可见名称。我将webhook配置为侦听event_type =“requests.status_changed”的事件。它们创建UberEvent ActiveRecord对象并检查重复项或筛选与ACTIVE_EVENTS列表不匹配的事件:

ACTIVE_EVENTS = ["requests.status_changed"]

if (!UberEvent.where(event_id: params["event_id"]).blank? || !ACTIVE_EVENTS.include?(params["event_type"]))
  Rails.logger.debug("Ignoring duplicate or filtered notice")
  return head :ok
end

我还有一个沙箱控制器,可以改变正在进行的行驶状态,因此我可以模拟行驶生命周期:

def ops_accepted
  UberConnection.put("/sandbox/requests/#{params[:ride_id]}",
    headers: {"Authorization" => "Bearer #{Uber.token}"},
    body: {status: "accepted"}.to_json)
    flash[:notice] = "Changed ride to Accepted"
    redirect_to action: :operator
end

和其他生命周期类型类似。

预期行为 一旦我计划骑行并且它处于处理状态,我应该能够点击触发ops_accepted的按钮并将骑行改为接受。这应该导致webhook事件触发,指示状态已更改,我可以根据该事件采取其他操作。

实际行为 除了webhook事件之外的所有事情都会发生。

提交新搭车

Started GET "/sandbox" for 2600:1005:b06a:1a83:9818:4356:ceda:ca11 at 2017-07-26 08:35:46 -0400
Cannot render console from 2600:1005:b06a:1a83:9818:4356:ceda:ca11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by WebhooksController#operator as HTML
  Uber Load (0.1ms)  SELECT  "ubers".* FROM "ubers" ORDER BY "ubers"."id" ASC LIMIT ?  [["LIMIT", 1]]
opening connection to sandbox-api.uber.com:443...
opened
starting SSL for sandbox-api.uber.com:443...
SSL established
<- "GET /v1.2/requests/current HTTP/1.1\r\nAccept-Language: en_US\r\nContent-Type: application/json\r\nAuthorization: Bearer [TOKEN REDACTED]\r\nConnection: close\r\nHost: sandbox-api.uber.com\r\n\r\n"
-> "HTTP/1.1 200 OK\r\n"
-> "Server: nginx\r\n"
-> "Date: Wed, 26 Jul 2017 12:35:45 GMT\r\n"
-> "Content-Type: application/json\r\n"
-> "Content-Length: 431\r\n"
-> "Connection: close\r\n"
-> "Content-Geo-System: wgs-84\r\n"
-> "Content-Language: en\r\n"
-> "Etag: W/\"e9fda87d668bbe0f46ec27d8557b110b03c8c422\"\r\n"
-> "X-Uber-App: uberex-sandbox\r\n"
-> "X-Uber-App: optimus\r\n"
-> "Strict-Transport-Security: max-age=604800\r\n"
-> "X-Content-Type-Options: nosniff\r\n"
-> "X-XSS-Protection: 1; mode=block\r\n"
-> "Strict-Transport-Security: max-age=2592000\r\n"
-> "X-Frame-Options: SAMEORIGIN\r\n"
-> "Cache-Control: max-age=0\r\n"
-> "\r\n"
reading 431 bytes...
-> "{\"status\":\"processing\",\"product_id\":\"6d898741-0175-4c71-ad5f-93fc66270d6a\",\"destination\":{\"latitude\":33.754177,\"longitude\":-84.371736},\"driver\":null,\"pickup\":{\"latitude\":33.7539854,\"region\":{\"latitude\":33.7489,\"country_name\":\"United States\",\"country_code\":\"US\",\"name\":\"Atlanta\",\"longitude\":-84.3881},\"eta\":6,\"longitude\":-84.3755874},\"request_id\":\"f14877e5-f060-4c4a-be91-bb66866238b9\",\"location\":null,\"vehicle\":null,\"shared\":false}"
read 431 bytes
Conn close
  Rendering webhooks/operator.html.erb within layouts/application
  Rendered webhooks/operator.html.erb within layouts/application (1.6ms)
Completed 200 OK in 795ms (Views: 27.9ms | ActiveRecord: 0.1ms)

更改为已接受

Started PUT "/webhooks/accept/f14877e5-f060-4c4a-be91-bb66866238b9" for 2600:1005:b06a:1a83:9818:4356:ceda:ca11 at 2017-07-26 08:48:22 -0400
Cannot render console from 2600:1005:b06a:1a83:9818:4356:ceda:ca11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by WebhooksController#ops_accepted as HTML
  Parameters: {"authenticity_token"=>"PIHCTPkaOpa8RrsvT4D+TF0PR1UvY8uukh9SC2MRw1o5StFZYo0PNtn1g0W6QQh/2f7/hQSDSVVy8CMLJv/GYg==", "ride_id"=>"f14877e5-f060-4c4a-be91-bb66866238b9"}
  Uber Load (0.2ms)  SELECT  "ubers".* FROM "ubers" ORDER BY "ubers"."id" ASC LIMIT ?  [["LIMIT", 1]]
opening connection to sandbox-api.uber.com:443...
opened
starting SSL for sandbox-api.uber.com:443...
SSL established
<- "PUT /v1.2/sandbox/requests/f14877e5-f060-4c4a-be91-bb66866238b9 HTTP/1.1\r\nAccept-Language: en_US\r\nContent-Type: application/json\r\nAuthorization: Bearer [TOKEN REDACTED]\r\nConnection: close\r\nHost: sandbox-api.uber.com\r\nContent-Length: 21\r\n\r\n"
<- "{\"status\":\"accepted\"}"
-> "HTTP/1.1 204 No Content\r\n"
-> "Server: nginx\r\n"
-> "Date: Wed, 26 Jul 2017 12:48:23 GMT\r\n"
-> "Content-Type: text/html; charset=UTF-8\r\n"
-> "Connection: close\r\n"
-> "Content-Language: en\r\n"
-> "X-Uber-App: uberex-sandbox\r\n"
-> "X-Uber-App: optimus\r\n"
-> "Strict-Transport-Security: max-age=604800\r\n"
-> "X-Content-Type-Options: nosniff\r\n"
-> "X-XSS-Protection: 1; mode=block\r\n"
-> "Strict-Transport-Security: max-age=2592000\r\n"
-> "X-Frame-Options: SAMEORIGIN\r\n"
-> "Cache-Control: max-age=0\r\n"
-> "\r\n"
Conn close
Redirected to http://edgexpress.ngrok.io/sandbox
Completed 302 Found in 1010ms (ActiveRecord: 0.2ms)


Started GET "/sandbox" for 2600:1005:b06a:1a83:9818:4356:ceda:ca11 at 2017-07-26 08:48:23 -0400
Cannot render console from 2600:1005:b06a:1a83:9818:4356:ceda:ca11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by WebhooksController#operator as HTML
  Uber Load (0.1ms)  SELECT  "ubers".* FROM "ubers" ORDER BY "ubers"."id" ASC LIMIT ?  [["LIMIT", 1]]
opening connection to sandbox-api.uber.com:443...
opened
starting SSL for sandbox-api.uber.com:443...
SSL established
<- "GET /v1.2/requests/current HTTP/1.1\r\nAccept-Language: en_US\r\nContent-Type: application/json\r\nAuthorization: Bearer [TOKEN REDACTED]\r\nConnection: close\r\nHost: sandbox-api.uber.com\r\n\r\n"
-> "HTTP/1.1 200 OK\r\n"
-> "Server: nginx\r\n"
-> "Date: Wed, 26 Jul 2017 12:48:24 GMT\r\n"
-> "Content-Type: application/json\r\n"
-> "Content-Length: 804\r\n"
-> "Connection: close\r\n"
-> "Content-Geo-System: wgs-84\r\n"
-> "Content-Language: en\r\n"
-> "Etag: W/\"c1f9c6d51c7094d1e7789222a522aa1d3f304068\"\r\n"
-> "X-Uber-App: uberex-sandbox\r\n"
-> "X-Uber-App: optimus\r\n"
-> "Strict-Transport-Security: max-age=604800\r\n"
-> "X-Content-Type-Options: nosniff\r\n"
-> "X-XSS-Protection: 1; mode=block\r\n"
-> "Strict-Transport-Security: max-age=2592000\r\n"
-> "X-Frame-Options: SAMEORIGIN\r\n"
-> "Cache-Control: max-age=0\r\n"
-> "\r\n"
reading 804 bytes...
-> "{\"status\":\"accepted\",\"product_id\":\"6d898741-0175-4c71-ad5f-93fc66270d6a\",\"destination\":{\"latitude\":33.754177,\"eta\":2,\"longitude\":-84.371736},\"driver\":{\"phone_number\":\"(555)555-5555\",\"rating\":4.9,\"picture_url\":\"https:\\/\\/d1a3f4spazzrp4.cloudfront.net\\/uberex-sandbox\\/images\\/driver.jpg\",\"name\":\"John\",\"sms_number\":null},\"pickup\":{\"latitude\":33.7539854,\"region\":{\"latitude\":33.7489,\"country_name\":\"United States\",\"country_code\":\"US\",\"name\":\"Atlanta\",\"longitude\":-84.3881},\"eta\":1,\"longitude\":-84.3755874},\"request_id\":\"f14877e5-f060-4c4a-be91-bb66866238b9\",\"location\":{\"latitude\":33.7559,\"bearing\":-178,\"longitude\":-84.37212},\"vehicle\":{\"make\":\"Toyota\",\"picture_url\":\"https:\\/\\/d1a3f4spazzrp4.cloudfront.net\\/uberex-sandbox\\/images\\/prius.jpg\",\"model\":\"Prius\",\"license_plate\":\"UBER-PLATE\"},\"shared\":false}"
read 804 bytes
Conn close
  Rendering webhooks/operator.html.erb within layouts/application
  Rendered webhooks/operator.html.erb within layouts/application (1.8ms)
Completed 200 OK in 965ms (Views: 28.0ms | ActiveRecord: 0.1ms)

正如您所看到的,没有启动webhook。现在,让我们取消驾驶员取消。

驱动程序取消

Started PUT "/webhooks/cancel/f14877e5-f060-4c4a-be91-bb66866238b9" for 2600:1005:b06a:1a83:9818:4356:ceda:ca11 at 2017-07-26 08:51:08 -0400
Cannot render console from 2600:1005:b06a:1a83:9818:4356:ceda:ca11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by WebhooksController#ops_cancelled as HTML
  Parameters: {"authenticity_token"=>"[REDACTED]", "ride_id"=>"f14877e5-f060-4c4a-be91-bb66866238b9"}
  Uber Load (0.1ms)  SELECT  "ubers".* FROM "ubers" ORDER BY "ubers"."id" ASC LIMIT ?  [["LIMIT", 1]]
opening connection to sandbox-api.uber.com:443...
opened
starting SSL for sandbox-api.uber.com:443...
SSL established
<- "PUT /v1.2/sandbox/requests/f14877e5-f060-4c4a-be91-bb66866238b9 HTTP/1.1\r\nAccept-Language: en_US\r\nContent-Type: application/json\r\nAuthorization: Bearer [REDACTED]\r\nConnection: close\r\nHost: sandbox-api.uber.com\r\nContent-Length: 28\r\n\r\n"
<- "{\"status\":\"driver_canceled\"}"
-> "HTTP/1.1 204 No Content\r\n"
-> "Server: nginx\r\n"
-> "Date: Wed, 26 Jul 2017 12:51:08 GMT\r\n"
-> "Content-Type: text/html; charset=UTF-8\r\n"
-> "Connection: close\r\n"
-> "Content-Language: en\r\n"
-> "X-Uber-App: uberex-sandbox\r\n"
-> "X-Uber-App: optimus\r\n"
-> "Strict-Transport-Security: max-age=604800\r\n"
-> "X-Content-Type-Options: nosniff\r\n"
-> "X-XSS-Protection: 1; mode=block\r\n"
-> "Strict-Transport-Security: max-age=2592000\r\n"
-> "X-Frame-Options: SAMEORIGIN\r\n"
-> "Cache-Control: max-age=0\r\n"
-> "\r\n"
Conn close
Redirected to http://edgexpress.ngrok.io/sandbox
Completed 302 Found in 582ms (ActiveRecord: 0.1ms)

Started POST "/webhooks/event" for 104.36.193.85 at 2017-07-26 08:51:10 -0400
Cannot render console from 104.36.193.85! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by WebhooksController#event as */*
  Parameters: {"event_id"=>"6b8e9684-c1c9-448b-92ef-54f9bbde53d0", "resource_href"=>"https://sandbox-api.uber.com/v1/requests/f14877e5-f060-4c4a-be91-bb66866238b9/receipt", "meta"=>{"status"=>"ready", "rider_id"=>"8Gb4HQ4kVZIq-Z6nR_kKYGBO_tjV1JqyU2VRJJdICrKLJDFVSv34MqsGfKZI0JO6d7-ELIws7Ia_YhwCmbvVHXRzwdIzEDOXs4aTrPRljXML10yOpwEKTn1sCyPlHmLT4g==", "user_id"=>"55d5e34c-1a9f-4dd8-87fe-1764678eea94", "resource_id"=>"f14877e5-f060-4c4a-be91-bb66866238b9"}, "event_type"=>"requests.receipt_ready", "event_time"=>1501073468, "webhook"=>{"event_id"=>"6b8e9684-c1c9-448b-92ef-54f9bbde53d0", "resource_href"=>"https://sandbox-api.uber.com/v1/requests/f14877e5-f060-4c4a-be91-bb66866238b9/receipt", "meta"=>{"status"=>"ready", "rider_id"=>"8Gb4HQ4kVZIq-Z6nR_kKYGBO_tjV1JqyU2VRJJdICrKLJDFVSv34MqsGfKZI0JO6d7-ELIws7Ia_YhwCmbvVHXRzwdIzEDOXs4aTrPRljXML10yOpwEKTn1sCyPlHmLT4g==", "user_id"=>"55d5e34c-1a9f-4dd8-87fe-1764678eea94", "resource_id"=>"f14877e5-f060-4c4a-be91-bb66866238b9"}, "event_type"=>"requests.receipt_ready", "event_time"=>1501073468}}
Comparing 6b8e9684-c1c9-448b-92ef-54f9bbde53d0 to what's in db. . .
  UberEvent Load (3.4ms)  SELECT "uber_events".* FROM "uber_events" WHERE "uber_events"."event_id" = ?  [["event_id", "6b8e9684-c1c9-448b-92ef-54f9bbde53d0"]]
Ignoring duplicate or filtered notice
Completed 200 OK in 7ms (ActiveRecord: 3.6ms)

正如您所看到的,webhook发布了收据信息,这意味着它不是我和webhooks海报之间的障碍,也不是错误配置。 webhook根本不是为我开火。

我错过了什么?

1 个答案:

答案 0 :(得分:0)

当沙盒中的旅行状态发生变化时,我们目前没有看到webhook问题。我已经使用我的测试应用程序进行了测试,并且我收到了所有状态更改的webhooks,其中webhook假设被解雇。请检查下面的屏幕打印: enter image description here