summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2024-03-07 20:59:26 +0000
committerJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2024-03-07 20:59:26 +0000
commit9f44e87b092e9149c47466e4578f794fe4376524 (patch)
treecab65045dac8cd99d48a225c731d09c4a000320b
parent2b8fea0fd0b514b5ca4349185bf4dfb4455d5875 (diff)
Does stuff
-rw-r--r--jsconfig.json1
-rw-r--r--src/app.js4
-rw-r--r--src/db.js29
3 files changed, 32 insertions, 2 deletions
diff --git a/jsconfig.json b/jsconfig.json
index 8d445d6..3545e94 100644
--- a/jsconfig.json
+++ b/jsconfig.json
@@ -2,7 +2,6 @@
"compilerOptions": {
"module": "commonjs",
"target": "es6",
- "checkJs": false
},
"exclude": ["node_modules"]
}
diff --git a/src/app.js b/src/app.js
index 8c863a2..9067aa6 100644
--- a/src/app.js
+++ b/src/app.js
@@ -7,8 +7,10 @@ const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/sms', (req, res) => {
- const
+ /** @type {string} */
+ const body = req.body;
const twiml = new MessagingResponse();
+ twiml.message(JSON.stringify(body));
res.type('text/xml').send(twiml.toString());
});
diff --git a/src/db.js b/src/db.js
new file mode 100644
index 0000000..145b144
--- /dev/null
+++ b/src/db.js
@@ -0,0 +1,29 @@
+// Ideally, we should write to a file and read it at app start in case of crashes.
+// An actual SQL database would probably be overkill.
+
+/** @type Array<{ name: string, number: string }> */
+const subscriptions = [];
+
+/**
+ * @param {string} number
+ * @param {string} name
+ */
+export function subscribe(number, name) {
+ subscriptions.push({ name, number });
+}
+
+/**
+ * @param {string} number
+ */
+export function isSubscribed(number) {
+ return subscriptions.some(s => s.number == number);
+}
+
+export function getSubscriptions() {
+ /** @type Array<{ name: string, number: string }> */
+ const clone = [];
+ for (const subscription of subscriptions) {
+ clone.push({ ...subscription });
+ }
+ return clone;
+} \ No newline at end of file