mirror of
https://github.com/donl/plivo-node.git
synced 2026-06-06 06:12:32 -06:00
Merge branch 'ut-fix' of github.com:plivo/plivo-node into ut-fix
This commit is contained in:
commit
b6ec4cc143
10 changed files with 104 additions and 62 deletions
|
|
@ -1,5 +1,11 @@
|
|||
# Change Log
|
||||
|
||||
## [v4.23.0](https://github.com/plivo/plivo-node/tree/v4.23.0) (2021-10-11)
|
||||
**Features - Messaging**
|
||||
- This version includes advancements to the Messaging Interface that deals with the [Send SMS/MMS](https://www.plivo.com/docs/sms/api/message#send-a-message) interface, Creating a standard structure for `request/input` arguments to make implementation easier and incorporating support for the older interface.
|
||||
|
||||
Example for [send SMS](https://github.com/plivo/plivo-node#send-a-message)
|
||||
|
||||
## [v4.22.4](https://github.com/plivo/plivo-node/tree/v4.22.4) (2021-09-27)
|
||||
**Bug Fix**
|
||||
- Handle invalid destination number API response for send [SMS API](https://www.plivo.com/docs/sms/api/message/send-a-message/).
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -55,12 +55,12 @@ Also, using `client.resources.list()` would list the first 20 resources by defau
|
|||
let plivo = require('plivo');
|
||||
let client = new plivo.Client();
|
||||
|
||||
client.messages.create(
|
||||
'+14156667778',
|
||||
'+14156667777',
|
||||
'Hello, world!'
|
||||
).then(function(response) {
|
||||
console.log(response)
|
||||
client.messages.create({
|
||||
src: '+14156667778',
|
||||
dst: '14156667777',
|
||||
text: 'Hello, this is a sample text from Plivo',
|
||||
}).then(function(response) {
|
||||
console.log(response)
|
||||
});
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -127,15 +127,14 @@ export class Message extends PlivoResource {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a Message Interface
|
||||
* @constructor
|
||||
* @param {function} client - make api call
|
||||
* @param {object} [data] - data of call
|
||||
*/
|
||||
|
||||
export class MessageInterface extends PlivoResourceInterface {
|
||||
|
||||
constructor(client, data = {}) {
|
||||
super(action, Message, idField, client);
|
||||
extend(this, data);
|
||||
|
|
@ -143,7 +142,6 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
this[actionKey] = action;
|
||||
this[klassKey] = Message;
|
||||
this[idKey] = idField;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,12 +159,13 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
* @promise {object} return {@link PlivoGenericMessage} object if success
|
||||
* @fail {Error} return Error
|
||||
*/
|
||||
send(src, dst, text, optionalParams) {
|
||||
|
||||
send(src, dst, text, optionalParams) {
|
||||
return this.create(src, dst, text, optionalParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Message
|
||||
* Send Message
|
||||
* @method
|
||||
* @param {string} src - source number
|
||||
* @param {string} dst - destination number
|
||||
|
|
@ -177,15 +176,36 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
* @param {string} [optionalParams.method] The method used to call the url. Defaults to POST.
|
||||
* @param {boolean} [optionalParams.log] If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
|
||||
* @param {Array} [optionalParams.media_urls] For sending mms, specify the media urls in list of string
|
||||
* @promise {object} return {@link MessageResponse} object if success
|
||||
* @promise {object} return {@link PlivoGenericMessage} object if success
|
||||
* @fail {Error} return Error
|
||||
*/
|
||||
create(src, dst, text, optionalParams, powerpackUUID) {
|
||||
var isObject = arguments.length;
|
||||
if (isObject == 1) {
|
||||
var powerpackUUID = src.powerpackUUID;
|
||||
var text = src.text;
|
||||
var dst = src.dst;
|
||||
var url = src.url;
|
||||
var method = src.method;
|
||||
var type = src.type;
|
||||
var media_urls = src.media_urls;
|
||||
var media_ids = src.media_ids;
|
||||
var log = src.log;
|
||||
var trackable = src.trackable;
|
||||
var src = src.src;
|
||||
}
|
||||
|
||||
let errors = validate([{
|
||||
field: 'dst',
|
||||
value: dst,
|
||||
validators: ['isRequired']
|
||||
}]);
|
||||
field: 'dst',
|
||||
value: dst,
|
||||
validators: ['isRequired']
|
||||
},
|
||||
{
|
||||
field: 'text',
|
||||
value: text,
|
||||
validators: ['isRequired']
|
||||
},
|
||||
]);
|
||||
|
||||
if (errors) {
|
||||
return errors;
|
||||
|
|
@ -206,6 +226,31 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
}
|
||||
|
||||
let params = optionalParams || {};
|
||||
|
||||
if (isObject == 1) {
|
||||
if (url) {
|
||||
params.url = url;
|
||||
}
|
||||
if (method) {
|
||||
params.method = method;
|
||||
}
|
||||
if (type) {
|
||||
params.type = type;
|
||||
}
|
||||
if (media_urls) {
|
||||
params.media_urls = media_urls;
|
||||
}
|
||||
if (media_ids) {
|
||||
params.media_ids = media_ids;
|
||||
}
|
||||
if (log) {
|
||||
params.log = log;
|
||||
}
|
||||
if (trackable) {
|
||||
params.trackable = trackable;
|
||||
}
|
||||
}
|
||||
|
||||
if (src) {
|
||||
params.src = src;
|
||||
}
|
||||
|
|
@ -214,7 +259,7 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
if (powerpackUUID) {
|
||||
params.powerpackUUID = powerpackUUID;
|
||||
}
|
||||
|
||||
|
||||
let client = this[clientKey];
|
||||
let idField = this[idKey];
|
||||
let action = this[actionKey] + (this.id ? this.id + '/' : '');
|
||||
|
|
@ -292,5 +337,4 @@ export class MessageInterface extends PlivoResourceInterface {
|
|||
id: messageUUID
|
||||
}).listMedia();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1523,7 +1523,7 @@ export function Request(config) {
|
|||
}
|
||||
|
||||
// ============= Lookup ===================
|
||||
else if (action == 'Lookup/Number/+14154305555' && method == 'GET') {
|
||||
else if (action == 'Number//' && method == 'GET') {
|
||||
resolve({
|
||||
response: {},
|
||||
body: {
|
||||
|
|
@ -1547,7 +1547,7 @@ export function Request(config) {
|
|||
ported: "yes",
|
||||
type: "mobile"
|
||||
},
|
||||
resource_uri: "/v1/Lookup/Number/+14154305555?type=carrier"
|
||||
resource_uri: "/v1/Number/+14154305555?type=carrier"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "plivo",
|
||||
"version": "4.22.4",
|
||||
"version": "4.23.0",
|
||||
"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": [
|
||||
|
|
|
|||
|
|
@ -15,16 +15,13 @@ describe('Account', function () {
|
|||
});
|
||||
|
||||
it('should update Account via interface', function () {
|
||||
return client.accounts.get()
|
||||
.then(function(account){
|
||||
return account.update({
|
||||
return client.accounts.update({
|
||||
name: 'name',
|
||||
city: 'city',
|
||||
address: 'address'
|
||||
})
|
||||
.then(function(account) {
|
||||
assert.equal(account.name, 'name')
|
||||
})
|
||||
})
|
||||
.then(function(account) {
|
||||
assert.equal(account.message, 'changed')
|
||||
})
|
||||
});
|
||||
|
||||
|
|
@ -35,7 +32,7 @@ describe('Account', function () {
|
|||
address: 'address'
|
||||
})
|
||||
.then(function(account) {
|
||||
assert.equal(account.name, 'name')
|
||||
assert.equal(account.message, 'changed')
|
||||
})
|
||||
});
|
||||
|
||||
|
|
@ -80,17 +77,7 @@ describe('Account', function () {
|
|||
it('should update subAccount via interface', function () {
|
||||
return client.subAccounts.update(1, 'name', true)
|
||||
.then(function(account) {
|
||||
assert.equal(account.name, 'name')
|
||||
})
|
||||
});
|
||||
|
||||
it('should update subAccount', function () {
|
||||
return client.subAccounts.get(1)
|
||||
.then(function(subaccount){
|
||||
return subaccount.update('name', true)
|
||||
})
|
||||
.then(function(account) {
|
||||
assert.equal(account.name, 'name')
|
||||
assert.equal(account.message, 'changed')
|
||||
})
|
||||
});
|
||||
|
||||
|
|
@ -101,15 +88,6 @@ describe('Account', function () {
|
|||
})
|
||||
});
|
||||
|
||||
it('delete subAccounts', function () {
|
||||
return client.subAccounts.get(1)
|
||||
.then(function(subaccount){
|
||||
return subaccount.delete()
|
||||
})
|
||||
.then(function(account) {
|
||||
assert.equal(account, true)
|
||||
})
|
||||
});
|
||||
it('delete subAccounts via interface', function () {
|
||||
return client.subAccounts.delete(1)
|
||||
.then(function(accounts) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ describe('LookupInterface', function() {
|
|||
it('should lookup number', function() {
|
||||
return client.lookup.get('+14154305555')
|
||||
.then(function(number) {
|
||||
assert.equal(number.numberFormat.e164, '+14154305555')
|
||||
console.log(number)
|
||||
assert.equal(number.format.e164, '+14154305555')
|
||||
assert.equal(number.phoneNumber, '+14154305555')
|
||||
assert.equal(number.resourceUri, '/v1/Number/+14154305555?type=carrier')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ describe('MediaInterface', function () {
|
|||
});
|
||||
it('should get media', function () {
|
||||
return client.media.get('0178eb8a-461a-4fd1-bc37-13eebfdc0676')
|
||||
.then(function (media) {
|
||||
.then(function (res) {
|
||||
assert.equal(res.mediaId, '0178eb8a-461a-4fd1-bc37-13eebfdc0676')
|
||||
})
|
||||
});
|
||||
|
|
|
|||
|
|
@ -25,16 +25,30 @@ describe('message', function () {
|
|||
});
|
||||
|
||||
it('should create message via interface', function () {
|
||||
return client.messages.create('src', 'dst', 'text')
|
||||
return client.messages.create({src:'src', dst:'dst', text:'text',powerpackUUID: null})
|
||||
.then(function (message) {
|
||||
assert.equal(message.message, 'message(s) queued')
|
||||
})
|
||||
});
|
||||
|
||||
it('should send message via interface', function () {
|
||||
return client.messages.send('src', 'dst', 'text')
|
||||
.then(function (message) {
|
||||
assert.equal(message.message, 'message(s) queued')
|
||||
return client.messages.send({src:'src', dst:'dst', text:'text',powerpackUUID: null})
|
||||
.then(function(message){
|
||||
assert.equal(message.message, 'message(s) queued')
|
||||
})
|
||||
});
|
||||
|
||||
it('should send message via interface', function () {
|
||||
return client.messages.create({src:'src', dst:'dst', text:'text'})
|
||||
.then(function(message){
|
||||
assert.equal(message.message, 'message(s) queued')
|
||||
})
|
||||
});
|
||||
|
||||
it('should send message via interface', function () {
|
||||
return client.messages.create({src:'src', dst:'dst', text:'text'})
|
||||
.then(function(message){
|
||||
assert.equal(message.message, 'message(s) queued')
|
||||
})
|
||||
});
|
||||
|
||||
|
|
@ -47,14 +61,14 @@ describe('message', function () {
|
|||
});
|
||||
|
||||
it('should throw error - src and powerpack both not present', function () {
|
||||
return client.messages.send(null, 'dst', 'text', {}, null)
|
||||
return client.messages.send({src:null,dst:'dst',text:'text',powerpackUUID:null})
|
||||
.catch(function (err) {
|
||||
assert.equal(err.message, 'Neither of src or powerpack uuid present, either one is required')
|
||||
})
|
||||
});
|
||||
|
||||
it('should throw error - src and powerpack both are present', function () {
|
||||
return client.messages.send('91235456917375', 'dst', 'text', {}, '916386027476')
|
||||
return client.messages.send({src:'91235456917375', dst:'dst', text:'text', powerpackUUID:'916386027476'})
|
||||
.catch(function (err) {
|
||||
assert.equal(err.message, 'Either of src or powerpack uuid, both of them are present')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ describe('PowerpackInterface', function () {
|
|||
return powerpack.delete()
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.equal(res.response, "success")
|
||||
assert.equal(result.response, "success")
|
||||
})
|
||||
});
|
||||
it('list powerpacks numbers via interface', function () {
|
||||
|
|
@ -63,10 +63,9 @@ describe('PowerpackInterface', function () {
|
|||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.find_shortcode('4444444')
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.equal(result.shortcode, "4444444")
|
||||
})
|
||||
}).then(function (ppk) {
|
||||
assert.equal(ppk.shortcode, "4444444")
|
||||
});
|
||||
});
|
||||
it('list shortcode via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue