Add \!sms command to send to a new number

This commit is contained in:
Skylar Ittner 2020-11-10 18:07:40 -07:00
parent 67fc6b72cb
commit 2b0a23d305
3 changed files with 25 additions and 2 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
/config.json
/node_modules/
/node_modules/
/nbproject/private/

View File

@ -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.

18
main.js
View File

@ -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);