node-red-contrib-nostr
Version:
Node-RED nodes for seamless Nostr protocol integration. Features robust WebSocket handling, event filtering, and NPUB-based routing. Built with TypeScript for type safety and extensive testing. Perfect for Nostr automation flows.
143 lines (133 loc) • 6.03 kB
HTML
<script type="text/html" data-template-name="nostr-filter">
<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>
<div class="form-row">
<label for="node-input-relay"><i class="fa fa-globe"></i> Relay</label>
<input type="text" id="node-input-relay">
</div>
<div class="form-row">
<label for="node-input-filterType"><i class="fa fa-filter"></i> Filter Type</label>
<select id="node-input-filterType">
<option value="npub">Track User (npub)</option>
<option value="kind">Event Kind</option>
<option value="tag">Tag</option>
<option value="since">Time Since</option>
<option value="custom">Custom</option>
</select>
</div>
<div class="form-row filter-npub">
<label for="node-input-npubValue"><i class="fa fa-user"></i> Nostr Public Key</label>
<input type="text" id="node-input-npubValue" placeholder="npub1...">
<div class="form-tips">Enter the npub of the user you want to track</div>
</div>
<div class="form-row filter-npub">
<label for="node-input-npubEventKinds"><i class="fa fa-list"></i> Event Types</label>
<select id="node-input-npubEventKinds" multiple>
<option value="0">Profile Metadata</option>
<option value="1">Text Notes</option>
<option value="3">Contacts</option>
<option value="6">Reposts</option>
<option value="7">Reactions</option>
<option value="9735">Zaps</option>
</select>
<div class="form-tips">Select which types of events to track for this user</div>
</div>
<div class="form-row filter-kind">
<label for="node-input-eventKinds"><i class="fa fa-list"></i> Event Kinds</label>
<select id="node-input-eventKinds" multiple>
<option value="0">Metadata (0)</option>
<option value="1">Text Note (1)</option>
<option value="3">Contacts (3)</option>
<option value="4">DM (4)</option>
<option value="6">Repost (6)</option>
<option value="7">Reaction (7)</option>
<option value="9735">Zap (9735)</option>
</select>
</div>
<div class="form-row filter-tag">
<label for="node-input-tagName"><i class="fa fa-tag"></i> Tag Name</label>
<input type="text" id="node-input-tagName" placeholder="e, p, t, etc">
</div>
<div class="form-row filter-tag">
<label for="node-input-tagValue"><i class="fa fa-tag"></i> Tag Value</label>
<input type="text" id="node-input-tagValue" placeholder="Tag value to match">
</div>
<div class="form-row filter-since">
<label for="node-input-sinceMinutes"><i class="fa fa-clock-o"></i> Minutes</label>
<input type="number" id="node-input-sinceMinutes" placeholder="Time window in minutes">
</div>
<div class="form-row filter-custom">
<label for="node-input-customFilter"><i class="fa fa-code"></i> Custom Filter</label>
<input type="text" id="node-input-customFilter" placeholder='{"kinds":[1],"#e":["..."]}'>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('nostr-filter', {
category: 'protocol',
color: '#a6bbcf',
defaults: {
name: { value: "" },
relay: { type: "nostr-relay-config", required: true },
filterType: { value: "npub" },
npubValue: { value: "", required: false },
npubEventKinds: { value: [0, 1], required: false },
eventKinds: { value: [1], required: false },
tagName: { value: "", required: false },
tagValue: { value: "", required: false },
sinceMinutes: { value: 60, required: false, validate: RED.validators.number() },
customFilter: { value: "", required: false }
},
label: function() {
if (this.filterType === 'npub' && this.npubValue) {
return this.name || `Track ${this.npubValue.substring(0, 12)}...`;
}
return this.name || "nostr filter";
},
oneditprepare: function() {
function showHideFields() {
$('.form-row').hide();
$('.form-row:first-child').show();
$('.form-row:nth-child(2)').show();
$('.form-row:nth-child(3)').show();
$(`.filter-${$('#node-input-filterType').val()}`).show();
}
$('#node-input-filterType').on('change', showHideFields);
showHideFields();
}
});
</script>
<script type="text/html" data-help-name="nostr-filter">
<p>Filters Nostr events based on various criteria.</p>
<h3>Properties</h3>
<dl class="message-properties">
<dt>Relay
<span class="property-type">config</span>
</dt>
<dd>Select the Nostr relay configuration to use</dd>
</dl>
<h3>Filter Types</h3>
<dl class="message-properties">
<dt>Track User (npub)
<span class="property-type">string</span>
</dt>
<dd>Track events from a specific Nostr user by their npub. Select which types of events to track.</dd>
<dt>Event Kind
<span class="property-type">array</span>
</dt>
<dd>Filter events by their kind (e.g., text notes, reactions, etc.)</dd>
<dt>Tag
<span class="property-type">string</span>
</dt>
<dd>Filter events by tag name and value</dd>
<dt>Time Since
<span class="property-type">number</span>
</dt>
<dd>Filter events within a time window (in minutes)</dd>
<dt>Custom
<span class="property-type">json</span>
</dt>
<dd>Specify a custom Nostr filter in JSON format</dd>
</dl>
</script>