Skip to content

Commit 7c6af8e

Browse files
authored
Ability to send messages back to Bluesky firehose
https://gist.github.com/simonw/9c4525e0364d60c1a8a7bd663ff0df35
1 parent e71a608 commit 7c6af8e

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

bluesky-firehose.html

+72-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111
margin: 20px auto;
1212
padding: 0 20px;
1313
}
14-
#output {
14+
.textarea-container {
15+
margin: 20px 0;
16+
}
17+
textarea {
1518
width: 100%;
16-
height: 400px;
17-
margin-top: 20px;
19+
height: 200px;
20+
margin-top: 10px;
1821
padding: 10px;
1922
font-family: monospace;
2023
border: 1px solid #ccc;
2124
border-radius: 4px;
2225
}
26+
#output {
27+
height: 400px;
28+
}
2329
.controls {
2430
margin: 20px 0;
2531
}
@@ -28,6 +34,11 @@
2834
margin-right: 10px;
2935
cursor: pointer;
3036
}
37+
.error {
38+
color: red;
39+
margin-top: 5px;
40+
font-size: 14px;
41+
}
3142
</style>
3243
</head>
3344
<body>
@@ -37,11 +48,34 @@ <h1>Bluesky WebSocket Feed Monitor</h1>
3748
<button id="disconnect">Disconnect</button>
3849
<button id="clear">Clear Log</button>
3950
</div>
40-
<textarea id="output" readonly></textarea>
51+
52+
<div class="textarea-container">
53+
<h3>Send Message</h3>
54+
<textarea id="input" placeholder="Paste your JSON message here..."></textarea>
55+
<div id="jsonError" class="error"></div>
56+
<button id="send">Send Message</button>
57+
<p>Example message to filter for only specific DID handles (<a href="https://tools.simonwillison.net/bluesky-resolve">resolve those here</a>):</p>
58+
<pre><code>
59+
{
60+
"type": "options_update",
61+
"payload": {
62+
"wantedCollections": ["app.bsky.feed.post"],
63+
"wantedDids": ["did:plc:kft6lu4trxowqmter2b6vg6z"],
64+
"maxMessageSizeBytes": 1000000
65+
}
66+
}</code></pre>
67+
</div>
68+
69+
<div class="textarea-container">
70+
<h3>Log Output</h3>
71+
<textarea id="output" readonly></textarea>
72+
</div>
4173

4274
<script>
4375
let ws = null;
4476
const output = document.getElementById('output');
77+
const input = document.getElementById('input');
78+
const jsonError = document.getElementById('jsonError');
4579

4680
function log(message) {
4781
const timestamp = new Date().toISOString();
@@ -96,12 +130,46 @@ <h1>Bluesky WebSocket Feed Monitor</h1>
96130
}
97131
}
98132

133+
function sendMessage() {
134+
if (!ws) {
135+
log('Not connected to WebSocket');
136+
return;
137+
}
138+
139+
const message = input.value.trim();
140+
if (!message) {
141+
jsonError.textContent = 'Please enter a message';
142+
return;
143+
}
144+
145+
try {
146+
// Validate JSON
147+
const jsonMessage = JSON.parse(message);
148+
149+
// Send the message
150+
ws.send(JSON.stringify(jsonMessage));
151+
log(`Sent: ${message}`);
152+
jsonError.textContent = '';
153+
} catch (error) {
154+
jsonError.textContent = 'Invalid JSON format';
155+
log(`Failed to send message: Invalid JSON format`);
156+
}
157+
}
158+
99159
// Event Listeners
100160
document.getElementById('connect').addEventListener('click', connect);
101161
document.getElementById('disconnect').addEventListener('click', disconnect);
102162
document.getElementById('clear').addEventListener('click', () => {
103163
output.value = '';
104164
});
165+
document.getElementById('send').addEventListener('click', sendMessage);
166+
167+
// Add keyboard shortcut (Ctrl/Cmd + Enter) to send message
168+
input.addEventListener('keydown', (e) => {
169+
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
170+
sendMessage();
171+
}
172+
});
105173
</script>
106174
</body>
107175
</html>

0 commit comments

Comments
 (0)