try @nostr-ts/common
This commit is contained in:
parent
bec30f2ab0
commit
c5e5e24802
3 changed files with 161 additions and 795 deletions
65
src/nostr.ts
65
src/nostr.ts
|
|
@ -1,7 +1,9 @@
|
|||
import pino from "pino";
|
||||
import { lambdaRequestTracker, pinoLambdaDestination } from "pino-lambda";
|
||||
import { MicroBlogBackend } from "./pocketbase";
|
||||
import NDK, { type NDKFilter } from "@nostr-dev-kit/ndk";
|
||||
import { RelayClient } from "@nostr-ts/node";
|
||||
import { NFilters, EventsRequest, CLIENT_MESSAGE_TYPE } from "@nostr-ts/common";
|
||||
import Client from "pocketbase";
|
||||
|
||||
// custom destination formatter
|
||||
const destination = pinoLambdaDestination();
|
||||
|
|
@ -10,15 +12,6 @@ const withRequest = lambdaRequestTracker();
|
|||
|
||||
const pb = new MicroBlogBackend(logger);
|
||||
|
||||
const npub = "npub1tcmsctewqs3yy0a9q2xh6r0tlm97dxdqcuehuyumyh4jkyfdg5xsmyvw2y";
|
||||
const ndk = new NDK({
|
||||
explicitRelayUrls: [
|
||||
"wss://nos.lol",
|
||||
// "wss://nostr.wine",
|
||||
// "wss://nostr.einundzwanzig.space",
|
||||
],
|
||||
});
|
||||
|
||||
// const feedEvents = await npubA.feed();
|
||||
|
||||
// type MastodonPost = {
|
||||
|
|
@ -103,8 +96,51 @@ const ndk = new NDK({
|
|||
exports.run = async (event: any, context: any) => {
|
||||
withRequest(event, context);
|
||||
logger.info("connecting to nostr relays");
|
||||
await ndk.connect();
|
||||
logger.info("connected to nostr relays");
|
||||
const npub =
|
||||
"npub1tcmsctewqs3yy0a9q2xh6r0tlm97dxdqcuehuyumyh4jkyfdg5xsmyvw2y";
|
||||
// "wss://nos.lol",
|
||||
// "wss://nostr.wine",
|
||||
// "wss://nostr.einundzwanzig.space",
|
||||
let client = new RelayClient([
|
||||
{
|
||||
url: "wss://travis-shears-nostr-relay-v2.fly.dev/",
|
||||
read: true,
|
||||
write: false,
|
||||
},
|
||||
// {
|
||||
// url: "wss://nos.lol",
|
||||
// read: true,
|
||||
// write: false,
|
||||
// },
|
||||
// {
|
||||
// url: "wss://nostr.einundzwanzig.space",
|
||||
// read: true,
|
||||
// write: false,
|
||||
// },
|
||||
]);
|
||||
const info = await client.getRelayInformation();
|
||||
logger.info({ info }, "relay info");
|
||||
|
||||
const filters = new NFilters();
|
||||
filters.addAuthor(npub);
|
||||
const req: EventsRequest = {
|
||||
filters,
|
||||
type: CLIENT_MESSAGE_TYPE.REQ,
|
||||
options: {
|
||||
timeoutIn: 10000,
|
||||
},
|
||||
};
|
||||
client.subscribe(req);
|
||||
|
||||
client.listen((payload) => {
|
||||
logger.info(
|
||||
{ info: payload.meta.info, url: payload.meta.url },
|
||||
"received event"
|
||||
);
|
||||
// logRelayMessage(payload.data);
|
||||
});
|
||||
client.disconnect();
|
||||
|
||||
// const lastSavedPostId = await pb.getLatestPostRemoteIDBySource("mastodon");
|
||||
// console.log({ lastSavedPostId });
|
||||
// const posts = await getPostUntilId({ lastSavedId: lastSavedPostId });
|
||||
|
|
@ -112,11 +148,6 @@ exports.run = async (event: any, context: any) => {
|
|||
// npub,
|
||||
// });
|
||||
// await user.fetchProfile();
|
||||
const filter: NDKFilter = { kinds: [1], authors: [npub] };
|
||||
const evt = await ndk.fetchEvent(filter, { closeOnEose: true });
|
||||
logger.info({ evt }, "Got event");
|
||||
|
||||
// logger.info({ profile: user.profile }, "Got user profile");
|
||||
|
||||
// for (const post of posts) {
|
||||
// logger.info({ post }, "saving post");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue