A simple ASP.NET Core webhook server that processes CloudContactAI webhook events with enhanced parsing and logging.
- CloudContactAI Event Processing: Automatically parses and displays all 5 CloudContactAI event types
- Enhanced Logging: Color-coded console output with emojis for easy identification
- Event Type Support:
message.sent- Message delivery confirmationsmessage.incoming- Incoming replies from recipientsmessage.excluded- Messages excluded from campaignsmessage.error.carrier- Carrier-level delivery failuresmessage.error.cloudcontact- CloudContactAI system errors
- Backward Compatibility: Still handles legacy webhook formats
- CORS Enabled: Works with ngrok and external services
-
Build the server:
git clone https://github.com/CloudContactAI/CCAI.NET.git cd CCAI.NET/examples/webhook-server dotnet add package CloudContactAI.CCAI.NET dotnet add package DotNetEnv dotnet build -
Configure the server:
Create a
.envfile in your project root:CCAI_CLIENT_ID=1231 CCAI_API_KEY=your-api-key-here
-
Start the Server
dotnet run
-
Server runs on:
http://localhost:3000 -
Test with sample events:
./test_webhook.sh
-
Install ngrok: https://ngrok.com/download
-
Start the webhook server:
dotnet run
-
In another terminal, start ngrok:
ngrok http 3000
-
Configure CloudContact:
- Copy the ngrok HTTPS URL (e.g.,
https://abc123.ngrok.io) - In CloudContactAI Settings\Webhooks, set webhook URL to:
https://abc123.ngrok.io/webhook
- Copy the ngrok HTTPS URL (e.g.,
-
Send a message with CloudContactAI:
- Send a message with the sms-sender project here
- Send a message through the CloudContactAI UI
When a webhook is received, you'll see output like:
🔔 Received webhook event at /webhook path!
⏰ Time: 2025-09-02 17:52:33 UTC
📋 Headers:
Content-Type: application/json
User-Agent: CloudContact-Webhook/1.0
📄 Raw Body:
{"eventType":"message.sent","data":{"SmsSid":12345,"MessageStatus":"DELIVERED"...}}
🎯 Parsed CloudContactAI Event:
Event Type: message.sent
Message Status: DELIVERED
To: +1234567890
Message: Hello! Your order #12345 has been shipped.
✅ Message delivered successfully!
💰 Cost: $0.0200
📊 Segments: 2
📢 Campaign: Order Notifications (ID: 67890)
📝 Custom Data: order_id:12345,customer_type:premium
🆔 External ID: customer_abc123
─────────────────────────────────────────────────────
- Confirms successful message delivery
- Shows cost, segments, and campaign info
- Includes delivery timestamps
- Processes replies from recipients
- Links back to original campaigns
- Useful for engagement tracking
- Shows why messages were filtered out
- Common reasons: duplicates, invalid numbers, opt-outs
- Helps optimize campaign targeting
- Carrier-level delivery failures
- Error codes like 30008 (invalid number)
- Helps identify bad phone numbers
- System-level errors
- Account issues (CCAI-001: insufficient balance)
- Service configuration problems
Use this server as a starting point for your webhook processing. You can:
- Add database logging
- Implement business logic for each event type
- Forward events to other systems
- Set up alerting for errors
- Track campaign performance metrics
The included test_webhook.sh script sends sample events of all types to test your webhook processing logic.