diff --git a/.gitignore b/.gitignore index 06adb8c..e35e928 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /config.json -/node_modules/ \ No newline at end of file +/node_modules/ +/nbproject/private/ diff --git a/README.md b/README.md index 9838b3f..6ab4a0d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,12 @@ Back and forth it goes! Or just run `node main.js`. +## Starting a new conversation + +When a SMS is received from a new number, a new room is created. If you need to send a message to +a new number, simply type something like `!sms 14065551234` into an existing SMS room. You'll be +invited to join a new room and will then be able to send your message. + ## Known Issues/Limitations * If you leave a room the bot won't invite you back, even if there are new SMS messages. diff --git a/main.js b/main.js index a68b302..e5ee13d 100644 --- a/main.js +++ b/main.js @@ -17,7 +17,7 @@ import { dirname } from 'path'; // Load settings from config.json const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); + const __dirname = dirname(__filename); let rawdata = fs.readFileSync(__dirname + '/config.json'); let settings = JSON.parse(rawdata); console.log(__dirname + "/config.json loaded."); @@ -217,6 +217,22 @@ client.login("m.login.password", {"user": settings.matrixuser, "password": setti if (client.getUserId() == event.event.sender) { return; // skip own messages to prevent loop } + if (event.event.content.body.startsWith("!sms")) { + // capture command to start room for new number + const matches = event.event.content.body.match(/([1-9]?[0-9]{10})/g); + if (matches.length == 1) { + var tel = matches[0]; + if (tel.length == 10) { + // make it the full number + tel = "1" + tel; + } + logger.info("Got request to start new SMS conversation with " + tel + " from " + event.event.sender + "."); + createOrJoinSMSRoom(tel, function () { + return; + }); + } + return; + } //sendMatrix(room.roomId, "echo " + event.event.content.body); //console.log(room); const matches = room.name.match(/([1-9][0-9]+)/g);