# Webhook Setup

To receive real-time updates, set up webhooks in your Facebook App:

```javascript
// Webhook verification (GET)
app.get('/webhook', (req, res) => {
  const mode = req.query['hub.mode'];
  const token = req.query['hub.verify_token'];
  const challenge = req.query['hub.challenge'];

  if (mode === 'subscribe' && token === 'YOUR_VERIFY_TOKEN') {
    res.status(200).send(challenge);
  } else {
    res.sendStatus(403);
  }
});

// Webhook events (POST)
app.post('/webhook', async (req, res) => {
  const data = req.body;

  if (data.object === 'instagram') {
    data.entry.forEach(entry => {
      entry.changes.forEach(async change => {
        if (change.field === 'comments') {
          // New comment received
          const commentId = change.value.id;
          const text = change.value.text;
          
          // Auto-reply to comment
          await instagram.replyToComment(commentId, 'Thanks for your comment!');
        }
      });
    });
  }

  res.sendStatus(200);
});
```