diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2024-03-07 21:56:54 +0000 |
|---|---|---|
| committer | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2024-03-07 21:56:54 +0000 |
| commit | d8287337edf14e507bcab31b91607133aff20b50 (patch) | |
| tree | abfe5833e9df2b101427b5f3fdcfcff0480e9195 /src/app.js | |
| parent | 3086d325afa7a9d8fc49a0d8022b675f6d4e370b (diff) | |
More stuff
Diffstat (limited to 'src/app.js')
| -rw-r--r-- | src/app.js | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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()); }); |
