Automation & Webhooks

Build powerful automation workflows with webhooks and message filters

Need Help with Automation Setup?

Our help center has detailed guides on webhooks, filters, and automation workflows. Get step-by-step instructions and troubleshooting tips.

Visit Help Center for Automation Guides

Webhooks Overview

Webhooks allow Infini Reach to send real-time notifications to your applications when events occur. Use webhooks to integrate Infini Reach with your own systems, trigger workflows, or log message activity.

Common Use Cases

📊 Analytics & Logging

Track message volumes and delivery rates

🔔 Notifications

Alert teams about important messages

🤖 Auto-Responders

Trigger automated responses

📝 CRM Updates

Sync messages to your CRM

Setting Up Webhooks

Step 1: Create Webhook Endpoint

First, create an endpoint in your application to receive webhook events:

// Express.js example
app.post('/webhooks/infinireach', (req, res) => {
  const event = req.body;
  
  // Verify signature (recommended)
  const signature = req.headers['x-infini-reach-signature'];
  if (!verifySignature(event, signature)) {
    return res.status(401).send('Invalid signature');
  }
  
  // Handle the event
  switch(event.event) {
    case 'message.received':
      handleInboundMessage(event.data);
      break;
    case 'message.delivered':
      handleDeliveryUpdate(event.data);
      break;
    case 'device.offline':
      alertTeam(event.data);
      break;
  }
  
  res.status(200).send('OK');
});

⚠️ Important: Your webhook endpoint should respond with a 200 status code within 5 seconds. For longer processing, acknowledge immediately and process asynchronously.

Step 2: Configure in Dashboard

Add your webhook URL in the Infini Reach dashboard:

  1. Go to Settings → Webhooks
  2. Click "Add Webhook"
  3. Enter your webhook URL (must be HTTPS)
  4. Select which events to receive
  5. Click "Save" and test the connection

Step 3: Verify Signature

Always verify webhook signatures to ensure requests are from Infini Reach:

const crypto = require('crypto');

function verifySignature(payload, signature) {
  const secret = process.env.INFINIREACH_WEBHOOK_SECRET;
  const hash = crypto
    .createHmac('sha256', secret)
    .update(JSON.stringify(payload))
    .digest('hex');
  
  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(hash)
  );
}

Webhook Events

message.received

Triggered when an inbound message is received on a device

{
  "event": "message.received",
  "timestamp": "2024-10-25T10:30:00Z",
  "data": {
    "messageId": "msg_xyz789",
    "deviceId": "dev_abc123",
    "from": "+1234567890",
    "to": "+0987654321",
    "message": "Hello!",
    "type": "sms"
  }
}

message.sent

Triggered when a message has been sent from the device

{
  "event": "message.sent",
  "timestamp": "2024-10-25T10:30:00Z",
  "data": {
    "messageId": "msg_xyz789",
    "deviceId": "dev_abc123",
    "to": "+1234567890",
    "status": "sent"
  }
}

message.delivered

Triggered when a message is confirmed delivered

{
  "event": "message.delivered",
  "timestamp": "2024-10-25T10:30:15Z",
  "data": {
    "messageId": "msg_xyz789",
    "deviceId": "dev_abc123",
    "status": "delivered"
  }
}

message.failed

Triggered when a message fails to send

{
  "event": "message.failed",
  "timestamp": "2024-10-25T10:30:30Z",
  "data": {
    "messageId": "msg_xyz789",
    "deviceId": "dev_abc123",
    "error": "No network connection",
    "status": "failed"
  }
}

device.online / device.offline

Triggered when a device status changes

{
  "event": "device.offline",
  "timestamp": "2024-10-25T10:30:00Z",
  "data": {
    "deviceId": "dev_abc123",
    "name": "Office SIM 1",
    "lastSeen": "2024-10-25T10:25:00Z"
  }
}

Message Filters & Routing

Use filters to route messages to different webhooks based on criteria such as sender, content, or device.

Filter Types

📱 Phone Number Filter

Route messages based on sender or recipient phone number

{
  "filter": {
    "type": "phone",
    "condition": "starts_with",
    "value": "+1555"
  },
  "action": {
    "webhook": "https://api.example.com/urgent-messages"
  }
}

💬 Keyword Filter

Trigger actions based on message content

{
  "filter": {
    "type": "keyword",
    "condition": "contains",
    "value": "urgent",
    "case_sensitive": false
  },
  "action": {
    "webhook": "https://api.example.com/urgent-webhook",
    "notify_admin": true
  }
}

📱 Device Filter

Route based on which device received/sent the message

{
  "filter": {
    "type": "device",
    "device_ids": ["dev_abc123", "dev_def456"]
  },
  "action": {
    "webhook": "https://api.example.com/sales-messages"
  }
}

⏰ Time-Based Filter

Route differently based on time of day or day of week

{
  "filter": {
    "type": "time",
    "days": ["monday", "tuesday", "wednesday"],
    "hours": { "start": "09:00", "end": "17:00" },
    "timezone": "America/New_York"
  },
  "action": {
    "webhook": "https://api.example.com/business-hours"
  }
}

Automation Examples

Example 1: Auto-Reply System

Automatically respond to incoming messages with specific keywords

// Webhook handler
app.post('/webhooks/auto-reply', async (req, res) => {
  const { event, data } = req.body;
  
  if (event === 'message.received') {
    const message = data.message.toLowerCase();
    
    if (message.includes('hours')) {
      await sendMessage({
        deviceId: data.deviceId,
        to: data.from,
        message: 'We are open Mon-Fri 9am-5pm EST'
      });
    }
    
    if (message.includes('support')) {
      await sendMessage({
        deviceId: data.deviceId,
        to: data.from,
        message: 'For support, please call 555-0100'
      });
    }
  }
  
  res.status(200).send('OK');
});

Example 2: CRM Integration

Sync all messages to your CRM automatically

// Webhook handler
app.post('/webhooks/crm-sync', async (req, res) => {
  const { event, data } = req.body;
  
  if (event === 'message.received') {
    // Create activity in CRM
    await crm.createActivity({
      contactPhone: data.from,
      type: 'inbound_sms',
      message: data.message,
      timestamp: data.timestamp
    });
    
    // Update contact last_contacted
    await crm.updateContact(data.from, {
      lastContacted: data.timestamp
    });
  }
  
  res.status(200).send('OK');
});

Example 3: Alert System

Send alerts when devices go offline

// Webhook handler
app.post('/webhooks/alerts', async (req, res) => {
  const { event, data } = req.body;
  
  if (event === 'device.offline') {
    // Send alert to team
    await sendEmail({
      to: 'team@company.com',
      subject: `Device Offline: ${data.name}`,
      body: `Device ${data.name} went offline at ${data.lastSeen}`
    });
    
    // Send SMS to admin
    await sendSMS({
      to: '+1234567890',
      message: `ALERT: Device ${data.name} is offline`
    });
  }
  
  res.status(200).send('OK');
});

Best Practices

Respond Quickly

Always respond with 200 status within 5 seconds. Process heavy tasks asynchronously.

Verify Signatures

Always verify webhook signatures to ensure requests are from Infini Reach.

Handle Retries

Implement idempotency - same webhook may be sent multiple times if delivery fails.

Use HTTPS

All webhook URLs must use HTTPS for security.

Monitor & Log

Log all webhook events and monitor for failures or delays.

Still Need Help with Automation?

Having trouble setting up webhooks or filters? Our help center has comprehensive guides and troubleshooting steps to get you up and running.

Go to Help Center