-
-
Save DanyF-github/bbe80ce4a474e8c9630a0ac7aafde23f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get environment variables | |
const YOUR_VONAGE_NUMBER = process.env.YOUR_VONAGE_NUMBER; | |
const YOUR_PHONE_NUMBER = process.env.YOUR_PHONE_NUMBER; | |
exports.helloWorld = (req, res) => { | |
// Check if there's DTMF payload in the request body | |
if (req.body.dtmf) { | |
// (2.2) Connect call to the number in the DTMF payload | |
res.json([{ | |
action: 'talk', | |
text: 'Connecting' | |
}, | |
{ | |
action: 'connect', | |
from: YOUR_VONAGE_NUMBER, | |
endpoint: [{ | |
type: 'phone', | |
number: req.body.dtmf.digits | |
}] | |
} | |
]) | |
} else { | |
// Check if you're the caller | |
if (req.query.from === YOUR_PHONE_NUMBER) { | |
// (2.1) Capture destination number via DTMF input | |
res.json([{ | |
action: 'talk', | |
text: 'Please enter a phone number in international format, omitting the leading plus sign. End with the pound key.' | |
}, | |
{ | |
action: 'input', | |
type: ['dtmf'], | |
dtmf: { | |
timeOut: 10, | |
maxDigits: 15, | |
submitOnHash: true | |
}, | |
eventUrl: ["https://europe-west2-my-proxy-calling-project.cloudfunctions.net/proxy-call"] | |
} | |
]) | |
} else { | |
// (1) Connect caller to your phone number | |
res.json([{ | |
action: 'talk', | |
text: 'Please wait while we connect you' | |
}, | |
{ | |
action: 'connect', | |
from: YOUR_VONAGE_NUMBER, | |
endpoint: [{ | |
type: 'phone', | |
number: YOUR_PHONE_NUMBER | |
}] | |
} | |
]) | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment