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

# During a call: end, pause, mute and more

> Control a Web SDK call once it has started: end it, pause and resume, mute the microphone, set the agent's volume, send keypad digits, and get the call's ID.

## Show what the agent is doing

`agentStateChanged` tells you what the agent is doing, so your page can show it:

| State | What it means |
| - | - |
| `idle` | No conversation yet. |
| `initializing` | The agent is getting ready. |
| `listening` | The agent is waiting for the visitor to speak. |
| `thinking` | The agent is working out its answer. |
| `speaking` | The agent is talking. |

```javascript theme={null}
agent.on("agentStateChanged", (state) => {
  callStatus.dataset.state = state; // style each state in your CSS
});
```

`speaking` and `listening` also fire as events of their own.

## End the call

```javascript theme={null}
agent.end();
```

`callEnded` fires, then `closed`. They also fire when the agent ends the call, or the connection is lost for good. After `end()`, `callEnded` can fire twice, so make your handler safe to run more than once. Leaving or reloading the page ends the call too.

## Pause and resume

```javascript theme={null}
agent.pause();  // fires callPaused
agent.resume(); // fires callResumed
```

`pause()` turns off the visitor's microphone and stops playing the agent. The call stays connected while it's paused. `resume()` turns both back on.

## Mute the microphone

```javascript theme={null}
agent.setMicMuted(true);            // fires micMuted
agent.setMicMuted(false);           // fires micUnmuted
agent.setMicMuted(!agent.isMicMuted()); // toggle
```

The agent keeps talking while the visitor is muted.

## Set the agent's volume

```javascript theme={null}
agent.setVolume(0.5);             // 0 (silent) to 1 (full)
const volume = agent.getOutputVolume();
```

This changes how loud the agent plays in the page, not the visitor's microphone. Values outside 0 to 1 are clamped.

## Send keypad digits

For agents that ask the caller to press a key, such as a menu, send the digit as a phone keypad would:

```javascript theme={null}
agent.on("dtmfSent", (digit) => highlightKey(digit));

agent.sendDTMF("1"); // "0" to "9", "*" or "#"
```

`sendDTMF()` throws if there's no call, or if the digit isn't one of those.

## The call's ID

`callStarted` sends the call's ID. It's the ID in **Call history**, in the agent's [webhook](https://docs.tryhamsa.com/agents/connect/webhooks.md), and in the API's [call endpoints](https://docs.tryhamsa.com/api-reference/endpoint/get-conversation.md).

```javascript theme={null}
agent.on("callStarted", ({ jobId }) => {
  saveCallId(jobId);
});

const jobId = agent.getJobId(); // the current call's ID, or null
```

To read the call's transcript and outcome after it ends, use the agent's [webhook](https://docs.tryhamsa.com/agents/connect/webhooks.md), or read the call from your server with a secret key ([Get a call](https://docs.tryhamsa.com/api-reference/endpoint/get-conversation.md)). `agent.getJobDetails()` works only with an older API key in the page, so with a public key or a call token it throws.

## Related

> [card] [Events](https://docs.tryhamsa.com/developers/sdks/web-sdk/events.md)
>
> Every event the SDK sends, and live transcripts.

> [card] [Audio](https://docs.tryhamsa.com/developers/sdks/web-sdk/audio.md)
>
> Levels, visualizers, and capturing the call's audio.


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