Creating a webhook that listens to casts
Creating a bot that replies to the casts
Creating frames dynamically using the neynar SDK
Setting up our server
Creating a bun server
I am using a bun server for the sake of simplicity of this guide, but you can use express, Next.js api routes or any server that you wish to use! Here’s a serverless example using next.js api routes created by @df. Create a new server by entering the following commands in your terminal:@neynar/nodejs-sdk
, so let’s install that as well:
index.ts
:
Serve the app via ngrok
We’ll serve the app using ngrok to use this URL in the webhook. If you don’t already have it installed, install it from here. Once it’s installed, authenticate using your auth token and serve your app using this command:Free endpoints like ngrok, localtunnel, etc. can have issues because service providers start blocking events over a certain limit
Creating a webhook
We need to create a webhook on the neynar dashboard that will listen for certain words/mentions and call our server which will then reply to the cast. So, head to the neynar dashboard and go to the webhooks tab. Click on new webhook and enter the details as such:Creating the bot
Head over to the app section in the neynar dashboard and copy the signer uuid for your account:.env
file in the root of your project and add the following:
SIGNER_UUID
and the neynar api key to the NEYNAR_API_KEY
which you can get from the overview section of the neynar dashboard:
neynarClient.ts
file and add the following:
index.ts
and add this inside the try block:
index.ts
file:
Creating the frame
We’ll now generate a unique frame for every user on the fly using neynar frames. To create the frame, add the following code in theindex.ts
before the reply:
index.ts
file should look similar to this complete example.
Don’t forget to restart your server after making these changes!