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 @@ -21,13 +21,18 @@ ... }; -type FetchFarcasterChannelsResponse = { +type FetchFarcasterChannelsPagedResponse = { +channels: $ReadOnlyArray, +next: { +cursor: ?string, }, }; +type FetchFarcasterChannelsResponse = { + +channels: $ReadOnlyArray, + ... +}; + type FetchUsersResponse = { +users: $ReadOnlyArray, }; @@ -128,7 +133,7 @@ }, }); - const json: FetchFarcasterChannelsResponse = await response.json(); + const json: FetchFarcasterChannelsPagedResponse = await response.json(); const { channels, next } = json; @@ -177,6 +182,36 @@ } } + async fetchFarcasterChannelsByIDs( + channelIDs: $ReadOnlyArray, + ): Promise { + const params: { [string]: string } = { + ids: channelIDs.join(','), + }; + + const url = getNeynarURL('2', 'channel/bulk', params); + + try { + const response = await fetch(url, { + method: 'GET', + headers: { + Accept: 'application/json', + api_key: this.apiKey, + }, + }); + + const json: FetchFarcasterChannelsResponse = await response.json(); + + return json.channels ? [...json.channels] : []; + } catch (error) { + console.log( + 'Failed to fetch Farcaster channel infos:', + getMessageForException(error) ?? 'unknown', + ); + throw error; + } + } + async getFarcasterUsers( fids: $ReadOnlyArray, ): Promise> { @@ -243,7 +278,7 @@ }, }); - const json: FetchFarcasterChannelsResponse = await response.json(); + const json: FetchFarcasterChannelsPagedResponse = await response.json(); const { channels, next } = json;