mirror of
https://github.com/vitalityAI/therapist.git
synced 2025-04-16 17:40:16 -04:00
feat: added gathering to twilio calling api
This commit is contained in:
parent
977c10c866
commit
73688270cd
42
call.js
42
call.js
|
@ -9,18 +9,54 @@ const authToken = process.env.TWILIO_AUTH_TOKEN;
|
||||||
const phone_number = process.env.TWILIO_PHONE_NUMBER;
|
const phone_number = process.env.TWILIO_PHONE_NUMBER;
|
||||||
|
|
||||||
const client = new twilio.Twilio(accountSid, authToken);
|
const client = new twilio.Twilio(accountSid, authToken);
|
||||||
|
const VoiceResponse = twilio.twiml.VoiceResponse;
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
app.use(express.urlencoded({ extended: false }));
|
||||||
|
|
||||||
app.post("/voice", (request, response) => {
|
app.post("/voice", (request, response) => {
|
||||||
console.log("got call!");
|
const city = request.body.FromCity;
|
||||||
const voiceResponse = new twilio.twiml.VoiceResponse();
|
console.log(`They're from ${city}!`);
|
||||||
voiceResponse.say({ voice: "alice" }, "hello world!");
|
|
||||||
|
// Use the Twilio Node.js SDK to build an XML response
|
||||||
|
const twiml = new VoiceResponse();
|
||||||
|
twiml.say({ voice: "alice" }, `Never gonna give you up ${city}.`);
|
||||||
|
twiml.play({}, "https://demo.twilio.com/docs/classic.mp3");
|
||||||
|
|
||||||
// Render the response as XML in reply to the webhook request
|
// Render the response as XML in reply to the webhook request
|
||||||
response.type("text/xml");
|
response.type("text/xml");
|
||||||
response.send(twiml.toString());
|
response.send(twiml.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post("/call", (req, res) => {
|
||||||
|
// Use the Twilio Node.js SDK to build an XML response
|
||||||
|
const twiml = new VoiceResponse();
|
||||||
|
|
||||||
|
// Use <Record> to record and transcribe the caller's message
|
||||||
|
const gather = twiml.gather({
|
||||||
|
action: "https://eowj0ew8hq7190e.m.pipedream.net/respond",
|
||||||
|
method: "POST",
|
||||||
|
input: "speech",
|
||||||
|
language: "en-US",
|
||||||
|
speechTimeout: "auto",
|
||||||
|
});
|
||||||
|
|
||||||
|
gather.say("Tell us what makes you sad.");
|
||||||
|
|
||||||
|
twiml.redirect("/call");
|
||||||
|
|
||||||
|
res.type("text/xml");
|
||||||
|
res.send(twiml.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post("/respond", (req, res) => {
|
||||||
|
let transcription = req.body.TranscriptionText;
|
||||||
|
console.log(transcription);
|
||||||
|
|
||||||
|
const twiml = new VoiceResponse();
|
||||||
|
twiml.say(`You said, {$transcription}`);
|
||||||
|
});
|
||||||
|
|
||||||
// Create an HTTP server and listen for requests on port 3000
|
// Create an HTTP server and listen for requests on port 3000
|
||||||
app.listen(3000, () => {
|
app.listen(3000, () => {
|
||||||
console.log(
|
console.log(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user