Skip to content

Commit

Permalink
add replyAttestation to routes
Browse files Browse the repository at this point in the history
  • Loading branch information
RamRamez committed Aug 31, 2024
1 parent 6e526ee commit 7a230cb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import routes from "./src/routes/routes.js";
import bot from "./src/routes/bot.js";
import {frogApp} from "./src/routes/frog.js";
import replyAttestation from "./src/routes/replyAttestation.js";

if (typeof Bun !== 'undefined') {
const server = Bun.serve({
Expand All @@ -13,6 +14,8 @@ if (typeof Bun !== 'undefined') {
return new Response('This is my Farcaster praise bot', { status: 200 });
case routes.bot:
return await bot(req);
case routes.replyAttestation:
return await replyAttestation(req);
case routes.frog:
return await frogApp.fetch(req);
default:
Expand Down
1 change: 1 addition & 0 deletions src/routes/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ If you want to give praise to someone and mint an attestation, try casting in th
return new Response('There\'s no \'praise\' in the cast', { status: 200 });
}
const praiseHandle = process.env.PRAISE_FARCASTER_HANDLE;
// TODO: Should consider only first mention as praise receiver
const praiseReceiver = mentioned_profiles.find((profile: any) => profile.username !== praiseHandle)
if (!praiseReceiver) {
await neynarClient.publishCast(
Expand Down
30 changes: 30 additions & 0 deletions src/routes/replyAttestation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import neynarClient from "../helpers/neynarClient.js";

const baseAttestationScan = 'https://base.easscan.org/attestation/view/';

const replyAttestation = async (req: Request) => {
if (!process.env.SIGNER_UUID) {
throw new Error("Make sure you set SIGNER_UUID in your .env file");
}
const body = await req.text();
const data = JSON.parse(body);
const { attestationHash, praiseHash } = data;
if (!attestationHash || !praiseHash) {
throw new Error("attestationHash and praiseHash are required");
}
await neynarClient.publishCast(
process.env.SIGNER_UUID,
`Thanks for using Praise and spreading gratitude and thankfulness!
This is the attestation URL you just minted:
${baseAttestationScan + attestationHash}`,
{
replyTo: praiseHash,
}
);
console.log("Replied with Attestation URL!");
return new Response('Attestation URL sent!', { status: 200 });
}

export default replyAttestation;
1 change: 1 addition & 0 deletions src/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const routes = {
home: '/',
bot: '/bot',
frog: '/frog',
replyAttestation: '/reply-attestation',
}

export default routes;

0 comments on commit 7a230cb

Please sign in to comment.