From 7a230cb5a57823dd6bb4735b47ee97980c1aafd2 Mon Sep 17 00:00:00 2001 From: Ramin Date: Sun, 1 Sep 2024 01:19:02 +0330 Subject: [PATCH] add replyAttestation to routes --- index.ts | 3 +++ src/routes/bot.ts | 1 + src/routes/replyAttestation.ts | 30 ++++++++++++++++++++++++++++++ src/routes/routes.ts | 1 + 4 files changed, 35 insertions(+) create mode 100644 src/routes/replyAttestation.ts diff --git a/index.ts b/index.ts index 43cbc4e..1823356 100644 --- a/index.ts +++ b/index.ts @@ -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({ @@ -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: diff --git a/src/routes/bot.ts b/src/routes/bot.ts index 85f46cc..3bb65ee 100644 --- a/src/routes/bot.ts +++ b/src/routes/bot.ts @@ -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( diff --git a/src/routes/replyAttestation.ts b/src/routes/replyAttestation.ts new file mode 100644 index 0000000..49fc721 --- /dev/null +++ b/src/routes/replyAttestation.ts @@ -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; diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 3cc5de7..a4e1a13 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -2,6 +2,7 @@ const routes = { home: '/', bot: '/bot', frog: '/frog', + replyAttestation: '/reply-attestation', } export default routes;