Add MMS support maybe
This commit is contained in:
parent
2b0a23d305
commit
7a50084bb9
51
main.js
51
main.js
@ -55,7 +55,7 @@ function checkSMS() {
|
|||||||
var msg = messages[i];
|
var msg = messages[i];
|
||||||
logger.info("Received SMS from " + msg.from + ": " + msg.body);
|
logger.info("Received SMS from " + msg.from + ": " + msg.body);
|
||||||
createOrJoinSMSRoom(msg.from, function (roomid) {
|
createOrJoinSMSRoom(msg.from, function (roomid) {
|
||||||
sendMatrix(roomid, msg.body);
|
sendMatrix(roomid, msg.body, msg.media);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -128,7 +128,53 @@ function createOrJoinSMSRoom(tel, callback) {
|
|||||||
* @param {function|undefined} callback passes true when successful, false on failure.
|
* @param {function|undefined} callback passes true when successful, false on failure.
|
||||||
* @returns {undefined}
|
* @returns {undefined}
|
||||||
*/
|
*/
|
||||||
function sendMatrix(roomid, body, callback) {
|
function sendMatrix(roomid, body, media, callback) {
|
||||||
|
|
||||||
|
if (body == "" && typeof media != "undefined") {
|
||||||
|
body = "Attachment";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof media == "string") {
|
||||||
|
var content = {
|
||||||
|
body: body,
|
||||||
|
msgtype: "m.file",
|
||||||
|
url: media
|
||||||
|
}
|
||||||
|
client.sendEvent(roomid, "m.room.message", content, "").then((res) => {
|
||||||
|
if (typeof callback == "function") {
|
||||||
|
callback(true);
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
if (typeof callback == "function") {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
if (err.data.error == "Unknown room") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.error(err);
|
||||||
|
});
|
||||||
|
} else if (typeof media == "array") {
|
||||||
|
for (var i = 0; i < media.length; i++) {
|
||||||
|
var content = {
|
||||||
|
body: body,
|
||||||
|
msgtype: "m.file",
|
||||||
|
url: media[i]
|
||||||
|
}
|
||||||
|
client.sendEvent(roomid, "m.room.message", content, "").then((res) => {
|
||||||
|
if (typeof callback == "function") {
|
||||||
|
callback(true);
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
if (typeof callback == "function") {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
if (err.data.error == "Unknown room") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var content = {
|
var content = {
|
||||||
body: body,
|
body: body,
|
||||||
@ -240,6 +286,7 @@ client.login("m.login.password", {"user": settings.matrixuser, "password": setti
|
|||||||
var tel = matches[0];
|
var tel = matches[0];
|
||||||
logger.info("Got message for " + tel + " from " + event.event.sender + ", relaying.");
|
logger.info("Got message for " + tel + " from " + event.event.sender + ", relaying.");
|
||||||
sendSMS(tel, event.event.content.body);
|
sendSMS(tel, event.event.content.body);
|
||||||
|
client.sendEvent(room.roomId, "m.fully_read", room.roomId, "");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user