Resolved issues.

This commit is contained in:
patelravi 2019-03-26 12:38:14 +05:30
parent 860a7aa1c2
commit 5e9d4076fc
6 changed files with 32 additions and 59 deletions

9
TODO
View file

@ -1,9 +0,0 @@
How to validate languages with voice
Male female voices for polly+voice combination
Promise, chain will break
Will childs be there in ssml for validation?
If Polly.* provided, is language validation required?

View file

@ -45,7 +45,7 @@ gulp.task('test', ['pre-test'], function (cb) {
console.log('Running tests with node version', process.version);
gulp.src('test/**/ssml.js')
gulp.src('test/**/*.js')
.pipe(plumber())
.pipe(mocha({ reporter: 'spec' }))
.on('error', function (err) {

View file

@ -59,11 +59,14 @@ export function validateVoiceForSsml(content, voice, language) {
return new Promise(function (resolve, reject) {
var voiceParts = voice.split('.');
if (['MAN', 'WOMAN'].indexOf(voice) != -1) {
if (!voice || ['MAN', 'WOMAN'].indexOf(voice) != -1) {
resolve({ success: true });
return;
} else if (voiceParts.length != 2 || voiceParts[0] != 'Polly') {
}
var voiceParts = voice.split('.');
if (voiceParts.length != 2 || voiceParts[0] != 'Polly') {
resolve({
success: false, msg: "Invalid voice " + voice + '.'
});

View file

@ -270,22 +270,18 @@ Response.prototype = {
}
body = newBody;
// If attributes not provided, use empty dictionary
if (!attributes) {
attributes = {};
}
// Validate voice first.
if (!attributes.voice) {
attributes.voice = 'WOMAN';
let voice = null, language = null;
if (attributes && attributes.voice) {
voice = attributes.voice;
}
if (!attributes.language) {
attributes.language = 'English';
if (attributes && attributes.language) {
language = attributes.language;
}
var item = this;
return new Promise(function (resolve, reject) {
plivoUtils.validateVoiceForSsml(body, attributes.voice, attributes.language).then(function (ssmlValidationResult) {
plivoUtils.validateVoiceForSsml(body, voice, language).then(function (ssmlValidationResult) {
// console.log('result...', ssmlValidationResult);
if (ssmlValidationResult.success == true) {
var result = item.add(new Speak(Response), body, attributes);

View file

@ -1,31 +1,10 @@
import assert from 'assert';
import { Response, Client } from '../lib/rest/client';
import { PlivoGenericResponse } from '../lib/base.js';
let client = new Client('sampleid', 'sammpletoken', 'sampleproxy');
describe('SsmlInterface', function () {
it('Ssml - Valid XML', function (done) {
let response = new Response();
// Valid speak body
let speak_body = ' Here is a number <w role="amazon: VBD">read</w> \
as a cardinal number: \
<say-as interpret-as="cardinal">klsdjflksjfsldk</say-as>. \
Here is a word spelled out: \
<say-as interpret-as="spell-out">hello</say-as>.';
// response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.*' });
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Conchita' }).then((result) => {
done();
}).catch((err) => {
done("Valid SSML xml should not be rejected.");
});
});
it('Ssml - Invalid SSML XML Structure', function (done) {
let response = new Response();

View file

@ -3,26 +3,30 @@ import sinon from 'sinon';
import { Response } from '../lib/utils/plivoxml';
describe('PlivoXML', function () {
it('should work', function () {
it('should work', function (done) {
const response = new Response();
response.addPreAnswer();
response.addRecord();
response.addHangup();
response.addSpeak('text');
response.addWait();
response.addDTMF('123');
response.addConference('test');
response.addRedirect('url');
response.addGetDigits();
response.addPlay('url');
const dial = response.addDial();
dial.addNumber('123');
response.addSpeak('text').then(function (result) {
response.addWait();
response.addDTMF('123');
response.addConference('test');
response.addRedirect('url');
response.addGetDigits();
response.addPlay('url');
const dial = response.addDial();
dial.addNumber('123');
dial.addUser('sip:test@sip.plivo.com');
response.addMessage('∫test', {
src: '123',
dst: '456',
dial.addUser('sip:test@sip.plivo.com');
response.addMessage('∫test', {
src: '123',
dst: '456',
});
assert.equal('<Response><PreAnswer/><Record/><Hangup/><Speak>text</Speak><Wait/><DTMF>123</DTMF><Conference>test</Conference><Redirect>url</Redirect><GetDigits/><Play>url</Play><Dial><Number>123</Number><User>sip:test@sip.plivo.com</User></Dial><Message src="123" dst="456">∫test</Message></Response>', response.toXML());
done();
}).catch(function (err) {
done("Failed to test Plivo Xml due to unknown error");
});
assert.equal('<Response><PreAnswer/><Record/><Hangup/><Speak>text</Speak><Wait/><DTMF>123</DTMF><Conference>test</Conference><Redirect>url</Redirect><GetDigits/><Play>url</Play><Dial><Number>123</Number><User>sip:test@sip.plivo.com</User></Dial><Message src="123" dst="456">∫test</Message></Response>', response.toXML());
});
});