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

# Voice calls

> Let people talk to an AI voice agent from your site or by phone.

Create a voice agent under **Agents → Inbound agents**. On its **Connect** tab, give it a phone number, put it on your site, or both. Every call is saved under Communications with a transcript and a summary.

## By phone

Give the agent a number you bought in the CRM, under **Connect → Telephony**. It answers while it's on.

* One number answers for one agent.
* A caller whose number belongs to a contact is filed under that contact.
* Numbers from a Twilio account you connected yourself can't be used.

## On your site

The call runs in the visitor's browser. Your server starts it, so your API key stays private.

On your server:

> [tab] Upsert
>
> ```ts theme={null}
> // the signed-in user, as a contact: created the first time, found every time after
> const [contact, contactError] = await crm.contacts.upsert({
>   dbId: user.id,
>   name: user.name,
>   emails: [user.email],
> });
> if (contactError) throw new Error(contactError.message);
>
> // credentials for one call with that contact, for the page to pass to gdcall.open
> const [credentials, callError] = await crm.calls.generateCredentials({
>   agentId: "0199…",
>   partyId: contact.id,
> });
> if (callError) throw new Error(callError.message);
> ```

> [tab] Look up
>
> ```ts theme={null}
> // the customer you already sent, found by your own id
> const [found, lookupError] = await crm.contacts.resolve({ dbId: user.id });
> if (lookupError) throw new Error(lookupError.message);
>
> // credentials for one call with that contact, for the page to pass to gdcall.open
> const [credentials, callError] = await crm.calls.generateCredentials({
>   agentId: "0199…",
>   partyId: found.partyId,
> });
> if (callError) throw new Error(callError.message);
> ```

> [tab] Saved id
>
> ```ts theme={null}
> // the contact.id you saved in your own database the first time
> const [credentials, callError] = await crm.calls.generateCredentials({
>   agentId: "0199…",
>   partyId: user.crmPartyId,
> });
> if (callError) throw new Error(callError.message);
> ```

**Upsert** creates the customer if they're new. **Look up** finds one you've already sent. **Saved id** is fastest: store `contact.id` in your own database the first time, and skip the extra call.

On the page, from your own button's click:

```html theme={null}
<script src="https://app.revenuebee.ai/call.js"></script>
<script>
  const call = gdcall.open({
    credentials, // from your server
    variant: "full", // or "compact"
    position: "bottom_right", // or "bottom_center", "bottom_left"
    onEvent: (event) => {
      // { type: "state", state: "connecting" | "live" | "ended", communicationId? }
      // { type: "transcript", id, speaker: "agent" | "customer", text, final }
      // { type: "speaking", speaking: true | false }
    },
  });
  // call.close() ends the call
</script>
```

* **Start it from a click.** Browsers only allow audio after one.
* **Credentials are good for one call.** Get new ones on every click.
* **`full`** shows the conversation as it happens; **`compact`** shows just the orb.
* **Transcripts arrive word by word**: the same `id` again with more text, until `final` is `true`.

### Let the script draw the button

```html theme={null}
<script>
  const button = gdcall.init({
    buttonText: "Talk to us",
    getCredentials: () => fetch("/api/call", { method: "POST" }).then((response) => response.json()),
    variant: "full",
    position: "bottom_right",
  });
  // button.close() takes it off the page
</script>
```

It asks your server for credentials on every click, and hides while a call is open.

### Your colours

Pass `colors` to `open` or `init`. Every one is optional and takes any CSS colour.

| Colour | Paints |
| - | - |
| `background` | The panel |
| `text` | The words |
| `border` | The panel's outline |
| `button` | The mute and close buttons |
| `danger` | The end call button |
| `launcher` | The button `init` draws |
| `orb` | The orb's two colours, as `["#3b5bdb", "#d9a514"]` |

### Build your own interface

`gdcall.connect({ credentials, onEvent })` runs the call with nothing on screen. It returns `mute(true)`, `hangUp()` and `levels()`, which gives `{ input, output }` from 0 to 1 for drawing.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.