2024-06-21 17:44:44 +00:00
|
|
|
exports.reply = function (options) {
|
|
|
|
var keyboard = "textinput";
|
|
|
|
try {
|
|
|
|
keyboard = require(keyboard);
|
|
|
|
} catch (e) {
|
|
|
|
keyboard = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function constructReply(msg, replyText, resolve) {
|
|
|
|
var responseMessage = {msg: replyText};
|
|
|
|
if (msg.id) {
|
|
|
|
responseMessage = { t: "notify", id: msg.id, n: "REPLY", msg: replyText };
|
|
|
|
}
|
|
|
|
E.showMenu();
|
|
|
|
if (options.sendReply == null || options.sendReply) {
|
2024-06-21 18:29:44 +00:00
|
|
|
Bluetooth.println(JSON.stringify(responseMessage));
|
2024-06-21 17:44:44 +00:00
|
|
|
}
|
|
|
|
resolve(responseMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
var menu = {
|
|
|
|
"": {
|
|
|
|
title: options.title || /*LANG*/ "Reply with:",
|
|
|
|
back: function () {
|
|
|
|
E.showMenu();
|
|
|
|
reject("User pressed back");
|
|
|
|
},
|
|
|
|
}, // options
|
|
|
|
/*LANG*/ "Compose": function () {
|
|
|
|
keyboard.input().then((result) => {
|
|
|
|
constructReply(options.msg ?? {}, result, resolve);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
var replies =
|
|
|
|
require("Storage").readJSON(
|
|
|
|
options.fileOverride || "replies.json",
|
|
|
|
true
|
2024-06-24 17:22:09 +00:00
|
|
|
) || [];
|
2024-06-21 17:44:44 +00:00
|
|
|
replies.forEach((reply) => {
|
|
|
|
menu = Object.defineProperty(menu, reply.text, {
|
|
|
|
value: () => constructReply(options.msg ?? {}, reply.text, resolve),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (!keyboard) delete menu[/*LANG*/ "Compose"];
|
|
|
|
|
|
|
|
if (replies.length == 0) {
|
|
|
|
if (!keyboard) {
|
|
|
|
E.showPrompt(
|
|
|
|
/*LANG*/ "Please install a keyboard app, or set a custom reply via the app loader!",
|
|
|
|
{
|
|
|
|
buttons: { Ok: true },
|
|
|
|
remove: function () {
|
|
|
|
reject(
|
|
|
|
"Please install a keyboard app, or set a custom reply via the app loader!"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
keyboard.input().then((result) => {
|
|
|
|
constructReply(options.msg.id, result, resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
E.showMenu(menu);
|
|
|
|
});
|
|
|
|
};
|