diff --git a/lib/utils/neynar-client.js b/lib/utils/neynar-client.js --- a/lib/utils/neynar-client.js +++ b/lib/utils/neynar-client.js @@ -33,6 +33,10 @@ +users: $ReadOnlyArray, }; +type FetchFarcasterChannelInfoResponse = { + +channel: NeynarChannel, +}; + const neynarBaseURL = 'https://api.neynar.com/'; const neynarURLs = { '1': `${neynarBaseURL}v1/farcaster/`, @@ -271,6 +275,39 @@ return farcasterChannels; } + + async fetchFarcasterChannelInfo( + channelID: string, + viewerFID: string, + ): Promise { + const params: { [string]: string } = { + id: channelID, + type: 'id', + viewer_fid: viewerFID, + }; + + const url = getNeynarURL('2', 'channel', params); + + try { + const response = await fetch(url, { + method: 'GET', + headers: { + Accept: 'application/json', + api_key: this.apiKey, + }, + }); + + const json: FetchFarcasterChannelInfoResponse = await response.json(); + + return json.channel; + } catch (error) { + console.log( + 'Failed to fetch Farcaster channel info:', + getMessageForException(error) ?? 'unknown', + ); + throw error; + } + } } export { NeynarClient };