Skip to content

Instantly share code, notes, and snippets.

@vernig
Created December 23, 2020 16:10
Show Gist options
  • Save vernig/def168281d1f4f39578565d29a0171d3 to your computer and use it in GitHub Desktop.
Save vernig/def168281d1f4f39578565d29a0171d3 to your computer and use it in GitHub Desktop.
Twilio conference with AsyncAMD
const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client
.conferences('test-conference')
.participants.create({
from: '+447723487719',
to: 'client:worker_client',
waitUrl: 'https://my.website.com/dialtone.mp3', // Link to dialtone mp3
startConferenceOnEnter: true,
endConferenceOnExit: true,
})
.then((participant) => {
console.log('Conference created: ', participant.conferenceSid);
return client.calls
.create({
machineDetection: 'Enable',
machineDetectionTimeout: 10,
asyncAmd: 'true',
asyncAmdStatusCallback: `https://my.website.com/async-amd-webhook`, // Link to your webhook for AMD dection notification
url: `https://my.website.com/add-to-conference?sid=${participant.conferenceSid}`, // URL for TwmiML conference
to: 'xxxxx',
from: 'xxxxx',
})
})
.then((call) => {
console.log('Outobound Call placed: ', call.sid);
})
.catch((err) => console.log(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment