Skip to content

feat: working farcaster client with neynar#570

Merged
lalalune merged 9 commits into
elizaOS:mainfrom
sayangel:farcaster-neynar-client
Dec 7, 2024
Merged

feat: working farcaster client with neynar#570
lalalune merged 9 commits into
elizaOS:mainfrom
sayangel:farcaster-neynar-client

Conversation

@sayangel
Copy link
Copy Markdown
Contributor

Relates to:

Farcaster client: #300
Modification of open PR: #386

Risks

Low

Background

What does this PR do?

Adds a farcaster-client package so that Eliza agents can post to Farcaster. This PR modifies an existing Farcaster client PR to use Neynar instead of a direct hub. This makes it easier for people to deploy hubs and makes it easier to add additional features in the future using Neynar's APIs for interacting with Farcaster data.

What kind of change is this?

Features (non-breaking change which adds functionality)

Documentation changes needed?

Needs documentation on how to create a signer that can submit messages to Farcaster (via Neynar).

Testing

I have tested this PR by running a local eliza agent that is making posts on Farcaster via the Yoinker account: https://warpcast.com/yoinker

All the accounts in this cast have been created by a local Eliza instance.

Where should a reviewer start?

  • Populate the new Farcaster env variables
  • Add "farcaster" client to your character
  • Run the agent
  • Verify that a cast is made on startup

Detailed testing steps

@rubinovitz
Copy link
Copy Markdown
Contributor

Thanks! Neynar is The Way.

@bmgalego
Copy link
Copy Markdown
Contributor

can you include #386 so it adds my commits too

Comment thread .env.example Outdated
# Farcaster Neynar Configuration
FARCASTER_FID=
FARCASTER_NEYNAR_SIGNER_UUID=
FARCASTER_NEYNAR_API_KEY= No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayangel Add comments for the newly added environment variables (FARCASTER_FID, FARCASTER_NEYNAR_SIGNER_UUID, FARCASTER_NEYNAR_API_KEY) to explain what each variable is used for and any format restrictions. This will help developers understand how to set up these configurations correctly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw does neynar signer uuid is the client id?

Comment thread agent/package.json
"@ai16z/client-auto": "workspace:*",
"@ai16z/client-direct": "workspace:*",
"@ai16z/client-discord": "workspace:*",
"@ai16z/client-farcaster": "workspace:*",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayangel Ensure that you review and update the documentation to reflect this new dependency.

Comment thread packages/client-farcaster/package.json Outdated
@@ -0,0 +1,19 @@
{
"name": "@ai16z/client-farcaster",
"version": "0.0.1",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayangel Review the new package’s version (0.0.1). Consider versioning best practices see semver.org

Comment thread packages/client-farcaster/package.json Outdated
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --watch"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayangel add both the lint and test scripts, refer to other packages to get more details about their implementations.

async stop() {
await Promise.all([this.posts.stop(), this.interactions.stop()]);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayangel Ensure the new client-farcaster package is covered by tests, including unit tests and integration tests, to verify its functionality.

async stop() {
await Promise.all([this.posts.stop(), this.interactions.stop()]);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayangel Update or add relevant documentation, such as the README, with information on the new package and environment variables.

Ensure to add any documentation for developers on how to configure the newly added @ai16z/client-farcaster and related environment variables.

@sayangel sayangel requested a review from bartrtl December 3, 2024 04:58
@sayangel sayangel requested a review from bartrtl December 4, 2024 18:14
Copy link
Copy Markdown
Contributor

@mcp97 mcp97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM added some nits but overall amazing work! Please add a screengrab of successful run if you can thanks so much! Amazing work!

}
} catch (err) {
if (isApiErrorResponse(err)) {
console.log(err.response.data);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use elizaLogger everywhere before throwing and not console log please thanks :)

});
const cast = {
hash: response.cast.hash,
//parentHash: cast.parent_hash,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this

fid: request.fid,
limit: request.pageSize,
});
//console.log(response);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

});
const result = await this.neynar.fetchBulkUsers({ fids: [fid] });
if (!result.users || result.users.length < 1) {
console.log("getUserDataByFid ERROR");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

return {
timeline,
nextPageToken: results.nextPageToken,
//TODO implement paging
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add an issue for this and reference it here


if (!memory.content.text) {
console.log("skipping cast with no text", cast.id);
console.log("skipping cast with no text", cast.hash);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

if (!response.text) return;

try {
console.log(`Replying to cast ${cast.hash}.`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

Comment on lines 51 to 53
// const farcasterUserName =
// this.runtime.getSetting("FARCASTER_USERNAME")!;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this

client: this.client,
runtime: this.runtime,
signer: this.signer,
//: this.signer,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

roomId
);

console.log(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

@lalalune lalalune merged commit cec95ac into elizaOS:main Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants