Skip to content

Commit

Permalink
extract query params
Browse files Browse the repository at this point in the history
  • Loading branch information
RamRamez committed Aug 23, 2024
1 parent 484a111 commit dcd094e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
source ~/.nvm/nvm.sh
cd farcaster-praise-bot
git pull origin main
npm install -g bun
pm2 stop all
bun install
pm2 start all
32 changes: 30 additions & 2 deletions src/routes/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,46 @@ const bot = async (req: Request) => {
}
const body = await req.text();
const hookData = JSON.parse(body);
const { channel, author, text, mentioned_profiles } = hookData;
const praiseHandle = process.env.PRAISE_FARCASTER_HANDLE;
const praiseReceiver = mentioned_profiles.find((profile: any) => profile.username !== praiseHandle)
if (!praiseReceiver) {
await neynarClient.publishCast(
process.env.SIGNER_UUID,
`gm ${author.username}! Please mention a Farcaster account to praise for`,
{
replyTo: hookData.data.hash,
}
);
}
let index = text.indexOf('for');
let reason
if (index !== -1) {
reason = text.substring(index);
} else {
// There's no 'for' in the praise
reason = text.split(praiseReceiver.username)[1]
}
const query = {
reason,
channel,
giver: author.username,
recipient: praiseReceiver.verified_addresses.eth_addresses[0] || praiseReceiver.custody_address
};

console.log('--------------------')
console.log(hookData.data)
console.log('--------------------')
console.log(query)
console.log('--------------------')

const reply = await neynarClient.publishCast(
process.env.SIGNER_UUID,
`gm ${hookData.data.author.username}`,
`gm ${author.username}`,
{
embeds: [
{
url: process.env.APP_URL!,
url: process.env.APP_URL + '?' + new URLSearchParams(query),
},
],
replyTo: hookData.data.hash,
Expand Down

0 comments on commit dcd094e

Please sign in to comment.