mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-21 02:16:12 -05:00
use neynar notifs
This commit is contained in:
@@ -2,6 +2,9 @@ import { NeynarAPIClient } from '@neynar/nodejs-sdk';
|
||||
|
||||
let neynarClient: NeynarAPIClient | null = null;
|
||||
|
||||
// Example usage:
|
||||
// const client = getNeynarClient();
|
||||
// const user = await client.lookupUserByFid(fid);
|
||||
export function getNeynarClient() {
|
||||
if (!neynarClient) {
|
||||
const apiKey = process.env.NEYNAR_API_KEY;
|
||||
@@ -13,6 +16,46 @@ export function getNeynarClient() {
|
||||
return neynarClient;
|
||||
}
|
||||
|
||||
// Example usage:
|
||||
// const client = getNeynarClient();
|
||||
// const user = await client.lookupUserByFid(fid);
|
||||
type SendFrameNotificationResult =
|
||||
| {
|
||||
state: "error";
|
||||
error: unknown;
|
||||
}
|
||||
| { state: "no_token" }
|
||||
| { state: "rate_limit" }
|
||||
| { state: "success" };
|
||||
|
||||
export async function sendNeynarFrameNotification({
|
||||
fid,
|
||||
title,
|
||||
body,
|
||||
}: {
|
||||
fid: number;
|
||||
title: string;
|
||||
body: string;
|
||||
}): Promise<SendFrameNotificationResult> {
|
||||
try {
|
||||
const client = getNeynarClient();
|
||||
const targetFids = [fid];
|
||||
const notification = {
|
||||
title,
|
||||
body,
|
||||
target_url: process.env.NEXT_PUBLIC_URL,
|
||||
};
|
||||
|
||||
const result = await client.publishFrameNotifications({
|
||||
targetFids,
|
||||
notification
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
return { state: "success" };
|
||||
} else if (result.status === 429) {
|
||||
return { state: "rate_limit" };
|
||||
} else {
|
||||
return { state: "error", error: result.error || "Unknown error" };
|
||||
}
|
||||
} catch (error) {
|
||||
return { state: "error", error };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user