-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.ts
77 lines (67 loc) · 2.33 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { type FrameRequest } from '@coinbase/onchainkit'
import { getFrameMetadata } from '@coinbase/onchainkit/dist/lib/core/getFrameMetadata'
import { getFrameMessage } from '@coinbase/onchainkit/dist/lib/core/getFrameMessage'
import { Request, Response, renderOpenGraph, route } from './frameSupport'
const BASE_URL = 'https://frames.phatfn.xyz'
const image = 'https://i.imgur.com/belk1Ha.png'
async function GET(req: Request): Promise<Response> {
const secret = req.queries?.key ?? '';
const frameMetadata = getFrameMetadata({
buttons: [
{
label: 'FrameHub Template\nClick Here!',
},
],
image: image,
post_url: BASE_URL + req.path + `?key=${secret[0]}`,
});
return new Response(renderOpenGraph({
title: BASE_URL + req.path,
description: 'FrameHub',
openGraph: {
title: BASE_URL + req.path,
description: 'FrameHub',
images: [image],
},
other: frameMetadata,
}),
{ headers: { 'Cache-Control': 'public, max-age=86400' } }
);
}
async function getResponse(req: Request): Promise<Response> {
let accountAddress: string | undefined = '';
const secret = req.queries?.key ?? ''
const apiKey = req.secret?.apiKey ?? 'NEYNAR_API';
const body: FrameRequest = await req.json();
const { isValid, message } = await getFrameMessage(body, { neynarApiKey: `${apiKey}`});
if (isValid) {
accountAddress = message.interactor.verified_accounts[0];
}
const frameMetadata = getFrameMetadata({
buttons: [
{
label: `Phat Hello to ${accountAddress}`,
},
],
image: image,
post_url: BASE_URL + req.path + `?key=${secret[0]}`,
});
return new Response(renderOpenGraph({
title: BASE_URL + req.path,
description: 'FrameHub',
openGraph: {
title: BASE_URL + req.path,
description: 'FrameHub',
images: [image],
},
other: frameMetadata,
}),
{ headers: { 'Cache-Control': 'public, max-age=86400' } }
);
}
async function POST(req: any): Promise<Response> {
return getResponse(req);
}
export default async function main(request: string) {
return await route({GET, POST}, request)
}