//native
type Telnyx = {
apiKey: string
}
/**
* Send a fax
* Send a fax. Files have size limits and page count limit validations. If a file is bigger than 50MB or has more than 350 pages it will fail with `file_size_limit_exceeded` and `page_count_limit_exceeded` respectively.
**Expected Webhooks:**
- `fax.queued`
- `fax.media.processed`
- `fax.sending.started`
- `fax.delivered`
- `fax.failed`
*/
export async function main(
auth: Telnyx,
body: {
connection_id: string
media_url?: string
media_name?: string
to: string
from: string
from_display_name?: string
quality?: 'normal' | 'high' | 'very_high' | 'ultra_light' | 'ultra_dark'
t38_enabled?: false | true
monochrome?: false | true
store_media?: false | true
store_preview?: false | true
preview_format?: 'pdf' | 'tiff'
webhook_url?: string
client_state?: string
}
) {
const url = new URL(`https://api.telnyx.com/v2/faxes`)
const formData = new FormData()
for (const [k, v] of Object.entries(body)) {
if (v !== undefined && v !== '') {
formData.append(k, String(v))
}
}
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