From 6d3fa96e04a054f8442849c41d78daf4cd20cb17 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Fri, 9 Oct 2020 08:02:33 -0400 Subject: [PATCH] add inbound and outbound messaging support --- lib/routes/api/accounts.js | 6 +++--- lib/routes/api/index.js | 5 +++-- lib/swagger/swagger.yaml | 14 ++++---------- package.json | 2 +- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/routes/api/accounts.js b/lib/routes/api/accounts.js index b52495e..2642062 100644 --- a/lib/routes/api/accounts.js +++ b/lib/routes/api/accounts.js @@ -5,6 +5,7 @@ const Account = require('../../models/account'); const Webhook = require('../../models/webhook'); const ApiKey = require('../../models/api-key'); const ServiceProvider = require('../../models/service-provider'); +const uuidv4 = require('uuid/v4'); const decorate = require('./decorate'); const snakeCase = require('../../utils/snake-case'); const sysError = require('./error'); @@ -153,9 +154,8 @@ async function validateCreateMessage(logger, sid, req) { } if (!obj.to) throw new DbErrorBadRequest('missing to property'); - //obj.to = typeof obj.to === 'string' ? [obj.to] : obj.to; - if (!obj.text && (!obj.media || 0 === obj.media.length)) { + if (!obj.text && !obj.media) { throw new DbErrorBadRequest('either text or media required in outbound message'); } } @@ -464,7 +464,7 @@ router.post('/:sid/Messages', async(req, res) => { const serviceUrl = `http://${ip}:3000/v1/createMessage/${sid}`; await validateCreateMessage(logger, sid, req); - const payload = req.body; + const payload = Object.assign({messageSid: uuidv4()}, req.body); logger.debug({payload}, `sending createMessage API request to to ${ip}`); updateLastUsed(logger, sid, req).catch((err) => {}); request({ diff --git a/lib/routes/api/index.js b/lib/routes/api/index.js index 639a003..2302e5b 100644 --- a/lib/routes/api/index.js +++ b/lib/routes/api/index.js @@ -20,7 +20,8 @@ api.use('/Sbcs', isAdminScope, require('./sbcs')); api.use('/Users', require('./users')); api.use('/login', require('./login')); -api.use('/messaging', require('./sms-inbound')); -api.use('/outboundSMS', require('./sms-outbound')); +// messaging +api.use('/messaging', require('./sms-inbound')); // inbound SMS from carrier +api.use('/outboundSMS', require('./sms-outbound')); // outbound SMS from feature server module.exports = api; diff --git a/lib/swagger/swagger.yaml b/lib/swagger/swagger.yaml index 10b22e7..71bbe38 100644 --- a/lib/swagger/swagger.yaml +++ b/lib/swagger/swagger.yaml @@ -1597,6 +1597,8 @@ paths: type: string format: uuid example: 2531329f-fb09-4ef7-887e-84e648214436 + providerResponse: + type: string 400: description: bad request components: @@ -1953,19 +1955,11 @@ components: from: type: string to: - type: array - items: - type: string - cc: - type: array - items: - type: string + type: string text: type: string media: - type: array - items: - type: string + type: string required: - from - to diff --git a/package.json b/package.json index 5efa5f9..dc81193 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "dependencies": { "@jambonz/db-helpers": "^0.5.1", "@jambonz/messaging-382com": "0.0.2", - "@jambonz/messaging-peerless": "0.0.6", + "@jambonz/messaging-peerless": "0.0.9", "@jambonz/messaging-simwood": "0.0.4", "@jambonz/realtimedb-helpers": "0.2.17", "cors": "^2.8.5",