Skip to content

Commit

Permalink
[lib] add post cast to neynar client
Browse files Browse the repository at this point in the history
Summary:
This implements posting a cast using the neynar client.

Followed https://docs.neynar.com/reference/post-cast almost exactly.

Depends on D13783

Test Plan:
Unfortunately, something seems to be wrong with the signer uuid configured in our comm neynar account. Debugging, but will ensure a reply cast is properly posted bofore landing

```
[NODEM]   code: 'NotFound',
[NODEM]   message: 'Signer not found.',
[NODEM]   property: 'signer_uuid'
[NODEM] }
```

Reviewers: ashoat, varun

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D13784
  • Loading branch information
wyilio committed Oct 31, 2024
1 parent db09962 commit e2c7376
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/types/farcaster-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ export type NeynarWebhookCastCreatedEvent = {
+data: NeynarWebhookCastCreatedData,
...
};

export type NeynarPostCastResponse = {
+success: boolean,
...
};
33 changes: 33 additions & 0 deletions lib/utils/neynar-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
NeynarChannel,
NeynarUser,
NeynarCast,
NeynarPostCastResponse,
} from '../types/farcaster-types.js';

type FetchRelevantFollowersResponse = {
Expand Down Expand Up @@ -357,6 +358,38 @@ class NeynarClient {
throw error;
}
}

async postCast(
signerUUID: string,
parent: string,
text: string,
): Promise<NeynarPostCastResponse> {
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 };

0 comments on commit e2c7376

Please sign in to comment.