Skip to content

🔗 Webhook Server

OS-based webhook server for process automation and integration

🎯 Overview

The Webhook Server is an OS-based webhook service deployed on the DevOps server that enables external systems to trigger custom bash scripts and processes. It provides a flexible, lightweight solution for process automation and system integration.

🏗️ Architecture

Core Components

  • Webhook Endpoints: HTTP endpoints for triggering processes
  • Script Manager: Manages bash script execution
  • Process Controller: Handles process lifecycle and monitoring
  • Security Layer: Input validation and access control

Technology Stack

  • OS: Linux-based server environment
  • Web Server: HTTP server for webhook endpoints
  • Bash Scripts: Custom process automation scripts
  • File System: EFS-based script storage and execution

Infrastructure

  • Server: ovh-devops (DevOps server)
  • Port: 1111 (HTTP)
  • Environment: Production, Staging, Development
  • Storage: /var/efs/webhook/ (EFS mounted storage)

🔧 Configuration

Server Details

  • Server: ovh-devops
  • Port: 1111 (HTTP)
  • Base URL: http://devops.apgpain.io:1111/hooks/
  • Storage Path: /var/efs/webhook/

Directory Structure

/var/efs/webhook/
├── scripts/          # Bash script files
├── hooks/           # Hook configuration files
├── logs/            # Execution logs
└── config/          # Server configuration

Script Management

# Script Location
/var/efs/webhook/scripts/

# Permission Requirements
chmod 777 /var/efs/webhook/scripts/newscript.sh

# Hook Configuration
/var/efs/webhook/hooks/hookname.json

📋 Usage

Adding New Processes

Step 1: Create Bash Script

# Create new script
vim /var/efs/webhook/scripts/delicatetravel-chatbot.sh

# Set permissions
chmod 777 /var/efs/webhook/scripts/delicatetravel-chatbot.sh

Step 2: Configure Hook

{
    "id": "hook ID , any ID",
    "execute-command": "/var/efs/webhook/scripts/new script.sh",
    "command-working-directory": "/var/efs/webhook",
    "include-command-output-in-response": true,
    "pass-arguments-to-command": [
      {
        "source": "payload",
        "name": "param1"
      },
      {
        "source": "payload",
        "name": "param2"
      },
      {
        "source": "payload",
        "name": "param3"
      },
      {
        "source": "payload",
        "name": "param4"
      }
    ]
  },

Step 3: Test Endpoint

# Test webhook endpoint
curl -X POST "http://devops.appgain.io:1111/hooks/newscript" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Hello World",
    "mobile_num": "+1234567890"
  }'

Webhook Format

# Endpoint Format
http://devops.appgain.io:1111/hooks/{script-name}

# Request Format
POST /hooks/{script-name}
Content-Type: application/json

{
  "parameter1": "value1",
  "parameter2": "value2"
}

🔒 Security

Access Control

  • IP Whitelisting: Configure allowed IP addresses
  • Authentication: Basic auth for sensitive endpoints
  • Input Validation: Sanitize all input parameters
  • Script Isolation: Execute scripts in isolated environment

Best Practices

  • Script Permissions: Always use chmod 777 for new scripts
  • Parameter Validation: Validate all input parameters
  • Error Handling: Implement proper error handling in scripts
  • Logging: Log all executions and errors

📊 Performance

Capabilities

  • Concurrent Requests: 100+ simultaneous webhook calls
  • Response Time: < 5 seconds average
  • Uptime: 99.9% service availability
  • Script Execution: Isolated process execution

Limitations

  • Script Timeout: 30 seconds maximum execution time
  • File Size: 10MB maximum script size
  • Parameters: 10 maximum input parameters
  • Memory: 512MB maximum memory usage

🔗 Integration Examples

WhatsApp Integration

# WhatsApp webhook endpoint
http://devops.apgpain.io:1111/hooks/whatsapp-processor

# Request format
{
  "message": "Customer message",
  "mobile_num": "+201234567890",
  "channel": "whatsapp"
}

Chatbot Integration

# Chatbot webhook endpoint
http://devops.apgpain.io:1111/hooks/delicatetravel-chatbot

# Request format
{
  "message": "User query",
  "mobile_num": "+1234567890",
  "context": "conversation_context"
}

CRM Integration

# CRM webhook endpoint
http://devops.apgpain.io:1111/hooks/crm-sync

# Request format
{
  "customer_id": "12345",
  "action": "update",
  "data": {
    "name": "John Doe",
    "email": "john@example.com"
  }
}

🛠️ Troubleshooting

Common Issues

Script Permission Errors

# Fix script permissions
chmod 777 /var/efs/webhook/scripts/scriptname.sh

# Check script exists
ls -la /var/efs/webhook/scripts/scriptname.sh

Parameter Validation Errors

# Check required parameters
{
  "error": "Both 'message' and 'mobile_num' are required in UOWHATSAPP"
}

# Fix: Include all required parameters
{
  "message": "Your message here",
  "mobile_num": "+1234567890"
}

Timeout Errors

# Check script execution time
# Scripts must complete within 30 seconds
# Optimize long-running scripts

Debug Commands

# Check server status
systemctl status webhook-server

# View logs
tail -f /var/efs/webhook/logs/access.log

# Test script manually
bash /var/efs/webhook/scripts/scriptname.sh "param1" "param2"

📚 Documentation

External Resources

Monitoring Tools

  • Server Monitoring: Prometheus + Grafana
  • Log Analysis: ELK Stack integration
  • Health Checks: Automated endpoint monitoring
  • Performance Metrics: Response time and throughput tracking

Development Tools

  • Git Repository: Source code and version control
  • Postman Collection: API testing and documentation
  • Development Environment: Docker setup for local testing
  • Testing Framework: Automated webhook testing
Ask Chehab GPT