# mv.whatsappCalls

> The whatsappCalls methods of @morevoice/sdk: Calls your business places to WhatsApp users.

Calls your business places to WhatsApp users. These methods are on `mv.whatsappCalls`, where `mv` is your client (see [the Node.js SDK](https://docs.morevoice.ai/sdk/node/#connect)). Each one returns the response object and throws when the API answers with an error.

## `create()`

**Call a WhatsApp user.** Calls a WhatsApp user from one of your WhatsApp numbers, with an assistant (`mode: ai`) or with an agent in the browser (`mode: agent`: the agent's browser rings first, then the user). The user must have allowed your business to call them (409 `permission_required` otherwise) and WhatsApp's call limits per user apply (429 `limit_reached`, with the limits in `details` and when they reset in `details.resets_at`); `biz_opaque_callback_data` goes to WhatsApp with the call as written; the do-not-call list applies as for any call. Needs a live key and WhatsApp calling enabled for the organization. The Idempotency-Key header is required, so a retried request never calls anyone twice. The call is a normal call: follow it with GET /v1/calls/{id} and the call.* webhooks.

```ts
mv.whatsappCalls.create(body: WhatsappCallsCreateData["body"], options?: RequestOptions): Promise<WhatsappCallsCreateResponse>
```

`POST /whatsapp_calls` · [API reference](https://docs.morevoice.ai/api/operations/whatsapp_calls_create/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `body.mode` | `"ai" \| "agent"` | yes | `ai`: the assistant talks to the user. `agent`: the agent's browser rings first; the user is called once they answer. |
| `body.agent_id` | `string` | no | mode `agent`: the member who talks, in the browser. Required with mode `agent`. |
| `body.assistant_id` | `string` | no | mode `ai`: the assistant that talks (default: the number's assistant). |
| `body.biz_opaque_callback_data` | `string` | no | Your data for this call at WhatsApp (`biz_opaque_callback_data`, at most 512 characters): WhatsApp returns it in the call's own webhooks (status and terminate), so a relay can match them to its records. Sent as written; returned on the call object. |
| `body.metadata` | `MetadataInput` | no | Up to 50 key/value pairs (keys up to 40 characters, values up to 500) you attach to an object. Returned as sent. |
| `body.recipient` | `string` | no | The WhatsApp user to call by the business-scoped ID WhatsApp gave you, when they don't share their number. Instead of `to`. |
| `body.to` | `string` | no | The WhatsApp user to call: their WhatsApp number (country code first, + optional). |
| `body.whatsapp_number_id` | `string` | no | The business number that calls (one of yours). |
| `body.whatsapp_phone_number_id` | `string` | no | WhatsApp's ID of the business number that calls (digits), instead of `whatsapp_number_id`. |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options.headers["Idempotency-Key"]` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

`WhatsAppCall`:

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | The call's ID (GET /v1/calls/{id}). |
| `object` | `"whatsapp_call"` | Always `whatsapp_call`. |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `mode` | `"ai" \| "agent"` | — |
| `status` | `"queued" \| "ringing"` | `ringing`: the user's phone rings. `queued`: ringing the agent first (mode `agent`), or WhatsApp has not confirmed the call yet. Follow the call with GET /v1/calls/{id} or the call.* webhooks. |
| `wacid` | `string \| null` | WhatsApp's ID of the call; null until WhatsApp named it. |
| `whatsapp_number_id` | `string` | The business number that calls. |
| `to` | `string \| null` | The user's WhatsApp number in E.164 (null when called by `recipient`). |
| `recipient` | `string \| null` | The user's business-scoped WhatsApp ID (null when called by `to`). |
| `assistant_id` | `string \| null` | `asst_…` ID. |
| `agent_id` | `string \| null` | `usr_…` ID. |
| `metadata` | `Metadata` | Up to 50 key/value pairs (keys up to 40 characters, values up to 500) you attach to an object. Returned as sent. |
| `biz_opaque_callback_data` | `string \| null` | Your data for this call at WhatsApp (`biz_opaque_callback_data`, at most 512 characters): WhatsApp returns it in the call's own webhooks (status and terminate), so a relay can match them to its records. Null when none was sent. |
| `created` | `string` | An ISO-8601 timestamp in UTC. |

### Example

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const whatsAppCall = await mv.whatsappCalls.create({
	assistant_id: "asst_7Kp1Ns4Vy6Ab9Dg2Hj5Lm8",
	biz_opaque_callback_data: "chat_88:req_4f2a",
	metadata: {
		crm_contact_id: "0031x00000AbCdE",
	},
	mode: "ai",
	to: "972501234567",
	whatsapp_number_id: "wan_4Gk2LmN9pQ4rS6tV8wX0yZ",
});
console.log(whatsAppCall);
```
