> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sendpilot.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# message.sent

> Triggered when a message is sent to a lead

This event is triggered when a LinkedIn message is successfully sent to a lead, either through campaign automation or via the API.

## When This Event Fires

* Campaign automation sends a follow-up message
* Message is sent via the [Send Message API](/api-reference/endpoint/post-send-message)
* A message is successfully delivered to the lead's LinkedIn inbox

## Payload

```json theme={null}
{
  "eventId": "evt_1708456789123_abc123def",
  "eventType": "message.sent",
  "timestamp": "2024-02-24T10:30:00.000Z",
  "workspaceId": "ws_abc123xyz",
  "data": {
    "leadId": "lead_abc123",
    "campaignId": "camp_xyz789",
    "linkedinUrl": "https://www.linkedin.com/in/john-doe",
    "senderId": "sender_def456",
    "message": "Hi John! Thank you for connecting. I wanted to reach out about our new product that could help your team increase productivity by 40%. Would you be open to a quick 15-minute call this week?",
    "sequenceStep": 2
  }
}
```

## Payload Fields

| Field               | Type   | Description                                         |
| ------------------- | ------ | --------------------------------------------------- |
| `eventId`           | string | Unique event identifier for idempotency             |
| `eventType`         | string | Always `message.sent`                               |
| `timestamp`         | string | ISO 8601 timestamp when the message was sent        |
| `workspaceId`       | string | Your workspace ID                                   |
| `data.leadId`       | string | The lead who received the message                   |
| `data.campaignId`   | string | The campaign this lead belongs to                   |
| `data.linkedinUrl`  | string | LinkedIn profile URL of the lead                    |
| `data.senderId`     | string | LinkedIn sender account that sent the message       |
| `data.message`      | string | Full message content that was sent                  |
| `data.sequenceStep` | number | Which step in the campaign sequence (if applicable) |

## Use Cases

<CardGroup cols={2}>
  <Card title="CRM Integration" icon="database">
    Log message activity in your CRM to maintain conversation history
  </Card>

  <Card title="Analytics" icon="chart-line">
    Track message delivery and sequence progression
  </Card>

  <Card title="Notifications" icon="bell">
    Alert team members when outreach is sent
  </Card>

  <Card title="Audit Trail" icon="list-check">
    Build an audit log of all outreach activity
  </Card>
</CardGroup>

## Example Handler

```javascript theme={null}
app.post('/webhooks/sendpilot', (req, res) => {
  const event = req.body;
  
  if (event.eventType === 'message.sent') {
    const { leadId, campaignId, message, sequenceStep } = event.data;
    
    // Log to your CRM
    await crm.logActivity({
      leadId,
      type: 'linkedin_message_sent',
      content: message,
      metadata: { campaignId, sequenceStep }
    });
    
    console.log(`Message sent to lead ${leadId} (step ${sequenceStep})`);
  }
  
  res.status(200).send('OK');
});
```

<Note>
  The `message` field contains the full message content that was sent to the lead.
</Note>
