atproto utils for zig zat.dev
atproto sdk zig
26
fork

Configure Feed

Select the types of activity you want to include in your feed.

at dfd015c4e12850beb5b43c8b301c91bc8ef0f877 38 lines 1.2 kB view raw
1const std = @import("std"); 2const zat = @import("zat"); 3 4pub fn main() !void { 5 var da: std.heap.DebugAllocator(.{}) = .init; 6 defer _ = da.deinit(); 7 const allocator = da.allocator(); 8 9 std.debug.print("smoke test starting\n", .{}); 10 11 var handler = Handler{}; 12 var client = zat.JetstreamClient.init(std.Options.debug_io, allocator, .{ 13 .hosts = &.{"jetstream2.us-east.bsky.network"}, 14 .wanted_collections = &.{"app.bsky.feed.post"}, 15 }); 16 try client.subscribe(&handler); 17} 18 19const Handler = struct { 20 count: u64 = 0, 21 connects: u64 = 0, 22 23 pub fn onEvent(self: *Handler, event: zat.JetstreamEvent) void { 24 self.count += 1; 25 if (self.count % 1000 == 0) { 26 std.debug.print(" [{d}] time_us={d}\n", .{ self.count, event.timeUs() }); 27 } 28 } 29 30 pub fn onConnect(self: *Handler, host: []const u8) void { 31 self.connects += 1; 32 std.debug.print("CONNECT #{d} to {s} (total events so far: {d})\n", .{ self.connects, host, self.count }); 33 } 34 35 pub fn onError(_: *Handler, err: anyerror) void { 36 std.debug.print("ERROR: {s}\n", .{@errorName(err)}); 37 } 38};