UNPKG

nodered-contrib-signal-client

Version:
325 lines (293 loc) 12.1 kB
<!-- Created by Martin Gaus --> <!-- Button injections --> <script type="text/javascript"> function inject(node) { if (node.changed) { return RED.notify("<strong>Warning</strong>: node has undeployed changes", "warning"); } var label = node._def.label.call(node); if (label.length > 30) { label = label.substring(0, 50) + "..."; } label = label.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); $.ajax({ url: "signal-client/" + node.id, type: "POST", success: function (resp) { RED.notify(`Successfully injected: ${label}`, { type: "success", id: node.type }); }, error: function (jqXHR, textStatus, errorThrown) { if (jqXHR.status == 404) { RED.notify("<strong>Error</strong>: node not deployed", "error"); } else if (jqXHR.status == 500) { RED.notify("<strong>Error</strong>: inject failed, see log for details", "error"); } else if (jqXHR.status == 0) { RED.notify("<strong>Error</strong>: no response from server", "error"); } else { RED.notify(`<strong>Error</strong>: unexpected error ${jqXHR.status} ${textStatus}`, "error"); } } }); } </script> <!-- configuration --> <script type="text/javascript"> RED.nodes.registerType('account', { category: 'config', defaults: { phoneNumber: { value: "", required: true }, password: { value: "", required: true }, dataStoreDirectory: { value: "", required: true }, liveServer: { value: false }, accountName: { value: "" }, }, label: function () { return this.accountName || this.phoneNumber; } }); </script> <script type="text/html" data-template-name="account"> <div class="form-row"> <label for="node-config-input-phoneNumber"><i class="fa fa-phone"></i> Phone Number</label> <input type="text" id="node-config-input-phoneNumber" placeholder="+4955512345678"> </div> <div class="form-tips form-row"> <b>Tip:</b> The phone number must to be noted in <a href="https://en.wikipedia.org/wiki/E.123" target_="_blank">E.123</a> format (without spaces). For instance a german phone number (555) 1234-5678 would be written +4955512345678. </div> <div class="form-row"> <label for="node-config-input-password"><i class="fa fa-ellipsis-h"></i> Password</label> <input type="text" id="node-config-input-password"> </div> <div class="form-row"> <label for="node-config-input-dataStoreDirectory"><i class="fa fa-database"></i> Data Store</label> <input type="text" id="node-config-input-dataStoreDirectory" placeholder="Data store directory, e.g. Account1"> </div> <div class="form-tips form-row"> <b>Tip:</b> The Data store directory must be a unique name that complies with the guidelines of the file system. It can only be assigned once for all accounts. </div> <div class="form-row"> <label for="node-config-input-liveServer"><i class="fa fa-paper-plane"></i> Live Server</label> <input type="checkbox" id="node-config-input-liveServer" style="display: inline-block; width: auto; vertical-align: top;"> </div> <div class="form-tips form-row"> <b>Tip:</b> To communicate with the real world (e.g. your mobile phone) activate the flag. </div> <div class="form-row"> <label for="node-config-input-accountName"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-config-input-accountName" placeholder="Name"> </div> </script> <!-- request-sms --> <script type="text/javascript"> RED.nodes.registerType('request-sms', { category: 'Signal Client', color: '#5692f3', defaults: { server: { value: "", type: "remote-server" }, account: { value: "", type: "account" }, captcha: { value: "", required: false }, name: { value: "", required: false }, }, inputs: 0, outputs: 2, button: { enabled: function () { return !this.changed }, onclick: function () { inject(this); } }, icon: "signal-registration.png", label: function () { return this.name || "request-sms"; } }); </script> <script type="text/html" data-template-name="request-sms"> <div class="form-row"> <label for="node-input-account"><i class="fa fa-globe"></i> Account</label> <input id="node-input-account"> </div> <div class="form-row"> <label for="node-input-captcha"><i class="fa fa-refresh"></i> Captcha Code</label> <input type="text" id="node-input-captcha" placeholder="Optional captcha code (see documentation)"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> </script> <script type="text/html" data-help-name="request-sms"> <p>Request a registration code from Signal Messenger. It is send via sms.</p> </script> <!-- request-voice --> <script type="text/javascript"> RED.nodes.registerType('request-voice', { category: 'Signal Client', color: '#5692f3', defaults: { server: { value: "", type: "remote-server" }, account: { value: "", type: "account" }, captcha: { value: "", required: false }, name: { value: "", required: false }, }, inputs: 0, outputs: 2, button: { enabled: function () { return !this.changed }, onclick: function () { inject(this); } }, icon: "signal-registration.png", label: function () { return this.name || "request-voice"; } }); </script> <script type="text/html" data-template-name="request-voice"> <div class="form-row"> <label for="node-input-account"><i class="fa fa-globe"></i> Account</label> <input id="node-input-account"> </div> <div class="form-row"> <label for="node-input-captcha"><i class="fa fa-refresh"></i> Captcha Code</label> <input type="text" id="node-input-captcha" placeholder="Optional captcha code (see documentation)"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> </script> <script type="text/html" data-help-name="request-voice"> <p>Request a registration code from Signal Messenger. It is transmitted by voice message.</p> </script> <!-- register --> <script type="text/javascript"> RED.nodes.registerType('register', { category: 'Signal Client', color: '#5692f3', defaults: { account: { value: "", type: "account" }, registrationCode: { value: "", required: true }, name: { value: "", required: false }, }, inputs: 0, outputs: 2, button: { enabled: function () { return !this.changed }, onclick: function () { inject(this); } }, icon: "signal-registration.png", label: function () { return this.name || "register"; } }); </script> <script type="text/html" data-template-name="register"> <div class="form-row"> <label for="node-input-account"><i class="fa fa-globe"></i> Account</label> <input id="node-input-account"> </div> <div class="form-row"> <label for="node-input-registrationCode"><i class="fa fa-registered"></i> Registration Code</label> <input type="text" id="node-input-registrationCode" placeholder="Registration code received via SMS, e.g. 123-456"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> </script> <script type="text/html" data-help-name="register"> <p>Register on Signal Messenger with the use of the registration code.</p> </script> <!-- send --> <script type="text/javascript"> RED.nodes.registerType('send', { category: 'Signal Client', color: '#5692f3', defaults: { account: { value: "", type: "account" }, receiverNumber: { value: "", required: false }, verboseLogging: { value: false }, name: { value: "", required: false }, }, inputs: 1, outputs: 2, icon: "signal.png", label: function () { return this.name || "send"; } }); </script> <script type="text/html" data-template-name="send"> <div class="form-row"> <label for="node-input-account"><i class="fa fa-globe"></i> Account</label> <input id="node-input-account"> </div> <div class="form-row"> <label for="node-input-receiverNumber"><i class="fa fa-phone"></i> Receiver Number</label> <input type="text" id="node-input-receiverNumber" placeholder="+4955512345678"> </div> <div class="form-row"> <div class="form-tips" style="width: auto"><b>Tip:</b> The receiver number must to be noted in <a href="https://en.wikipedia.org/wiki/E.123" target_="_blank">E.123</a> format (without spaces). For instance a german phone number (555) 1234-5678 would be written +4955512345678.</div> </div> <div class="form-row"> <label for="node-input-verboseLogging"><i class="fa fa-search"></i> Verbose Logging</label> <input type="checkbox" id="node-input-verboseLogging" style="display: inline-block; width: auto; vertical-align: top;"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> </script> <script type="text/html" data-help-name="send"> <p>Send a message via Signal Messenger.</p> </script> <!-- receive --> <script type="text/javascript"> RED.nodes.registerType('receive', { category: 'Signal Client', color: '#5692f3', defaults: { account: { value: "", type: "account" }, downloadDirectory: { value: "", required: false }, verboseLogging: { value: false }, name: { value: "", required: false }, }, inputs: 0, outputs: 2, icon: "signal.png", label: function () { return this.name || "receive"; } }); </script> <script type="text/html" data-template-name="receive"> <div class="form-row"> <label for="node-input-account"><i class="fa fa-globe"></i> Account</label> <input id="node-input-account"> </div> <div class="form-row"> <label for="node-input-downloadDirectory"><i class="fa fa-download"></i> Download Directory</label> <input type="text" id="node-input-downloadDirectory" placeholder="Download Directory"> </div> <div class="form-row"> <label for="node-input-verboseLogging"><i class="fa fa-search"></i> Verbose Logging</label> <input type="checkbox" id="node-input-verboseLogging" style="display: inline-block; width: auto; vertical-align: top;"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> </script> <script type="text/html" data-help-name="receive"> <p>Receive a message via Signal Messenger.</p> </script>