From 977c10c86642bc6a3d80ce9f5949c7f06cf3339b Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Sat, 4 Mar 2023 16:20:00 -0500 Subject: [PATCH] feat: basic calling express server --- .env.sample | 3 ++- call.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.env.sample b/.env.sample index 7b9bdeb..8c709d2 100644 --- a/.env.sample +++ b/.env.sample @@ -1,3 +1,4 @@ OPENAI_API_KEY="openaikey" TWILIO_ACCOUNT_SID=account_sid -TWILIO_AUTH_TOKEN=auth_token \ No newline at end of file +TWILIO_AUTH_TOKEN=auth_token +TWILIO_PHONE_NUMBER=phone_number \ No newline at end of file diff --git a/call.js b/call.js index 890055c..074fa48 100644 --- a/call.js +++ b/call.js @@ -1,3 +1,30 @@ -// call.js import * as dotenv from "dotenv"; dotenv.config(); + +import twilio from "twilio"; +import express from "express"; + +const accountSid = process.env.TWILIO_ACCOUNT_SID; +const authToken = process.env.TWILIO_AUTH_TOKEN; +const phone_number = process.env.TWILIO_PHONE_NUMBER; + +const client = new twilio.Twilio(accountSid, authToken); +const app = express(); + +app.post("/voice", (request, response) => { + console.log("got call!"); + const voiceResponse = new twilio.twiml.VoiceResponse(); + voiceResponse.say({ voice: "alice" }, "hello world!"); + + // Render the response as XML in reply to the webhook request + response.type("text/xml"); + response.send(twiml.toString()); +}); + +// Create an HTTP server and listen for requests on port 3000 +app.listen(3000, () => { + console.log( + "Now listening on port 3000. " + + "Be sure to restart when you make code changes!" + ); +});