diff --git a/config.json b/config.json index 6138dcd..f6f05d0 100644 --- a/config.json +++ b/config.json @@ -6,23 +6,7 @@ "deliveryModes": [ { "name": "Normal", - "params": { - "type": "duplex", - "routing": { - "device": "birdyslim", - "connectors": [ - [ - "em-p-twoways", - "1234567" - ], - [ - "pocsag", - "424242" - ] - ] - } - }, - "_id": "" + "preset": "" } ] } \ No newline at end of file diff --git a/html/index.html b/html/index.html index 9b4d15e..9b6ae21 100644 --- a/html/index.html +++ b/html/index.html @@ -15,6 +15,7 @@ Telegram Bot Configuration + Store & Restart @@ -34,7 +35,7 @@

Targets:

- Add + Add
Index: {{ index }}
@@ -43,35 +44,18 @@ + - - - - - - - - - - Delivery Targets: - Add - - - - - - - - - mdi-delete - - - - - -
- - Store & Restart @@ -82,10 +66,6 @@ - - - Store & Restart - @@ -106,42 +86,32 @@ return { EXPERTMODE: false, configTab: null, - pagerTypes: [ - {k: 'Simple', v: 'simple'}, - {k: 'Duplex', v: 'duplex'}, - ], - deviceType: [ - {k: 'Generic', v: 'generic'}, - {k: 'Birdy Slim (IoT)', v: 'birdyslim'}, - ], - connectorTypes: [ - {k: 'Dummy', v: 'dummy'}, - {k: 'POCSAG GW', v: 'pocsag'}, - {k: 'DAPNET', v: 'dapnet'}, - - {k: 'e*Cityruf inetgw', v: 'ecityruf'}, - {k: 'e*Cityruf Puppeteer', v: 'em-p-cityruf'}, - {k: 'e*Cityruf alertManager', v: 'em-a-cityruf'}, - - {k: 'e*2wayS Puppeteer', v: 'em-p-twoways'}, - {k: 'e*2wayS alertManager', v: 'em-a-twoways'}, - - {k: 'LoRaWAN TTNv3', v: 'lorawan'}, - ], configData: { - "bottoken": "", + "bottoken": "", "pager": { "url": "", }, "menuSupport": false, "deliveryModes": [] }, + presetSearchItems: [], } }, created() { + this.loadPresets() this.loadConfig() }, methods: { + loadPresets() { + this.$http.get('/api/deliveryPresets') + .then(response => { + this.presetSearchItems = response.body.map(x => { return { + text: x.name, + value: x.key, + }}) + }, response => { + }) + }, loadConfig() { this.$http.get('/config').then(response => { const newConfig = response.body @@ -155,6 +125,10 @@ }, storeConfig() { const storeConfig = JSON.parse(JSON.stringify(this.configData)) + storeConfig.deliveryModes = storeConfig.deliveryModes.map((x) => { + delete x._id + return x + }) this.$http.post('/config', storeConfig).then(response => { }) .then(this.$http.post('/restart')) @@ -163,19 +137,10 @@ setTimeout(() => window.location.reload(), 1e3) }) }, - addDeliveryTarget(index) { - this.configData.deliveryModes[ index ].params.routing.connectors.push(["connectorName","connectorParam"]) - }, - addRegionCMD() { + addDeliveryMode() { this.configData.deliveryModes.push({ name: "", - params: { - "type": "simple", - "routing": { - "device": "generic", - "connectors": [] - } - }, + preset: null }) }, } diff --git a/index.js b/index.js index 6539b66..c261be8 100644 --- a/index.js +++ b/index.js @@ -15,8 +15,12 @@ function filter(txt) { return txt.replace(/[^\x00-\x7F]/g, "") } + function editStatus(msgId, msg) { if (!assoc[msgId]) return + const sPass = Math.floor( (new Date().valueOf() - assoc[msgId].date.valueOf() ) / 1e3) + msg = `+${ sPass }s> ${ msg }` + console.log(assoc[msgId]) const [tgChatId, tgMsgId] = [assoc[msgId].tgchat, assoc[msgId].tgmsg] assoc[msgId].newText = assoc[msgId].newText + '\n' + msg @@ -57,8 +61,17 @@ for (let deliveryModeIndex in config.deliveryModes) { const origText = ctx.update.callback_query.message.text.substring(8+1) await ctx.answerCbQuery() await ctx.editMessageReplyMarkup(undefined) - let msgId = (await axios.post(config.pager.url, Object.assign({ ...config.deliveryModes[ deliveryModeIndex ].params }, { payload: origText }))).data + + const deliveryModeData = config.deliveryModes[ deliveryModeIndex ] + + let msgId = ( + await axios.post(config.pager.url, Object.assign( !!deliveryModeData.preset + ? { ...deliveryModeData.params } // backward compatibility + : { preset: deliveryModeData.preset } + , { payload: origText })) + ).data assoc[msgId] = { + date: new Date(), tgmsg: ctx.update.callback_query.message.message_id, text: origText, newText: `Preview: ${ origText }\n\n--[${ msgId }]--\n`, @@ -85,6 +98,10 @@ appConfig.use(express.static(__dirname + '/node_modules/@mdi/font')) appConfig.get('/config', async (req, res) => { return res.json(JSON.parse(fs.readFileSync('config.json'))) }) +appConfig.get('/api/deliveryPresets', async (req, res) => { + const presets = await axios.get(new URL(config.pager.url).origin + '/api/deliveryPresets') + return res.json(presets.data) +}) appConfig.post('/config', async (req, res) => { if (!(!!req.body.bottoken)) return res.status(403).json(false) if (!(!!req.body.pager)) return res.status(403).json(false)