Levers uses Svix to securely deliver webhooks. Every webhook request includes cryptographic signatures that you can verify to ensure the request originated from Levers and wasn’t tampered with.
import { Webhook } from "svix";const secret = "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw";// These are sent from Levers in the request headers and bodyconst headers = { "svix-id": "msg_p5jXN8AQM9LWM0D4loKWxJek", "svix-timestamp": "1614265330", "svix-signature": "v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=",};const payload = '{"test": 2432232314}';const wh = new Webhook(secret);// Throws on error, returns the verified content on successconst event = wh.verify(payload, headers);
Rails.application.routes.draw do post "/webhook", to: "webhook#index"end
Create the controller app/controllers/webhook_controller.rb:
Copy
require 'svix'class WebhookController < ApplicationController protect_from_forgery with: :null_session # Disable CSRF for API endpoints def index begin payload = request.body.read headers = request.headers wh = Svix::Webhook.new("whsec_YOUR_WEBHOOK_SECRET_HERE") event = wh.verify(payload, headers) # Process the verified event event_type = event['type'] event_data = event['data'] if event_type == 'phone_call.ended' puts "Call ended: #{event_data['providerCallId']}" # Your business logic here end head :no_content rescue head :bad_request end endend
To test webhooks during development, use a tool like ngrok or localtunnel to expose your local server to the internet:
Copy
# Install ngrokbrew install ngrok # macOS# or visit: https://ngrok.com/download# Start your local serverpython app.py # Your webhook server# In another terminal, expose itngrok http 3000
Then use the ngrok URL (e.g., https://abc123.ngrok.io/webhook) in your webhook configuration.
Contact our support team if you encounter issues with webhook verification.