NodeJS Bandwidth BXML
This package is a Bandwidth BXML builder written for NodeJS
Release Notes
Version | Notes |
---|
2.0.0 | Renamed toXml() to toBxml() |
2.1.0 | Added support for Record verb, and SSML in SpeakSentence |
2.2.0 | Added StartRecording, PauseRecording, ResumeRecording, and StopRecording verbs |
2.3.0 | Added support for transcriptions to Record and StartRecording verbs |
2.3.1 | Fixed startRecording init |
2.4.0 | Added transferDisconnectUrl and transferDisconnectMethod to PhoneNumber |
2.5.0 | Updated Pause (changed code comment to floats instead of ints), SendDtmf (added toneInterval and toneDuration attributes), and Record (added silenceTimeout attribute) verbs |
2.6.0 | Multiple nested verbs with Gather verb |
2.7.0 | Added Conference verb |
2.8.0 | Added Bridge verb |
2.9.0 | Added fallback urls and Ring verb |
Installing
npm install @bandwidth/bxml
Usage
Client Initialization
var BandwidthBxml = require("@bandwidth/bxml");
Hangup Response
var hangup = new BandwidthBxml.Verbs.Hangup();
var response = new BandwidthBxml.Response();
response.addVerb(hangup);
console.log(response.toBxml());
PlayAudio Response
var playAudio = new BandwidthBxml.Verbs.PlayAudio();
playAudio.setUrl("https:###test.com");
playAudio.setUsername("user");
playAudio.setPassword("pass");
var response = new BandwidthBxml.Response();
response.addVerb(playAudio);
console.log(response.toBxml());
SpeakSentence Response
var speakSentence = new BandwidthBxml.Verbs.SpeakSentence();
speakSentence.setSentence("test");
speakSentence.setVoice("susan");
speakSentence.setGender("female");
speakSentence.setLocale("en_US");
var response = new BandwidthBxml.Response();
response.addVerb(speakSentence);
console.log(response.toBxml());
SendDtmf Response
var sendDtmf = new BandwidthBxml.Verbs.SendDtmf();
sendDtmf.setDtmf("123");
var response = new BandwidthBxml.Response();
response.addVerb(sendDtmf);
console.log(response.toBxml());
Forward Response
var forward = new BandwidthBxml.Verbs.Forward();
forward.setTo("+18888888888");
forward.setFrom("+19999999999");
forward.setCallTimeout(3);
forward.setDiversionTreatment("none");
forward.setDiversionReason("away");
var response = new BandwidthBxml.Response();
response.addVerb(forward);
console.log(response.toBxml());
Pause Response
var pause = new BandwidthBxml.Verbs.Pause();
pause.setDuration(3);
var response = new BandwidthBxml.Response();
response.addVerb(pause);
console.log(response.toBxml());
Redirect Response
var redirect = new BandwidthBxml.Verbs.Redirect();
redirect.setUsername("user");
redirect.setPassword("pass");
redirect.setRedirectUrl("https:###test.com");
redirect.setRedirectMethod("GET");
redirect.setTag("tag");
var response = new BandwidthBxml.Response();
response.addVerb(redirect);
console.log(response.toBxml());
Gather Response with a nested SpeakSentence
var speakSentence = new BandwidthBxml.Verbs.SpeakSentence();
speakSentence.setSentence("test");
speakSentence.setVoice("susan");
speakSentence.setGender("female");
speakSentence.setLocale("en_US");
var gather = new BandwidthBxml.Verbs.Gather();
gather.setGatherUrl("https:###test.com");
gather.setGatherMethod("GET");
gather.setUsername("user");
gather.setPassword("pass");
gather.setTag("tag");
gather.setTerminatingDigits("123");
gather.setMaxDigits(3);
gather.setInterDigitTimeout(4);
gather.setFirstDigitTimeout(5);
gather.setSpeakSentence(speakSentence);
var response = new BandwidthBxml.Response();
response.addVerb(gather);
console.log(response.toBxml());
Gather Response with a nested PlayAudio
var playAudio = new BandwidthBxml.Verbs.PlayAudio();
playAudio.setUrl("https:###test.com");
playAudio.setUsername("user");
playAudio.setPassword("pass");
var gather = new BandwidthBxml.Verbs.Gather();
gather.setGatherUrl("https:###test.com");
gather.setGatherMethod("GET");
gather.setUsername("user");
gather.setPassword("pass");
gather.setTag("tag");
gather.setTerminatingDigits("123");
gather.setMaxDigits(3);
gather.setInterDigitTimeout(4);
gather.setFirstDigitTimeout(5);
gather.setPlayAudio(playAudio);
var response = new BandwidthBxml.Response();
response.addVerb(gather);
console.log(response.toBxml());
Gather Response with multiple nested verbs
var playAudio = new BandwidthBxml.Verbs.PlayAudio();
playAudio.setUrl("https:###test.com");
playAudio.setUsername("user");
playAudio.setPassword("pass");
var speakSentence = new BandwidthBxml.Verbs.SpeakSentence();
speakSentence.setSentence("test");
speakSentence.setVoice("susan");
speakSentence.setGender("female");
speakSentence.setLocale("en_US");
var gather = new BandwidthBxml.Verbs.Gather();
gather.setGatherUrl("https:###test.com");
gather.setGatherMethod("GET");
gather.setUsername("user");
gather.setPassword("pass");
gather.setTag("tag");
gather.setTerminatingDigits("123");
gather.setMaxDigits(3);
gather.setInterDigitTimeout(4);
gather.setFirstDigitTimeout(5);
gather.setPlayAudio(playAudio);
gather.setSpeakSentence(speakSentence);
var response = new BandwidthBxml.Response();
response.addVerb(gather);
console.log(response.toBxml());
Gather Response with no nested verbs
var gather = new BandwidthBxml.Verbs.Gather();
gather.setGatherUrl("https:###test.com");
gather.setGatherMethod("GET");
gather.setUsername("user");
gather.setPassword("pass");
gather.setTag("tag");
gather.setTerminatingDigits("123");
gather.setMaxDigits(3);
gather.setInterDigitTimeout(4);
gather.setFirstDigitTimeout(5);
gather.setRepeatCount(6);
var response = new BandwidthBxml.Response();
response.addVerb(gather);
console.log(response.toBxml());
Transfer Response
var number1 = new BandwidthBxml.Verbs.PhoneNumber();
number1.setNumber("+17777777777");
number1.setTransferAnswerUrl("https:###test.com");
number1.setTransferAnswerMethod("GET");
number1.setUsername("user");
number1.setPassword("pass");
number1.setTag("tag");
var number2 = new BandwidthBxml.Verbs.PhoneNumber();
number2.setNumber("+17777777779");
number2.setTransferAnswerUrl("https:###test2.com");
number2.setTransferAnswerMethod("POST");
number2.setUsername("user2");
number2.setPassword("pass2");
number2.setTag("tag2");
var transfer = new BandwidthBxml.Verbs.Transfer();
transfer.setTransferCallerId("+18888888888");
transfer.setCallTimeout(3);
transfer.setTag("tagTransfer");
transfer.setTransferCompleteUrl("https:###testtransfer.com");
transfer.setTransferCompleteMethod("GET");
transfer.setUsername("usertransfer");
transfer.setPassword("passtransfer");
transfer.setDiversionTreatment("none");
transfer.setDiversionReason("away");
transfer.addPhoneNumber(number1);
transfer.addPhoneNumber(number2);
var response = new BandwidthBxml.Response();
response.addVerb(transfer);
console.log(response.toBxml());
PlayAudio and SpeakSentence
var playAudio = new BandwidthBxml.Verbs.PlayAudio();
playAudio.setUrl("https:###test.com");
playAudio.setUsername("user");
playAudio.setPassword("pass");
var speakSentence = new BandwidthBxml.Verbs.SpeakSentence();
speakSentence.setSentence("test");
speakSentence.setVoice("susan");
speakSentence.setGender("female");
speakSentence.setLocale("en_US");
var response = new BandwidthBxml.Response();
response.addVerb(playAudio);
response.addVerb(speakSentence);
console.log(response.toBxml());
Record
var record = new BandwidthBxml.Verbs.Record();
record.setRecordCompleteUrl("https://url.com");
record.setRecordCompleteMethod("POST");
record.setRecordingAvailableUrl("https://url.com");
record.setRecordingAvailableMethod("POST");
record.setUsername("user");
record.setPassword("pass");
record.setTag("tag");
record.setTerminatingDigits("123");
record.setMaxDuration(3);
record.setFileFormat("wav");
record.setTranscribe(true);
record.setTranscriptionAvailableUrl("https://test.com");
record.setTranscriptionAvailableMethod("POST");
var response = new BandwidthBxml.Response();
response.addVerb(record);
console.log(response.toBxml());
StartRecording
var startRecording = new BandwidthBxml.Verbs.StartRecording();
startRecording.setRecordingAvailableUrl("https://url.com");
startRecording.setRecordingAvailableMethod("POST");
startRecording.setUsername("user");
startRecording.setPassword("pass");
startRecording.setTag("tag");
startRecording.setFileFormat("wav");
startRecording.setMultiChannel(false);
startRecording.setTranscribe(true);
startRecording.setTranscriptionAvailableUrl("https://test.com");
startRecording.setTranscriptionAvailableMethod("POST");
var response = new BandwidthBxml.Response();
response.addVerb(startRecording);
console.log(response.toBxml());
StopRecording
var stopRecording = new BandwidthBxml.Verbs.StopRecording();
var response = new BandwidthBxml.Response();
response.addVerb(stopRecording);
console.log(response.toBxml());
PauseRecording
var pauseRecording = new BandwidthBxml.Verbs.PauseRecording();
var response = new BandwidthBxml.Response();
response.addVerb(pauseRecording);
console.log(response.toBxml());
ResumeRecording
var resumeRecording = new BandwidthBxml.Verbs.ResumeRecording();
var response = new BandwidthBxml.Response();
response.addVerb(resumeRecording);
console.log(response.toBxml());
Conference
var conference = new BxmlBuilder.Verbs.Conference();
conference.setHold(true);
conference.setMute(true);
conference.setTag('tag1');
conference.setUsername('username');
conference.setPassword('pswd');
conference.setCallIdsToCoach('id1,id2');
conference.setConferenceEventMethod('POST');
conference.setConferenceEventUrl('https://example.com');
conference.setName('my-conference');
var response = new BxmlBuilder.Response();
response.addVerb(conference);
console.log(response.toBxml());
Bridge
var bridge = new BandwidthBxml.Verbs.Bridge();
bridge.setCallId("c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d");
bridge.setBridgeCompleteUrl("https://test.com");
bridge.setBridgeCompleteMethod("GET");
bridge.setBridgeTargetCompleteUrl("https://test2.com");
bridge.setBridgeTargetCompleteMethod("POST");
bridge.setUsername("user");
bridge.setPassword("pass");
bridge.setTag("custom tag");
var response = new BandwidthBxml.Response();
response.addVerb(bridge);
console.log(response.toBxml());
Running tests
Tests can be run by executing
npm test
The dependency for XSD validation (xsd-schema-validator
) requires the environment variable JAVA_HOME
to be set. More information can be found on that package's github page
BXML Documentation
Bandwidth's BXML documentation can be found on the Bandwidth Developer Docs BXML page