Make a Phone Call
One script reply has been approved by the moderators Verified

Make a phone call, passing text that Twilio will speak to the recipient of the call. See the docs for more information

Created by stephanesbei 1291 days ago
Submitted by hugo697 Bun
Verified 225 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