Add \!sms command to send to a new number
This commit is contained in:
parent
67fc6b72cb
commit
2b0a23d305
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/config.json
|
/config.json
|
||||||
/node_modules/
|
/node_modules/
|
||||||
|
/nbproject/private/
|
||||||
|
@ -19,6 +19,12 @@ Back and forth it goes!
|
|||||||
|
|
||||||
Or just run `node main.js`.
|
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
|
## Known Issues/Limitations
|
||||||
|
|
||||||
* If you leave a room the bot won't invite you back, even if there are new SMS messages.
|
* If you leave a room the bot won't invite you back, even if there are new SMS messages.
|
||||||
|
18
main.js
18
main.js
@ -17,7 +17,7 @@ import { dirname } from 'path';
|
|||||||
|
|
||||||
// Load settings from config.json
|
// Load settings from config.json
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
let rawdata = fs.readFileSync(__dirname + '/config.json');
|
let rawdata = fs.readFileSync(__dirname + '/config.json');
|
||||||
let settings = JSON.parse(rawdata);
|
let settings = JSON.parse(rawdata);
|
||||||
console.log(__dirname + "/config.json loaded.");
|
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) {
|
if (client.getUserId() == event.event.sender) {
|
||||||
return; // skip own messages to prevent loop
|
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);
|
//sendMatrix(room.roomId, "echo " + event.event.content.body);
|
||||||
//console.log(room);
|
//console.log(room);
|
||||||
const matches = room.name.match(/([1-9][0-9]+)/g);
|
const matches = room.name.match(/([1-9][0-9]+)/g);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user