summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.js22
-rw-r--r--src/db.js4
2 files changed, 23 insertions, 3 deletions
diff --git a/src/app.js b/src/app.js
index 7c7ac83..e363916 100644
--- a/src/app.js
+++ b/src/app.js
@@ -1,6 +1,6 @@
const bodyParser = require('body-parser');
const express = require('express');
-const { isSubscribed, getSubscriptions, getSubscriptionFromNumber } = require('./db');
+const { isSubscribed, getSubscriptions, getSubscriptionFromNumber, subscribe } = require('./db');
const { sendTextMessage } = require('./sendTextMessage');
const { MessagingResponse } = require('twilio').twiml;
@@ -35,10 +35,28 @@ app.post('/sms', (req, res) => {
recipients: "${abbreviatedBody}". Only you can see this message.
`;
sendTextMessage([senderSubscription], confirmationMessage);
+ } else {
+ if (body.toLocaleLowerCase().startsWith('my name is ') || body.toLocaleLowerCase().startsWith('my name is: ')) {
+ const senderName = body.matchAll(/^my name is:? (.*)$/)?.next()?.[1];
+
+ if (!senderName) {
+ const twiml = new MessagingResponse();
+ twiml.message("Please provide a name. Syntax: my name is <your name>");
+ res.type('text/xml').send(twiml.toString());
+ return;
+ }
+
+ const subscription = subscribe(senderPhoneNumber, senderName);
+ const welcomeMessage = `
+ Well done, ${senderName}! You have successfully subscribed to the Glen
+ Coe meet texting group. You will now be able to send and receive messages
+ to and from the group.
+ `;
+ sendTextMessage([subscription], welcomeMessage);
+ }
}
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
index b668495..ba37a30 100644
--- a/src/db.js
+++ b/src/db.js
@@ -9,7 +9,9 @@ const subscriptions = [];
* @param {string} name
*/
function subscribe(number, name) {
- subscriptions.push({ name, number });
+ const subscription = { name, number };
+ subscriptions.push(subscription);
+ return subscription;
}
/**