-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-recording.js
More file actions
51 lines (45 loc) · 1.83 KB
/
create-recording.js
File metadata and controls
51 lines (45 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require('dotenv').config()
const express = require('express')
const bodyParser = require('body-parser')
const freeclimbSDK = require('@freeclimb/sdk')
const app = express()
app.use(bodyParser.json())
// Where your app is hosted ex. www.myapp.com
const host = process.env.HOST
const port = process.env.PORT || 80
// your freeclimb API key (available in the Dashboard) - be sure to set up environment variables to store these values
const accountId = process.env.ACCOUNT_ID
const apiKey = process.env.API_KEY
const freeclimb = freeclimbSDK(accountId, apiKey)
const applicationId = process.env.APPLICATION_ID
// Invoke create method to initiate the asynchronous outdial request
freeclimb.api.calls.create(to, from, applicationId).catch(err => {/* Handle Errors */ })
// Handles incoming calls. Set with 'Call Connect URL' in App Config
app.post('/incomingCall', (req, res) => {
// Create PerCL say script
const say = freeclimb.percl.say('Hello. Please leave a message after the beep, then press one or hangup.')
const options = {
playBeep: true,
finishOnKey: '1'
}
// Create PerCL record utterance script
const record = freeclimb.percl.recordUtterance(`${host}/finishedRecording`, options)
const percl = freeclimb.percl.build(say, record)
res.status(200).json(percl)
})
app.post('/finishedRecording', (req, res) => {
const recordingResponse = req.body
const say = freeclimb.percl.say('This is what you have recorded')
const play = freeclimb.percl.play(recordingResponse.recordingUrl)
const goodbye = freeclimb.percl.say('Goodbye')
const percl = freeclimb.percl.build(say, play)
res.status(200).json(percl)
})
// Specify this route with 'Status Callback URL' in App Config
app.post('/status', (req, res) => {
// handle status changes
res.status(200)
})
app.listen(port, () => {
console.log(`started the server on port ${port}`)
})