1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Send a message using number pool |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | body: { |
12 | messaging_profile_id: string |
13 | to: string |
14 | text?: string |
15 | subject?: string |
16 | media_urls?: string[] |
17 | webhook_url?: string |
18 | webhook_failover_url?: string |
19 | use_profile_webhooks?: false | true |
20 | type?: 'SMS' | 'MMS' |
21 | auto_detect?: false | true |
22 | } |
23 | ) { |
24 | const url = new URL(`https://api.telnyx.com/v2/messages/number_pool`) |
25 |
|
26 | const response = await fetch(url, { |
27 | method: 'POST', |
28 | headers: { |
29 | 'Content-Type': 'application/json', |
30 | Authorization: 'Bearer ' + auth.apiKey |
31 | }, |
32 | body: JSON.stringify(body) |
33 | }) |
34 | if (!response.ok) { |
35 | const text = await response.text() |
36 | throw new Error(`${response.status} ${text}`) |
37 | } |
38 | return await response.json() |
39 | } |
40 |
|