diff --git a/lib/types/farcaster-types.js b/lib/types/farcaster-types.js --- a/lib/types/farcaster-types.js +++ b/lib/types/farcaster-types.js @@ -84,3 +84,8 @@ +data: NeynarWebhookCastCreatedData, ... }; + +export type NeynarPostCastResponse = { + +success: boolean, + ... +}; 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 @@ -7,6 +7,7 @@ NeynarChannel, NeynarUser, NeynarCast, + NeynarPostCastResponse, } from '../types/farcaster-types.js'; type FetchRelevantFollowersResponse = { @@ -357,6 +358,38 @@ throw error; } } + + async postCast( + signerUUID: string, + parent: string, + text: string, + ): Promise { + const url = getNeynarURL('2', 'cast', {}); + const body = { + signer_uuid: signerUUID, + parent, + text, + }; + try { + const response = await fetch(url, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'api_key': this.apiKey, + 'Content-Type': 'application/json', + }, + body: JSON.stringify(body), + }); + + return await response.json(); + } catch (error) { + console.log( + 'Failed to post Farcaster cast:', + getMessageForException(error) ?? 'unknown', + ); + throw error; + } + } } export { NeynarClient };