//native
type Telnyx = {
apiKey: string
}
/**
* Gather using speak
* Convert text to speech and play it on the call until the required DTMF signals are gathered to build interactive menus.
*/
export async function main(
auth: Telnyx,
call_control_id: string,
body: {
payload: string
invalid_payload?: string
payload_type?: 'text' | 'ssml'
service_level?: 'basic' | 'premium'
voice: string
voice_settings?: { api_key_ref?: string }
language?:
| 'arb'
| 'cmn-CN'
| 'cy-GB'
| 'da-DK'
| 'de-DE'
| 'en-AU'
| 'en-GB'
| 'en-GB-WLS'
| 'en-IN'
| 'en-US'
| 'es-ES'
| 'es-MX'
| 'es-US'
| 'fr-CA'
| 'fr-FR'
| 'hi-IN'
| 'is-IS'
| 'it-IT'
| 'ja-JP'
| 'ko-KR'
| 'nb-NO'
| 'nl-NL'
| 'pl-PL'
| 'pt-BR'
| 'pt-PT'
| 'ro-RO'
| 'ru-RU'
| 'sv-SE'
| 'tr-TR'
minimum_digits?: number
maximum_digits?: number
maximum_tries?: number
timeout_millis?: number
terminating_digit?: string
valid_digits?: string
inter_digit_timeout_millis?: number
client_state?: string
command_id?: string
}
) {
const url = new URL(
`https://api.telnyx.com/v2/calls/${call_control_id}/actions/gather_using_speak`
)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 428 days ago