mirror of
https://github.com/donl/plivo-node.git
synced 2026-05-25 22:07:10 -06:00
Merge branch 'master' into mms_changes
This commit is contained in:
commit
a7c2fe4433
12 changed files with 528 additions and 41 deletions
|
|
@ -1,5 +1,14 @@
|
|||
# Change Log
|
||||
|
||||
## [4.1.6](https://github.com/plivo/plivo-node/releases/tag/v4.1.6)(2019-11-14)
|
||||
- Fix list APIs to return meta in response.
|
||||
|
||||
## [4.1.5](https://github.com/plivo/plivo-node/releases/tag/v4.1.5)(2019-11-13)
|
||||
- Add GetInput XML support
|
||||
|
||||
## [4.1.4](https://github.com/plivo/plivo-node/releases/tag/v4.1.4)(2019-11-06)
|
||||
- Add SSML support
|
||||
|
||||
## [4.1.3](https://github.com/plivo/plivo-node/releases/tag/v4.1.3)(2019-07-30)
|
||||
- Add proxy-support for Signature Validation
|
||||
- Add HTTP status codes in responses
|
||||
|
|
|
|||
7
Jenkinsfile
vendored
Normal file
7
Jenkinsfile
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#!groovy
|
||||
|
||||
@Library('plivo_standard_libs@sdks') _
|
||||
|
||||
sdksPipeline ([
|
||||
buildContainer: 'plivo/jenkins-ci/node-sdk:latest'
|
||||
])
|
||||
7
ci/config.yml
Normal file
7
ci/config.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
parent: central
|
||||
serviceName: plivo-node
|
||||
language: node-sdk
|
||||
build:
|
||||
command: |
|
||||
npm install
|
||||
59
examples/speak.js
Normal file
59
examples/speak.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
var Plivo = require('../dist/rest/client.js');
|
||||
var response = new Plivo.Response();
|
||||
|
||||
const speak = response.addSpeak('hello', {
|
||||
voice: "Polly.Aditi",
|
||||
language: 'en-IN',
|
||||
});
|
||||
|
||||
speak.addLang('आप लोग कैसे हो', {
|
||||
'xml:lang': 'hi-IN',
|
||||
});
|
||||
|
||||
const emphasis = speak.addEmphasis('emphasis', {
|
||||
'level': 'x-strong',
|
||||
})
|
||||
emphasis.addBreak();
|
||||
emphasis.addLang('language!!!');
|
||||
|
||||
// Mixed-content without tag
|
||||
speak.addText('extra text');
|
||||
|
||||
speak.addLang('how are you people?', {
|
||||
'xml:lang': 'en-IN',
|
||||
});
|
||||
|
||||
speak.addSayAs('30101996', {
|
||||
'interpret-as': 'date',
|
||||
'format': 'dmy'
|
||||
});
|
||||
|
||||
speak.addLang('well well well').addBreak();
|
||||
|
||||
speak.addLang('no no no');
|
||||
|
||||
speak.addProsody('कैसे हो');
|
||||
|
||||
speak.addSayAs('S A Y A S', {
|
||||
'interpret-as': 'characters',
|
||||
});
|
||||
|
||||
speak.addP('this is p tag');
|
||||
|
||||
speak.addPhoneme('this is Phoneme', {
|
||||
'alphabet': 'ipa',
|
||||
});
|
||||
|
||||
speak.addS('this is s tag');
|
||||
|
||||
speak.addSub('Hg', {
|
||||
alias: 'Mercury',
|
||||
});
|
||||
|
||||
speak.addText('Past of read is')
|
||||
|
||||
speak.addW('read', {
|
||||
'role': 'amazon:VBD',
|
||||
});
|
||||
|
||||
console.log(response.toXML());
|
||||
|
|
@ -113,7 +113,7 @@ export class PlivoResourceInterface {
|
|||
client('GET', action, params)
|
||||
.then(response => {
|
||||
let objects = [];
|
||||
Object.defineProperty(objects, 'meta', { value: response.body.meta });
|
||||
Object.defineProperty(objects, 'meta', { value: response.body.meta, enumerable: true });
|
||||
response.body.objects.forEach(item => {
|
||||
objects.push(new Klass(client, item));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import _snakeCase from 'lodash/snakeCase';
|
|||
import _mapKeys from 'lodash/mapKeys';
|
||||
import _mapValues from 'lodash/mapValues';
|
||||
import _map from 'lodash/map';
|
||||
import { parseString } from 'xml2js';
|
||||
|
||||
function recursivelyRenameObject(object, renameFunc) {
|
||||
if (!(object instanceof Object)) {
|
||||
|
|
@ -54,3 +55,20 @@ export function camelCaseRequestWrapper(requestFunc) {
|
|||
}
|
||||
}
|
||||
|
||||
export function validateSpeakAttributes(content, voice) {
|
||||
|
||||
if (!voice || ['MAN', 'WOMAN'].indexOf(voice) != -1) {
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
var voiceParts = voice.split('.');
|
||||
if (voiceParts.length != 2 || voiceParts[0] != 'Polly') {
|
||||
return {
|
||||
success: false, msg: "Invalid voice " + voice + '.'
|
||||
};
|
||||
};
|
||||
return {
|
||||
success: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
export class PlivoRestError extends Error {}
|
||||
export class ResourceNotFoundError extends PlivoRestError {}
|
||||
export class ServerError extends PlivoRestError {}
|
||||
export class InvalidRequestError extends PlivoRestError {}
|
||||
export class PlivoXMLError extends PlivoRestError {}
|
||||
export class AuthenticationError extends PlivoRestError {}
|
||||
export class PlivoRestError extends Error { }
|
||||
export class ResourceNotFoundError extends PlivoRestError { }
|
||||
export class ServerError extends PlivoRestError { }
|
||||
export class InvalidRequestError extends PlivoRestError { }
|
||||
export class PlivoXMLError extends PlivoRestError { }
|
||||
export class PlivoXMLValidationError extends PlivoRestError { }
|
||||
export class AuthenticationError extends PlivoRestError { }
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
16
package-lock.json
generated
16
package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "plivo",
|
||||
"version": "4.0.5",
|
||||
"version": "4.1.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
@ -4669,6 +4669,11 @@
|
|||
"integrity": "sha512-1HwIYD/8UlOtFS3QO3w7ey+SdSDFE4HRNLZoZRYVQefrOY3l17epswImeB1ijgJFQJodIaHcwkp3r/myBjFVbg==",
|
||||
"dev": true
|
||||
},
|
||||
"sax": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
||||
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
|
||||
},
|
||||
"semver": {
|
||||
"version": "4.3.6",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz",
|
||||
|
|
@ -5565,6 +5570,15 @@
|
|||
"mkdirp": "^0.5.1"
|
||||
}
|
||||
},
|
||||
"xml2js": {
|
||||
"version": "0.4.19",
|
||||
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
|
||||
"integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
|
||||
"requires": {
|
||||
"sax": ">=0.6.0",
|
||||
"xmlbuilder": "~9.0.1"
|
||||
}
|
||||
},
|
||||
"xmlbuilder": {
|
||||
"version": "9.0.7",
|
||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "plivo",
|
||||
"version": "4.1.3",
|
||||
"version": "4.1.6",
|
||||
"description": "A Node.js SDK to make voice calls and send SMS using Plivo and to generate Plivo XML",
|
||||
"homepage": "https://github.com/plivo/plivo-node",
|
||||
"files": [
|
||||
|
|
@ -64,6 +64,7 @@
|
|||
"request": "^2.81.0",
|
||||
"uri-parser": "^1.0.0",
|
||||
"utf8": "^2.1.2",
|
||||
"xml2js": "^0.4.19",
|
||||
"xmlbuilder": "^9.0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
97
test/ssml.js
Normal file
97
test/ssml.js
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
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 - Invalid SSML XML Structure', function (done) {
|
||||
|
||||
let response = new Response();
|
||||
|
||||
// Invalid speak body
|
||||
let speak_body = ' Here is a number <w role="amazon: VBD">read</w> \
|
||||
as a cardinal number: \
|
||||
<say-as interpret-as="cardinal"><wa role="amazon: VBD"><cr>read</wa></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(new Error("Invalid xml should be rejected and should throw error."));
|
||||
}).catch((err) => {
|
||||
assert.equal('Invalid SSML xml structure. Content must be a valid xml.', err.message);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Ssml - Invalid SSML Tags', function (done) {
|
||||
|
||||
let response = new Response();
|
||||
|
||||
// Invalid speak body
|
||||
let speak_body = ' Here is a number <w role="amazon: VBD">read</w> \
|
||||
as a cardinal number: \
|
||||
<say-as interpret-as="cardinal"><wa role="amazon: VBD"><cr>read</cr></wa></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(new Error("Invalid xml tags should be rejected and should throw error."));
|
||||
}).catch((err) => {
|
||||
assert.equal('Ssml tag <wa> is not supported.', err.message);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Ssml - Invalid Language Validation', function (done) {
|
||||
|
||||
let response = new Response();
|
||||
|
||||
// Invalid speak body
|
||||
let speak_body = ' Here is a number';
|
||||
|
||||
response.addSpeak(speak_body, { language: 'Spanish-Castilian1', voice: 'Polly.Conchita' }).then((result) => {
|
||||
done(new Error("Unsupported language `Spanish-Castilian1` should be rejected and should throw error."));
|
||||
}).catch((err) => {
|
||||
assert.equal('Invalid language. Language `Spanish-Castilian1` is not supported.', err.message);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Ssml - Invalid Language-Voice Combination', function (done) {
|
||||
|
||||
let response = new Response();
|
||||
|
||||
// Invalid speak body
|
||||
let speak_body = '<w>Here is a number</w>';
|
||||
|
||||
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Maxim' }).then((result) => {
|
||||
done(new Error("Invalid language voice combination should be rejected"));
|
||||
}).catch((err) => {
|
||||
assert.equal('<Speak> voice ‘Polly.Maxim’ is not valid. Refer <link> for list of supported voices.', err.message);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Ssml - Valid Language-Voice Combination', function (done) {
|
||||
|
||||
let response = new Response();
|
||||
|
||||
// Invalid speak body
|
||||
let speak_body = '<w>Here is a number</w>';
|
||||
|
||||
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Conchita' }).then((result) => {
|
||||
done();
|
||||
}).catch((err) => {
|
||||
done('Validate Language Voice combination should be accepted.');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
37
test/xml.js
37
test/xml.js
|
|
@ -1,27 +1,32 @@
|
|||
import assert from 'assert';
|
||||
import sinon from 'sinon';
|
||||
import {Response} from '../lib/utils/plivoxml';
|
||||
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');
|
||||
dial.addUser('sip:test@sip.plivo.com');
|
||||
response.addMessage('∫test', {
|
||||
src: '123',
|
||||
dst: '456',
|
||||
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',
|
||||
});
|
||||
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());
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue