# Examples

> Code examples and templates for Sendable integration.

Source: https://wav1.recrav.com/docs/resources/examples

## GitHub Examples [#github-examples]

<Cards>
  <Card title="Next.js Full-Stack App" description="Complete Next.js application with Sendable integration, webhooks, and dashboard" href="https://github.com/sendablelabs/examples/tree/main/nextjs" external="true" />

  <Card title="Express REST API" description="REST API server with Express and Sendable webhook handling" href="https://github.com/sendablelabs/examples/tree/main/express" external="true" />

  <Card title="Notification Service" description="Standalone notification microservice with retry logic and queue" href="https://github.com/sendablelabs/examples/tree/main/notifications" external="true" />
</Cards>

### Code Snippets [#code-snippets]

#### Send Notification [#send-notification]

Simple notification sender with the SDK:

```typescript
import { Sendable } from '@sendable-dev/sdk'

const sendable = new Sendable({
  apiKey: process.env.SENDABLE_API_KEY!,
  apiKeyScope: 'session',
})

async function sendNotification(chatId: string, message: string) {
  return sendable.messages.send({
    chatId,
    text: { content: message },
  })
}

// Usage
await sendNotification('6281234567890@s.whatsapp.net', 'Your order is ready!')
```

#### Webhook Handler [#webhook-handler]

Basic webhook receiver:

```typescript
import express from 'express'
import { Sendable } from '@sendable-dev/sdk'

const sendable = new Sendable({
  apiKey: process.env.SENDABLE_API_KEY!,
  apiKeyScope: 'session',
  webhookSecret: process.env.SENDABLE_WEBHOOK_SECRET,
})

app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
  const payload = req.body.toString()

  try {
    const event = await sendable.webhooks.verifyAndParse(payload, req.headers)
    console.log(event.type, event.data)
    return res.sendStatus(200)
  } catch {
    return res.status(401).send('Invalid signature')
  }
})
```

### Message Templates [#message-templates]

#### Order Confirmation [#order-confirmation]

```javascript
const orderConfirmation = (order) => ({
  chatId: `${order.customerPhone}@s.whatsapp.net`,
  text: {
    content: `Hi ${order.customerName}! Your order #${order.id} for ${order.total} has been confirmed.`,
  },
})
```

#### Shipping Update [#shipping-update]

```javascript
const shippingUpdate = (order) => ({
  chatId: `${order.customerPhone}@s.whatsapp.net`,
  text: {
    content: `Great news! Your order #${order.id} has shipped. Track: ${order.trackingUrl}`,
  },
})
```

#### Appointment Reminder [#appointment-reminder]

```javascript
const appointmentReminder = (appt) => ({
  chatId: `${appt.patientPhone}@s.whatsapp.net`,
  text: {
    content: `Reminder: Appointment with ${appt.doctorName} on ${appt.date} at ${appt.time}.`,
  },
})
```

### Quick Start [#quick-start]

See [Quick Start](/docs/quickstart/nodejs) for framework-specific examples.
