Skip to content

Add LINE webhook support (bypass Cloudflare Access + add public route) #101

@Amusac

Description

@Amusac

Summary

When using the LINE Messaging API channel plugin with Moltworker, LINE webhooks fail with a 302 redirect because:

  1. Cloudflare Access blocks the incoming webhook request
  2. No public route exists in the Worker to proxy the webhook to the sandbox

Steps to Reproduce

  1. Deploy Moltworker with Cloudflare Access enabled
  2. Configure LINE channel in Clawdbot (channels.line)
  3. Set LINE webhook URL to https://<worker>.workers.dev/line/webhook
  4. Click "Verify" in LINE Developers Console
  5. Get 302 Found error

Solution

1. Add public route in src/routes/public.ts

Add before export { publicRoutes };:

// POST /line/webhook - LINE webhook endpoint (no auth required)
publicRoutes.post('/line/webhook', async (c) => {
  const sandbox = c.get('sandbox');
  
  try {
    const response = await sandbox.containerFetch(
      new Request(`http://localhost:${MOLTBOT_PORT}/line/webhook`, {
        method: 'POST',
        headers: c.req.raw.headers,
        body: c.req.raw.body,
      }),
      MOLTBOT_PORT
    );
    
    return new Response(response.body, {
      status: response.status,
      headers: response.headers,
    });
  } catch (err) {
    console.error('[LINE] Webhook proxy error:', err);
    return c.json({ error: 'Gateway not ready' }, 503);
  }
});
  1. Create Cloudflare Access Bypass Application

  2. Go to Cloudflare Zero Trust Dashboard

  3. Access → Applications → Add application → Self-hosted

  4. Set: • Application domain: .workers.dev
    • Path: /line/webhook

  5. Add policy: • Action: Bypass
    • Include: Everyone

Suggestion

Consider adding LINE webhook route to the default public.ts and documenting the Cloudflare Access bypass requirement in the README.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions