0

Make a Phone Call

by
Published Jun 6, 2022

Make a phone call, passing text that Twilio will speak to the recipient of the call. [See the docs](https://www.twilio.com/docs/voice/api/call-resource#create-a-call-resource) for more information

Script twilio Verified

The script

Submitted by hugo697 Bun
Verified 398 days ago
1
import { Twilio } from "twilio";
2

3
type Twilio = {
4
  accountSid: string;
5
  token: string;
6
};
7

8
export async function main(
9
  twilio: Twilio,
10
  fromPhoneNumber: string,
11
  toPhoneNumber: string,
12
  text: string
13
) {
14
  const client = new Twilio(twilio.accountSid, twilio.token);
15

16
  const call = await client.calls.create({
17
    url:
18
      "http://twimlets.com/echo?Twiml=<Response><Say>" +
19
      encodeURIComponent(text) +
20
      "</Say></Response>",
21
    to: toPhoneNumber,
22
    from: fromPhoneNumber,
23
  });
24

25
  return call;
26
}
27

Other submissions
  • Submitted by hugo697 Deno
    Created 974 days ago
    1
    import { Twilio } from "twilio";
    2
    
    
    3
    type Twilio = {
    4
      accountSid: string;
    5
      token: string;
    6
    };
    7
    
    
    8
    export async function main(
    9
      twilio: Twilio,
    10
      fromPhoneNumber: string,
    11
      toPhoneNumber: string,
    12
      text: string
    13
    ): Promise<void> {
    14
      const client = new Twilio(twilio.accountSid, twilio.token);
    15
    
    
    16
      const call = await client.calls.create({
    17
        url:
    18
          "http://twimlets.com/echo?Twiml=<Response><Say>" +
    19
          encodeURIComponent(text) +
    20
          "</Say></Response>",
    21
        to: toPhoneNumber,
    22
        from: fromPhoneNumber,
    23
      });
    24
    
    
    25
      console.log(call.sid);
    26
    }
    27