When developing applications that use A1Base webhooks, you’ll need a way to receive webhook events on your local development machine. This guide explains how to use Ngrok to create a secure tunnel to your local server.
Ngrok is a tool that creates secure tunnels from public URLs to your local machine, allowing external services like A1Base to send webhooks to your local development environment.
First, make sure your local webhook server is running. For A1Framework or NextJS you’ll run “npm run dev”. When you do this you’ll find out what port
your app is running on (e.g. localhost:3000).
Once your local server is running, use Ngrok to create a tunnel to your local port:
Copy
Ask AI
ngrok http 3000
This will start Ngrok and display output similar to:
Copy
Ask AI
Session Status onlineAccount Your Name (Plan: Free)Version 3.3.1Region United States (us)Latency 24msWeb Interface http://127.0.0.1:4040Forwarding https://a1b2-203-0-113-42.ngrok-free.app -> http://localhost:3000
The https://a1b2-203-0-113-42.ngrok-free.app URL is your public webhook URL that you’ll configure in the A1Base dashboard.
Ngrok free tier URLs change every time you restart Ngrok. You get one free consistent URL with Ngrok. For consistent URLs, consider upgrading to a paid plan.
Purchase Two Phone Numbers: In your A1Base dashboard, purchase two separate phone numbers
Label Your Numbers: Clearly label one as “Development” and one as “Production”
Configure Different Webhooks:
Development number: Point to your Ngrok URL
Production number: Point to your production server URL
Use Environment Variables: In your code, use environment variables to determine which phone number to use:
Copy
Ask AI
// Example of using different phone numbers based on environmentconst phoneNumber = process.env.NODE_ENV === 'production' ? process.env.A1BASE_PRODUCTION_PHONE : process.env.A1BASE_DEVELOPMENT_PHONE;// Use the appropriate phone number for outgoing messagesa1base.sendMessage({ to: recipientNumber, from: phoneNumber, message: "Hello from A1Base!"});
Free Tier Restrictions: Ngrok’s free tier has limitations on connections and features
URL Changes: Free Ngrok URLs change each time you restart Ngrok
Latency: There may be slight additional latency when using Ngrok
Security: Be cautious about sensitive data passing through your development environment
By following this guide, you can effectively test A1Base webhooks in your local development environment using Ngrok, ensuring a smooth transition to production.