added config interface on port 5060 aswell as new connectorTypes

master
cheetah 2 years ago
parent fd752fed6f
commit 46b1f7bd43

@ -1,24 +1,28 @@
{ {
"bottoken": "<BOT_TOKEN>", "bottoken": "",
"pager": { "pager": {
"url": "http://127.0.0.1:3000/api/message/advanced", "url": "http://127.0.0.1:3000/api/message/advanced"
"paramsNormal": {
"type": "duplex",
"routing": {
"device": "birdyslim",
"connectors": [
[ "pocsag", "133708C" ]
]
}
}, },
"paramsPriority": { "deliveryModes": [
{
"name": "Normal",
"params": {
"type": "duplex", "type": "duplex",
"routing": { "routing": {
"device": "birdyslim", "device": "birdyslim",
"connectors": [ "connectors": [
[ "pocsag", "133708A" ] [
"em-p-twoways",
"1234567"
],
[
"pocsag",
"424242"
]
] ]
} }
},
"_id": ""
} }
} ]
} }

@ -0,0 +1,177 @@
<!DOCTYPE html>
<html>
<head>
<title>Telegram Bot Configuration</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
<div id="app">
<v-app>
<v-app-bar app>
<v-toolbar-title>
Telegram Bot Configuration
</v-toolbar-title>
</v-app-bar>
<v-content>
<v-form>
<v-tabs v-model="configTab" next-icon="mdi-arrow-right-bold-box-outline" prev-icon="mdi-arrow-left-bold-box-outline" show-arrows>
<v-tabs-slider></v-tabs-slider>
<v-tab key="botSettings">Bot Settings</v-tab>
<v-tab key="notificationConfig">Notification Configuration</v-tab>
</v-tabs>
<v-tabs-items v-model="configTab">
<v-tab-item key="botSettings">
<v-container>
<!-- <v-row>
<v-col cols="12" sm="12" md="12">
<v-checkbox label="Support Menus" v-model="configData.menuSupport"></v-checkbox>
</v-col>
</v-row> -->
<p>Targets:</p>
<v-row>
<v-btn color="success" @click="addRegionCMD()">Add</v-btn>
</v-row>
<v-row v-for="(deliveryMode, index) in configData.deliveryModes" :key="deliveryMode._id" style="border-bottom: 2px solid black;">
<pre>Index: {{ index }}</pre>
<v-col cols="12" sm="12" md="12">
<v-btn color="error" @click="configData.deliveryModes.splice(index, 1)" icon><v-icon>mdi-delete</v-icon></v-btn>
</v-col>
<v-col cols="6" sm="6" md="4">
<v-text-field v-model="deliveryMode.name" label="Name"></v-text-field>
</v-col>
<v-col>
<v-col cols="12" sm="12" md="6">
<v-select :items="pagerTypes" v-model="deliveryMode.params.type" item-text="k" item-value="v" label="Delivery Type"></v-select>
</v-col>
<v-row>
<v-col cols="12" sm="12" md="6">
<v-select :items="deviceType" v-model="deliveryMode.params.routing.device" item-text="k" item-value="v" label="Device"></v-select>
</v-col>
</v-row>
<b>Delivery Targets:</b>
<v-btn color="success" @click="addDeliveryTarget(index)">Add</v-btn>
<v-row v-for="(connector, index) in deliveryMode.params.routing.connectors" :key="index">
<v-col cols="6" sm="4" md="4">
<v-select :items="connectorTypes" v-model="connector[0]" item-text="k" item-value="v" label="Connector Name"></v-select>
</v-col>
<v-col cols="6" sm="4" md="4">
<v-text-field v-model="connector[1]" label="Connector Param"></v-text-field>
</v-col>
<v-col cols="6" sm="4" md="4">
<v-btn color="error" @click="deliveryMode.params.routing.connectors.splice(index, 1)" icon><v-icon>mdi-delete</v-icon></v-btn>
</v-col>
</v-row>
</v-col>
</v-row>
<v-row>
<v-btn color="success" @click="storeConfig()">Store & Restart</v-btn>
</v-row>
</v-container>
</v-tab-item>
<v-tab-item key="notificationConfig">
<v-container>
<b>Routing Paramters:</b>
<v-row>
<v-col cols="12" sm="12" md="6">
<v-text-field label="Daemon Endpoint URL" v-model="configData.pager.url"></v-text-field>
</v-col>
<v-row>
<v-btn color="success" @click="storeConfig()">Store & Restart</v-btn>
</v-row>
</v-container>
</v-tab-item>
</v-tabs-items>
</v-form>
</v-content>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-resource@1.5.1"></script>
<script>
new Vue({
el: '#app',
vuetify: new Vuetify(),
http: { root: '/' },
data() {
return {
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'},
],
configData: {
"pager": {
"url": "",
},
"menuSupport": false,
"deliveryModes": []
},
}
},
created() {
this.loadConfig()
},
methods: {
loadConfig() {
this.$http.get('/config').then(response => {
const newConfig = response.body
newConfig.deliveryModes = newConfig.deliveryModes.map((x) => {
x._id = btoa(JSON.stringify(x))
return x
})
this.configData = newConfig
}, response => {
})
},
storeConfig() {
const storeConfig = JSON.parse(JSON.stringify(this.configData))
this.$http.post('/config', storeConfig).then(response => {
})
.then(this.$http.post('/restart'))
.then(() => {
document.body.style = 'display:none'
setTimeout(() => window.location.reload(), 1e3)
})
},
addDeliveryTarget(index) {
this.configData.deliveryModes[ index ].params.routing.connectors.push(["connectorName","connectorParam"])
},
addRegionCMD() {
this.configData.regions.push({
name: "",
active: true,
dwdID: "",
})
},
}
})
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

@ -3,6 +3,7 @@ const config = require('./config.json')
const { Telegraf, Markup } = require('telegraf') const { Telegraf, Markup } = require('telegraf')
const io = require("socket.io-client") const io = require("socket.io-client")
const axios = require('axios') const axios = require('axios')
const fs = require('fs')
const socket = io(new URL(config.pager.url).origin) const socket = io(new URL(config.pager.url).origin)
const bot = new Telegraf(config.bottoken) const bot = new Telegraf(config.bottoken)
@ -44,30 +45,19 @@ bot.on('message', (ctx) => {
console.log(ctx.update.message.from) console.log(ctx.update.message.from)
const preview = `Preview: ${ filter(ctx.update.message.from.first_name) }:${ filter(ctx.update.message.text) }` const preview = `Preview: ${ filter(ctx.update.message.from.first_name) }:${ filter(ctx.update.message.text) }`
console.log(preview) console.log(preview)
ctx.reply(preview, Markup.inlineKeyboard([ ctx.reply(preview, Markup.inlineKeyboard(
Markup.button.callback('💬(Receive ACK)', 'normal'), config.deliveryModes.map((deliveryModeConfig, index) =>
Markup.button.callback('🚨(Receive,Read,Response ACKs)', 'priority') Markup.button.callback(deliveryModeConfig.name, 'deliveryMode-' + index)
])) )
))
}) })
bot.action('normal', async (ctx) => {
const origText = ctx.update.callback_query.message.text.substring(8+1) for (let deliveryModeIndex in config.deliveryModes) {
await ctx.answerCbQuery() bot.action('deliveryMode-' + deliveryModeIndex, async (ctx) => {
await ctx.editMessageReplyMarkup(undefined)
let msgId = (await axios.post(config.pager.url, Object.assign({ ...config.pager.paramsNormal }, { payload: origText }))).data
assoc[msgId] = {
tgmsg: ctx.update.callback_query.message.message_id,
text: origText,
newText: `Preview: ${ origText }\n\n--[${ msgId }]--\n`,
tgchat: ctx.update.callback_query.message.chat.id
}
await ctx.editMessageText(assoc[msgId].newText)
await ctx.replyWithSticker('CAACAgIAAxkBAANwYJRBBO79JToCqzsjJi1DltHnaTcAAmYNAALviaBI68kAAd6sFEZIHwQ')
})
bot.action('priority', async (ctx) => {
const origText = ctx.update.callback_query.message.text.substring(8+1) const origText = ctx.update.callback_query.message.text.substring(8+1)
await ctx.answerCbQuery() await ctx.answerCbQuery()
await ctx.editMessageReplyMarkup(undefined) await ctx.editMessageReplyMarkup(undefined)
let msgId = (await axios.post(config.pager.url, Object.assign({ ...config.pager.paramsPriority }, { payload: origText }))).data let msgId = (await axios.post(config.pager.url, Object.assign({ ...config.deliveryModes[ deliveryModeIndex ].params }, { payload: origText }))).data
assoc[msgId] = { assoc[msgId] = {
tgmsg: ctx.update.callback_query.message.message_id, tgmsg: ctx.update.callback_query.message.message_id,
text: origText, text: origText,
@ -75,11 +65,34 @@ bot.action('priority', async (ctx) => {
tgchat: ctx.update.callback_query.message.chat.id tgchat: ctx.update.callback_query.message.chat.id
} }
await ctx.editMessageText(assoc[msgId].newText) await ctx.editMessageText(assoc[msgId].newText)
await ctx.replyWithSticker('CAACAgIAAxkBAANwYJRBBO79JToCqzsjJi1DltHnaTcAAmYNAALviaBI68kAAd6sFEZIHwQ') })
}) }
bot.launch() bot.launch()
// Enable graceful stop // Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT')) process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM')) process.once('SIGTERM', () => bot.stop('SIGTERM'))
const express = require('express')
const appConfig = express()
appConfig.use(express.json())
appConfig.use(express.static('html'))
/** CONFIG Routes */
appConfig.get('/config', async (req, res) => {
return res.json(JSON.parse(fs.readFileSync('config.json')))
})
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)
console.log(req.body)
fs.writeFileSync('config.json', JSON.stringify(req.body, null, "\t"))
return res.json(true)
})
appConfig.post('/restart', (req, res) => {
process.exit(1)
})
appConfig.listen(3060, '0.0.0.0' || config.host || '127.0.0.1')

@ -1,6 +1,7 @@
{ {
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^0.21.1",
"express": "^4.18.2",
"moment": "^2.29.1", "moment": "^2.29.1",
"socket.io-client": "^4.0.2", "socket.io-client": "^4.0.2",
"telegraf": "^4.3.0" "telegraf": "^4.3.0"

Loading…
Cancel
Save