# autessa.phoneNumbers

Source: https://docs.autessa.com/docs/autessascript/sdk/twilio

> Phone numbers, call flows, call settings, call history, text handling, the shared inbox, and text messages from AutessaScript.

# autessa.phoneNumbers

Buy, route, and manage company phone numbers, and handle their calls and texts.

## Texting from a script

Scripts can find numbers to buy, send texts, and read a number's text history. Sending is checked exactly like the [Send SMS tool](/docs/tools/phone-sms.md#send-sms-): your company needs a finished [Text Messaging registration](/docs/guide/agentic/sms-setup.md) (or the number comes from your own connected Twilio account), and the recipient needs an approved [consent record](/docs/guide/agentic/sms-consent.md) or a text to you within the last year. Opted-out numbers are never texted.

```javascript title="Send a text"
const { ok, data } = autessa.phoneNumbers.smsSend({
  configId: 'pH9nR3vC6b',
  to: '+14155550100',
  body: 'Hi Sam, your order has shipped. Reply STOP to opt out.'
});
if (data.success) console.log('sent', data.messageId, data.status, data.segments);
else console.log('not sent', data.errorCode, data.errorMessage);
```

A refused text isn't an exception: `success` is `false`, `errorCode` says why, and `errorMessage` explains it in plain language.

```javascript title="Read a number's text history"
let cursor;
do {
  const { ok, data } = autessa.phoneNumbers.smsMessagesList({ configId: 'pH9nR3vC6b', pageSize: 25, cursor });
  if (!ok) break;
  data.messages.forEach(m => console.log(m.direction, m.counterparty, m.status, m.body));
  cursor = data.nextCursor;
} while (cursor);
```

Messages come newest first, with the other party's number masked. Blocked sends are included with their reason.

```javascript title="Find numbers to buy"
const { ok, data } = autessa.phoneNumbers.searchNumbers({ areaCode: '206', limit: 10 });
data.numbers.forEach(n => console.log(n.phoneNumber, n.locality, n.region));
```

> `sendSms`, `listSmsMessages`, and `searchNumbers` ship with the Text Messaging release. The reference below is generated from the platform and lists them once the release is live.

## Calls from a script

Scripts can set who answers a number, change its recording and call-limit settings, read its call history, and turn its quick automations on or off. What each setting does is explained in the [Phone Numbers guide](/docs/guide/agentic/phone-numbers.md).

```javascript title="Ring people, with voicemail as the fallback"
const { ok, data } = autessa.phoneNumbers.updateCallFlow({
  configId: 'pH9nR3vC6b',
  callFlow: {
    greeting: 'Thanks for calling Acme Dental.',
    destination: {
      type: 'RING',
      ring: {
        targets: [
          { to: '+14155550100', label: 'Front desk' },
          { to: '+14155550101', label: 'Office manager', ringSeconds: 30 }
        ],
        strategy: 'SEQUENTIAL',
        ringSeconds: 20,
        maxTotalSeconds: 45,
        requireKeyPress: true,
        whisper: 'Call from the Acme Dental line.',
        noAnswer: { type: 'VOICEMAIL', voicemail: { maxSeconds: 120, finishOnKey: '#', transcribe: true } }
      }
    }
  }
});
if (ok) console.log(data.routingType); // "FLOW"
```

Pass `callFlow: null` to go back to sending every call straight to the number's agent or multi-agent. An invalid flow (an unknown agent, a bad time, a phone number not in E.164 format) comes back with `ok` false and a plain-language message. Every flow field, including holiday `closedDates`, menu timing and messages, and ring options like `callerId` and `waitAudio`, is described in the [call flow object](/docs/api/poweruser/phone-numbers.md#the-call-flow-object) reference.

```javascript title="Upload a recorded greeting"
// 1. get an upload link
const link = autessa.phoneNumbers.audioUploadLink({ configId: 'pH9nR3vC6b', fileType: 'mp3' }).data;
console.log(link.uploadUrl, link.contentType, link.audioUri);
// 2. PUT the file to link.uploadUrl with the header "Content-Type: <link.contentType>",
//    from curl or any HTTP client that can send a file's raw bytes
// 3. once it's uploaded, save link.audioUri into an audio field
autessa.phoneNumbers.updateCallFlow({
  configId: 'pH9nR3vC6b',
  callFlow: {
    greeting: 'Thanks for calling Acme Dental.',
    greetingAudio: link.audioUri,
    destination: { type: 'AI_AGENT', resourceId: 'V1StGXR8Z5' }
  }
});
```

The upload must use exactly the `contentType` the link came with, and must happen before `expiresInSeconds` runs out. The [`api` helper](/docs/autessascript/helpers/api.md) sends text bodies, so upload the audio file itself from outside the script. Audio fields (`greetingAudio`, `messageAudio`, `promptAudio`, a voicemail's `greetingAudio`, a ring's `waitAudio`) also accept an `https://` link to a file you host. When one is set, it plays instead of the matching text.

```javascript title="Record calls and remove card numbers"
const { ok, data } = autessa.phoneNumbers.updateCallSettings({
  configId: 'pH9nR3vC6b',
  callSettings: {
    recording: { save: true, announcement: 'This call may be recorded.' },
    redaction: { enabled: true, redact: ['CARD_NUMBER', 'CARD_EXPIRY', 'CARD_CVV'], audioRedaction: 'TONE' },
    limits: { maxDurationMinutes: 30, silenceTimeoutSeconds: 20 }
  }
});
```

Settings sections are `speech` (voice and language), `transcript` and `recording` (each with an optional `retentionDays`), `redaction`, `limits`, `callerInfo`, `screening` (blocked callers), `ai` (interruptions, end-of-turn speed, hang-up phrases, key presses), and `answeringMachine` (detection on outgoing calls). Call Redaction costs $0.15 per audio hour, or $0.20 with health and national ID types. Every field and range is in the [call settings object](/docs/api/poweruser/phone-numbers.md#the-call-settings-object) reference.

```javascript title="Answer in Spanish, block a number, and keep recordings for 90 days"
const { data: options } = autessa.phoneNumbers.voiceOptions({});
options.languages.forEach(l => console.log(l.code, l.label));

autessa.phoneNumbers.updateCallSettings({
  configId: 'pH9nR3vC6b',
  callSettings: {
    speech: { language: 'es-US' },
    recording: { save: true, announcement: 'Esta llamada puede ser grabada.', retentionDays: 90 },
    screening: { blockedNumbers: ['+15555550123'], rejectAnonymous: true },
    ai: { endOfTurn: 'PATIENT', hangUpPhrases: ['Que tenga un buen día'] }
  }
});
```

`voiceOptions` lists the languages and voices you can use in `speech`.

```javascript title="Read call history"
let after;
do {
  const { ok, data } = autessa.phoneNumbers.callsList({ configId: 'pH9nR3vC6b', limit: 50, after });
  if (!ok) break;
  data.calls.forEach(c => console.log(c.startedAt, c.direction, c.otherNumber, c.status, c.durationSeconds));
  after = data.next;
} while (after);
```

Calls come newest first from your company's [Phone calls table](/docs/guide/agentic/phone-numbers.md#the-phone-calls-table). Each call includes its caller info, status, who handled it, the transcript, and links to the recording and voicemail that stay valid for 10 minutes. `data.tableId` is the Phone calls table, so you can also query it directly with [`autessa.autessadb`](/docs/autessascript/sdk/autessadb.md).

```javascript title="Email new voicemails to the front desk"
autessa.phoneNumbers.setAutomation({
  configId: 'pH9nR3vC6b',
  automation: 'EMAIL_VOICEMAILS',
  enabled: true,
  emails: ['frontdesk@example.com']
});
```

`automation` is `TEXT_BACK_MISSED_CALLS` (with `smsMessage`; the number must be able to text) or `EMAIL_VOICEMAILS` (with up to 5 `emails`). `enabled: false` turns it off without deleting the trigger behind it.

> `updateCallFlow`, `updateCallSettings`, `getCalls`, `setAutomation`, `audioUploadLink`, and `voiceOptions` ship with the phone call controls release. The reference below lists them once the release is live.

## Texts without AI from a script

Scripts can decide who answers a number's texts, read and reply to its shared inbox, and forward texts to your team. What each setting does is explained in [Texts](/docs/guide/agentic/phone-numbers.md#texts).

```javascript title="Team answers texts by day, an AI agent after hours"
const { ok, data } = autessa.phoneNumbers.updateTextFlow({
  configId: 'pH9nR3vC6b',
  textFlow: {
    keywordReplies: [{ keyword: 'HOURS', reply: 'We are open Monday to Friday, 9 to 5.' }],
    useCallFlowHours: true,
    open: {
      type: 'NO_AI',
      autoReply: { message: 'Thanks for your message. We will text you back shortly.', onceEveryHours: 24 }
    },
    closed: { type: 'AI_AGENT', resourceId: 'V1StGXR8Z5' }
  }
});
if (ok) console.log(data.config.textFlow);
```

Pass `textFlow: null` to go back to the default: the agent the number sends calls to directly answers texts, or, without one, texts get no reply and wait in the inbox. STOP, START, and HELP are always handled first. Every field is in the [text flow object](/docs/api/poweruser/phone-numbers.md#the-text-flow-object) reference.

```javascript title="Read the inbox and reply"
const threads = autessa.phoneNumbers.smsThreadsList({ configId: 'pH9nR3vC6b', limit: 20 }).data.threads;
threads.forEach(t => console.log(t.otherNumber, t.lastDirection, t.lastBody, t.messageCount));

const first = threads[0];
const { data } = autessa.phoneNumbers.smsThreadGet({ configId: 'pH9nR3vC6b', otherNumber: first.otherNumber, limit: 50 });
data.messages.forEach(m => console.log(m.sentAt, m.direction, m.handledBy, m.body));

if (first.lastDirection === 'INBOUND') {
  autessa.phoneNumbers.smsSend({ configId: 'pH9nR3vC6b', to: first.otherNumber, body: 'Thanks, we got your message.' });
}
```

Pass `next` as `after` for more threads, or as `before` for older messages in a thread. Replies go out as the business number and are checked like any other text.

```javascript title="Forward incoming texts to the front desk"
autessa.phoneNumbers.setAutomation({
  configId: 'pH9nR3vC6b',
  automation: 'FORWARD_TEXTS_SMS',
  enabled: true,
  phones: ['+14155550100']
});
```

`FORWARD_TEXTS_SMS` takes up to 5 `phones`, and `FORWARD_TEXTS_EMAIL` up to 5 `emails`. Forwarded texts are sent from the business number, so each phone must be allowed to receive texts from it (texting the number once from each phone is enough). Every text is also a row in your company's [Text messages table](/docs/guide/agentic/phone-numbers.md#the-text-messages-table); `textLogTableId` from `getConfig` is its id, so you can query it with [`autessa.autessadb`](/docs/autessascript/sdk/autessadb.md).

> `updateTextFlow`, `listSmsThreads`, `getSmsThread`, and the forwarding automations ship with the texting-without-AI release. The reference below lists them once the release is live.

## Related

- [Autessa SDK overview](/docs/autessascript/sdk.md)
- [Text Messaging setup](/docs/guide/agentic/sms-setup.md)
- [Phone and SMS tool types](/docs/tools/phone-sms.md)

