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

# WhatsApp Accounts

> Manage WhatsApp Business accounts, phone numbers, and templates

The WhatsApp Accounts resource provides access to your connected WhatsApp Business Accounts and their phone numbers.

## Overview

```typescript theme={null}
// WhatsApp Accounts
client.whatsappAccounts.list()
client.whatsappAccounts.get(id)
client.whatsappAccounts.create(input)
client.whatsappAccounts.deployAgent(id, input)
client.whatsappAccounts.addNumber(id, input)
client.whatsappAccounts.getAvailableNumbers()

// Business API Proxy
client.whatsappAccounts.proxy(id, method, path, options)
client.whatsappAccounts.getTemplates(id, wabaId)
client.whatsappAccounts.createTemplate(id, wabaId, input)
client.whatsappAccounts.getBusinessProfile(wabaId, phoneId)

// Link Sessions
client.whatsappLinkSessions.create(input)
client.whatsappLinkSessions.get(id)
client.whatsappLinkSessions.list()

// Phone Numbers
client.phoneNumbers.list()
client.phoneNumbers.get(number)
```

## List WhatsApp Accounts

Get all connected WhatsApp Business Accounts.

```typescript theme={null}
const accounts = await client.whatsappAccounts.list();

accounts.forEach(account => {
  console.log(`${account.name || 'Unnamed'} (${account.waId})`);
  console.log(`Phone numbers: ${account.phoneNumbers.length}`);
});
```

### Response Type

```typescript theme={null}
interface WhatsAppAccount {
  id: UUID;
  name: string | null;
  waId: string;                    // Meta's WABA ID
  phoneNumbers: WhatsAppPhoneNumber[];
  templatesUrl: string;
}

interface WhatsAppPhoneNumber {
  id: UUID;
  number: string;
  bot: { id: UUID; name: string } | null;
  waba: { id: UUID; name: string | null } | null;
}
```

## Get WhatsApp Account

Retrieve a single account with its phone numbers.

```typescript theme={null}
const account = await client.whatsappAccounts.get(accountId);

console.log(`Account: ${account.name}`);
account.phoneNumbers.forEach(phone => {
  console.log(`  ${phone.number}: ${phone.bot?.name || 'No agent deployed'}`);
});
```

## Connect a New Account

Create a link session to connect a new WhatsApp Business Account.

```typescript theme={null}
// Create a link session
const session = await client.whatsappAccounts.create({
  successUrl: 'https://yourapp.com/whatsapp/success',
  returnUrl: 'https://yourapp.com/whatsapp/return',
});

// Redirect user to Meta's signup flow
window.location.href = session.linkUrl;
```

After the user completes the flow, they'll be redirected to your success URL.

## Link Sessions

Manage the WhatsApp connection flow.

### Create Session

```typescript theme={null}
const session = await client.whatsappLinkSessions.create({
  successUrl: 'https://yourapp.com/success',
  returnUrl: 'https://yourapp.com/return',
});

console.log(`Redirect to: ${session.linkUrl}`);
```

### Check Session Status

```typescript theme={null}
const session = await client.whatsappLinkSessions.get(sessionId);

switch (session.status) {
  case 'PENDING':
    console.log('User has not completed signup');
    break;
  case 'SUCCESS':
    console.log('Account connected successfully');
    break;
  case 'FAILED':
    console.log('Connection failed');
    break;
  case 'EXPIRED':
    console.log('Session expired');
    break;
}
```

### List All Sessions

```typescript theme={null}
const sessions = await client.whatsappLinkSessions.list();
```

## Deploy Agent to Account

Deploy an agent to a phone number within an account.

```typescript theme={null}
const updated = await client.whatsappAccounts.deployAgent(accountId, {
  agentId: 'agent-uuid',
  phoneNumberId: 'phone-number-uuid',
});
```

## Add Phone Number

Add a pre-verified phone number to an account.

```typescript theme={null}
// Get available pre-verified numbers
const available = await client.whatsappAccounts.getAvailableNumbers();

if (available.length > 0) {
  const added = await client.whatsappAccounts.addNumber(accountId, {
    id: available[0].id,
    name: 'Customer Support Line',
  });
}
```

## Phone Numbers

Access phone numbers directly.

### List Phone Numbers

```typescript theme={null}
const numbers = await client.phoneNumbers.list();

numbers.forEach(phone => {
  console.log(`${phone.number}: ${phone.activeAgent?.name || 'No agent'}`);
});
```

### Get Phone Number

```typescript theme={null}
const phone = await client.phoneNumbers.get('14155551234');

console.log(`Number: ${phone.number}`);
console.log(`WABA: ${phone.whatsappBusinessAccount?.name}`);
console.log(`Agent: ${phone.activeAgent?.name}`);
```

## Business API Proxy

Access the WhatsApp Business API directly through Wassist's proxy.

### Generic Proxy Method

```typescript theme={null}
// GET request
const templates = await client.whatsappAccounts.proxy<{ data: Template[] }>(
  accountId,
  'GET',
  `${wabaId}/message_templates`
);

// POST request
const result = await client.whatsappAccounts.proxy(
  accountId,
  'POST',
  `${wabaId}/message_templates`,
  {
    body: {
      name: 'my_template',
      category: 'UTILITY',
      language: 'en',
      components: [/* ... */],
    },
  }
);
```

### Helper Methods

#### Get Templates

```typescript theme={null}
const templates = await client.whatsappAccounts.getTemplates(
  accountId,  // Our internal UUID
  wabaId      // Meta's WABA ID
);

templates.forEach(t => {
  console.log(`${t.name}: ${t.status}`);
});
```

#### Create Template

```typescript theme={null}
const template = await client.whatsappAccounts.createTemplate(
  accountId,
  wabaId,
  {
    name: 'order_update',
    category: 'UTILITY',
    language: 'en',
    components: [
      {
        type: 'HEADER',
        format: 'TEXT',
        text: 'Order Update',
      },
      {
        type: 'BODY',
        text: 'Hi {{1}}, your order {{2}} is now {{3}}.',
        example: {
          body_text: [['John', 'ORD-123', 'shipped']],
        },
      },
      {
        type: 'FOOTER',
        text: 'Thanks for shopping with us!',
      },
    ],
  }
);
```

#### Get Business Profile

```typescript theme={null}
const profile = await client.whatsappAccounts.getBusinessProfile(
  accountId,       // Our internal WABA UUID
  phoneNumberId    // Meta's phone number ID
);

console.log(`About: ${profile.about}`);
console.log(`Email: ${profile.email}`);
console.log(`Website: ${profile.websites?.join(', ')}`);
```

## Complete Example

```typescript theme={null}
import { createWassistClient } from '@wassist/sdk';

const client = createWassistClient({
  baseUrl: 'https://backend.wassist.app/api/v1/',
  authToken: process.env.WASSIST_TOKEN,
});

async function setupWhatsAppIntegration() {
  // 1. Create a link session
  const session = await client.whatsappLinkSessions.create({
    successUrl: 'https://myapp.com/whatsapp/success',
    returnUrl: 'https://myapp.com/whatsapp/cancel',
  });
  
  console.log(`Redirect user to: ${session.linkUrl}`);
  
  // ... user completes Meta's signup flow ...
  
  // 2. Check session status (after redirect)
  const completed = await client.whatsappLinkSessions.get(session.id);
  
  if (completed.status !== 'SUCCESS') {
    throw new Error('Connection failed');
  }
  
  // 3. Get the connected account
  const accounts = await client.whatsappAccounts.list();
  const newAccount = accounts[accounts.length - 1];
  
  // 4. Create a message template
  await client.whatsappAccounts.createTemplate(
    newAccount.id,
    newAccount.waId,
    {
      name: 'welcome_message',
      category: 'MARKETING',
      language: 'en',
      components: [
        {
          type: 'BODY',
          text: 'Welcome to our service, {{1}}! Reply to get started.',
          example: { body_text: [['John']] },
        },
      ],
    }
  );
  
  // 5. Deploy an agent to the phone number
  if (newAccount.phoneNumbers.length > 0) {
    await client.whatsappAccounts.deployAgent(newAccount.id, {
      agentId: 'my-agent-uuid',
      phoneNumberId: newAccount.phoneNumbers[0].id,
    });
  }
  
  console.log('WhatsApp integration complete!');
}
```

## Related

<CardGroup cols={2}>
  <Card title="Connect WhatsApp Guide" icon="plug" href="/guides/connect-whatsapp">
    Step-by-step connection guide.
  </Card>

  <Card title="Deploy Agent Guide" icon="rocket" href="/guides/deploy-agent">
    Deploy agents to phone numbers.
  </Card>
</CardGroup>
