pluginservice/plugin/index.js
Daniel Brahneborg b4d27098ec some docs
2019-08-12 20:25:03 +02:00

55 lines
1.7 KiB
JavaScript

const express = require('express')
const router = express.Router()
// The following endpoints are supported.
//
// /before_receive
// /route
// /before_route (only for PROTOCOL=ROUTE connectors)
// /before_send
// /after_send
// /before_dlr (gets dlrinfo)
// /after_dlr
// The req.body contains the following fields.
//
// ccarg - from PLUGIN=pluginname:ccarg of the current connector
// qe - message or delivery report, with field names in uppercase
// result - for after_send and after_dlr
// dlrinfo - custom options for incoming delivery reports
// route - as returned by the previously called plugin
// Output is a list of key=value entries, one per line.
// The key can be as follows.
//
// result - for before_receive, where non-zero means the message will be rejected
// route - the name of the outgoing connector, used for /route
// qe.OPTION_NAME - new value for a message option called "OPTION_NAME"
// dlrinfo.OPTION_NAME - for before_dlr, to return HLR lookup results:
// - OPTION_NAME can be mnc, mcc, msc, and imsi
router.post('/before_receive', (req, res) => {
console.log('in before_receive') //, body:', req.body)
const qe = req.body.qe
let respbuf = ''
if (qe.DESTADDR === '911') respbuf = 'result = 8'
else respbuf = 'qe.SMPPOPTION=0x1400:414243\nqe.SMPPOPTION=0x1401:61626364'
res.send(respbuf)
})
router.post('/route', (req, res) => {
console.log('in route') //, qe:', req.body.qe)
const qe = req.body.qe
let respbuf = ''
if (qe.DESTADDR === '123')
respbuf = Buffer.from('route = out')
res.send(respbuf)
})
router.use((req, res, next) => {
console.log('nothing to do for %s %s', req.method, req.url)
res.status(404).end()
})
module.exports = router