-
Notifications
You must be signed in to change notification settings - Fork 2
/
make-call.js
35 lines (29 loc) · 957 Bytes
/
make-call.js
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
require('dotenv').config({ path: __dirname + '/../.env' })
const TO_NUMBER = process.env.TO_NUMBER
const NEXMO_NUMBER = process.env.NEXMO_NUMBER
const NEXMO_API_KEY = process.env.NEXMO_API_KEY
const NEXMO_API_SECRET = process.env.NEXMO_API_SECRET
const NEXMO_APPLICATION_ID = process.env.NEXMO_APPLICATION_ID
const NEXMO_APPLICATION_PRIVATE_KEY_PATH = __dirname + "/../" + process.env.NEXMO_APPLICATION_PRIVATE_KEY_PATH
const Nexmo = require('nexmo')
const nexmo = new Nexmo({
apiKey: NEXMO_API_KEY,
apiSecret: NEXMO_API_SECRET,
applicationId: NEXMO_APPLICATION_ID,
privateKey: NEXMO_APPLICATION_PRIVATE_KEY_PATH
})
const ANSWER_URL = 'https://developer.nexmo.com/ncco/tts.json'
nexmo.calls.create({
to: [{
type: 'phone',
number: TO_NUMBER
}],
from: {
type: 'phone',
number: NEXMO_NUMBER
},
answer_url: [ANSWER_URL]
}, (error, response) => {
if (error) console.error(error)
if (response) console.log(response)
})