> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# Dialer

> Place an outbound call to an agent or a SWML document only once every check, such as consent and calling hours, passes.

[rest-client]: /docs/server-sdks/reference/python/rest/client

[dial]: /docs/server-sdks/reference/python/rest/calling/dial

`Dialer` places an outbound call to an agent's URL, or runs a SWML document, only once
every check passes. Otherwise it raises `NotPlaced` with the reason and makes no
request. Calling hours are read on the callee's own clock. Pacing, retries, and
outcomes belong to your scheduler, which calls `place()`.

```python
from signalwire.operations.outbound import (
    Callee, Dialer, NotPlaced, calling_hours, consented,
)
```

## Parameters

**`client`** `RestClient` — required

A [`RestClient`][rest-client].

---

**`from_number`** `str` — required

Keyword-only, as are all the parameters below. The number calls come from.

---

**`url`** `str | None` — default: None

The agent's URL. The callee's `data` is added to it as query parameters. Give exactly
one of `url` and `swml`, or `ValueError` is raised.

---

**`swml`** `Mapping[str, Any] | None` — default: None

A SWML document to run in place of an agent at a URL.

---

**`checks`** `Sequence[Check]` — default: ()

What must pass before a call is placed, in order. The first objection stops the call.

---

**`timeout`** `int | None` — default: None

How long to ring, in seconds. The platform's default when `None`.

---

**`status_url`** `str | None` — default: None

Where the platform posts the call's progress.

---

**`status_events`** `Sequence[str] | None` — default: None

Which progress events to post, such as `["answered", "ended"]`.

---

## Methods

### place

`place(callee, now=None)` dials `callee` once every check passes and returns the
result of [`client.calling.dial()`][dial]. Raises `NotPlaced` with the first
objection otherwise, and makes no request.

### why_not

`why_not(callee, now=None)` returns why a call to `callee` can't be placed now, or
`None` when every check passes. Places no call.

For both methods, `now` is the time to check at, for tests. It must carry a time zone,
or `ValueError` is raised; it defaults to the current time.

## Callee

`Callee(number, zone, data={})`, a frozen dataclass, is the person to be called.

**`Callee.number`** `str` — required

Their number, in E.164 form.

---

**`Callee.zone`** `str` — required

Their IANA time zone name, such as `"America/Chicago"`. A name that isn't a time zone
raises `ValueError`.

---

**`Callee.data`** `Mapping[str, Any]`

What the call is about, added to the agent's URL as query parameters.

---

## NotPlaced

`NotPlaced(callee, reason)` is raised by `place()` in place of dialing. It has
`.callee` and `.reason`.

## Checks

A check has the type `Check = Callable[[Callee, datetime], str | None]`: it returns why
the call can't be placed now, or `None`. `now` is an aware UTC time. Use the built-in
checks or any function of your own with the same type.

* `consented(lookup)`: `lookup(callee)` returns `True` when consent is on record,
  `False` when it was withdrawn, or `None` when there's none on record. Only `True`
  lets the call through.
* `calling_hours(start, end, *, days=None)`: the callee's local time must be within
  `start` and `end` (`datetime.time` values, inclusive), and on one of `days` when
  given, with Monday as 0 through Sunday as 6.

## Example

This places a real call, so it needs `SIGNALWIRE_PROJECT_ID`, `SIGNALWIRE_API_TOKEN`,
and `SIGNALWIRE_SPACE`.

```python
from datetime import time

from signalwire.operations.outbound import Callee, Dialer, NotPlaced, calling_hours, consented
from signalwire.rest import RestClient

CONSENT = {"+15557654321": True}

dialer = Dialer(
    RestClient(),
    from_number="+15550001111",
    url="https://agents.example.com/reminders",
    checks=[consented(lambda callee: CONSENT.get(callee.number)), calling_hours(time(9), time(20))],
)

try:
    dialer.place(Callee("+15557654321", "America/Los_Angeles", {"appointment": "a1"}))
except NotPlaced as e:
    print(e.reason)
```

The call is placed to `https://agents.example.com/reminders?appointment=a1`.