v5.15.0
This release of the Nylas Ruby SDK includes the release of local webhook development support built directly into the SDK. When implementing this feature in your app, the SDK will create a tunnel connection to a websocket server and registers it as a webhook callback to your Nylas account. See below for a usage example.
Release Notes
Added
- Add local webhook testing support (#399)
- Add
tzinfo
,faye-websocket
,eventmachine
as runtime dependencies (#401)
Usage
Webhook Tunnel
During the setup process you can pass in methods to override the websocket client's callback methods. The most important method is the on_message
method which returns a parsed delta event from the webhook server.
nylas = Nylas::API.new(
app_id: CLIENT_ID,
app_secret: CLIENT_SECRET
)
# Define the callback for the on_message event
def on_message(delta)
if delta.type == Nylas::WebhookTrigger::MESSAGE_UPDATED
p [:delta, delta]
end
end
# Config that sets the region, triggers, and callbacks
config = {
"region": "us",
"triggers": [WebhookTrigger::MESSAGE_UPDATED],
"on_message": method(:on_message)
}
# Create, register, and open the webhook tunnel for testing
Nylas::Tunnel::open_webhook_tunnel(nylas, config)