diff --git a/lib/resources/messages.js b/lib/resources/messages.js index 4942ded..1b9665e 100644 --- a/lib/resources/messages.js +++ b/lib/resources/messages.js @@ -1,6 +1,6 @@ -import {extend, validate} from '../utils/common.js'; -import {PlivoResource, PlivoResourceInterface} from '../base'; +import { extend, validate } from '../utils/common.js'; +import { PlivoResource, PlivoResourceInterface } from '../base'; import * as _ from "lodash"; const action = 'Message/'; @@ -37,42 +37,42 @@ export class MessageInterface extends PlivoResourceInterface { extend(this, data); } -/** - * Send Message - * @method - * @param {string} src - source number - * @param {string} dst - destination number - * @param {string} text - text to send - * @param {object} optionalParams - Optional Params to send message - * @param {string} [optionalParams.type] - The type of message. Should be `sms` for a text message. Defaults to `sms`. - * @param {string} [optionalParams.url] The URL to which with the status of the message is sent. - * @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. - * @promise {object} return {@link PlivoGenericMessage} object if success - * @fail {Error} return Error - */ + /** + * Send Message + * @method + * @param {string} src - source number + * @param {string} dst - destination number + * @param {string} text - text to send + * @param {object} optionalParams - Optional Params to send message + * @param {string} [optionalParams.type] - The type of message. Should be `sms` for a text message. Defaults to `sms`. + * @param {string} [optionalParams.url] The URL to which with the status of the message is sent. + * @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. + * @promise {object} return {@link PlivoGenericMessage} object if success + * @fail {Error} return Error + */ send(src, dst, text, optionalParams) { return this.create(src, dst, text, optionalParams); } -/** - * Send Message - * @method - * @param {string} src - source number - * @param {string} dst - destination number - * @param {string} text - text to send - * @param {object} optionalParams - Optional Params to send message - * @param {string} [optionalParams.type] - The type of message. Should be `sms` for a text message. Defaults to `sms`. - * @param {string} [optionalParams.url] The URL to which with the status of the message is sent. - * @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. - * @promise {object} return {@link PlivoGenericMessage} object if success - * @fail {Error} return Error - */ + /** + * Send Message + * @method + * @param {string} src - source number + * @param {string} dst - destination number + * @param {string} text - text to send + * @param {object} optionalParams - Optional Params to send message + * @param {string} [optionalParams.type] - The type of message. Should be `sms` for a text message. Defaults to `sms`. + * @param {string} [optionalParams.url] The URL to which with the status of the message is sent. + * @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. + * @promise {object} return {@link PlivoGenericMessage} object if success + * @fail {Error} return Error + */ create(src, dst, text, optionalParams, powerpackUUID) { let errors = validate([ - {field: 'dst', value: dst, validators: ['isRequired']}, - {field: 'text', value: text, validators: ['isRequired']}, + { field: 'dst', value: dst, validators: ['isRequired'] }, + { field: 'text', value: text, validators: ['isRequired'] }, ]); if (errors) { @@ -81,14 +81,14 @@ export class MessageInterface extends PlivoResourceInterface { if (!src && !powerpackUUID) { let errorText = 'Neither of src or powerpack uuid present, either one is required' - return new Promise(function(resolve, reject) { + return new Promise(function (resolve, reject) { reject(new Error(errorText)); }); } if (src && powerpackUUID) { let errorText = 'Either of src or powerpack uuid, both of them are present' - return new Promise(function(resolve, reject) { + return new Promise(function (resolve, reject) { reject(new Error(errorText)); }) } @@ -102,20 +102,19 @@ export class MessageInterface extends PlivoResourceInterface { if (powerpackUUID) { params.powerpackUUID = powerpackUUID; } - console.log(params) return super.create(params); } -/** - * Get Message by given id - * @method - * @param {string} id - id of message - * @promise {object} return {@link Message} object if success - * @fail {Error} return Error - */ + /** + * Get Message by given id + * @method + * @param {string} id - id of message + * @promise {object} return {@link Message} object if success + * @fail {Error} return Error + */ get(id) { let errors = validate([ - {field: 'id', value: id, validators: ['isRequired']} + { field: 'id', value: id, validators: ['isRequired'] } ]); if (errors) {