-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-endpoints.js
63 lines (47 loc) · 1.5 KB
/
update-endpoints.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require('dotenv-safe').load()
const Nexmo = require('nexmo')
const privateKey = Buffer.from(process.env.PRIVATE_KEY)
const nexmo = new Nexmo({
apiKey: process.env.KEY,
apiSecret: process.env.SECRET,
applicationId: process.env.APP_ID,
privateKey: privateKey
})
const answer_url = process.env.PUBLIC_URL + '/answer/' + process.env.WEBHOOK_TOKEN
const event_url = process.env.PUBLIC_URL + '/event/' + process.env.WEBHOOK_TOKEN
const sms_url = process.env.PUBLIC_URL + '/sms/' + process.env.WEBHOOK_TOKEN
console.log(`Updating endpoints:
app: ${process.env.APP_ID}
answer url: ${answer_url}
event url: ${event_url}
sms url: ${sms_url} (takes longer)
`)
console.log('Setting app answer/event urls...')
nexmo.applications
.update(
process.env.APP_ID,
'Nexmoji (auto updated)',
'voice',
answer_url, event_url,
{},
(err) => {
if(err) throw err
console.log('...Done')
console.log('Looking up number...')
nexmo.numberInsight.get(
{level: 'standard', number: process.env.NUMBER},
(err, result) => {
if(err) throw err
console.log('...Done')
console.log('Updating sms endpoint...')
nexmo.number.update(
result.country_code,
result.international_format_number, {
moHttpUrl: sms_url
}, (err, result) => {
if(err) throw err
console.log(`...Done (${result['error-code-label']})`)
})
}
)
})