|
1 | | -import { farcasterHubContext } from "frames.js/middleware"; |
2 | | -import { createFrames, Button } from "frames.js/next"; |
3 | | - |
4 | | -const frames = createFrames({ |
5 | | - basePath: '/frames', |
6 | | - middleware: [ |
7 | | - farcasterHubContext({ |
8 | | - // remove if you aren't using @frames.js/debugger or you just don't want to use the debugger hub |
9 | | - ...(process.env.NODE_ENV === "production" |
10 | | - ? {} |
11 | | - : { |
12 | | - hubHttpUrl: "http://localhost:3010/hub", |
13 | | - }), |
14 | | - }), |
15 | | - ], |
16 | | -}); |
| 1 | +import { Button } from "frames.js/next"; |
| 2 | +import { frames } from "./frames"; |
17 | 3 |
|
18 | 4 | const handleRequest = frames(async (ctx) => { |
| 5 | + if (!ctx.message) { |
| 6 | + return { |
| 7 | + image: ( |
| 8 | + <div> |
| 9 | + This is the initial frame which will be shown before the user has |
| 10 | + interacted with the frame. |
| 11 | + </div> |
| 12 | + ), |
| 13 | + buttons: [<Button action="post">Say hello</Button>], |
| 14 | + }; |
| 15 | + } |
| 16 | + |
| 17 | + if (!ctx.message.isValid) { |
| 18 | + throw new Error("Invalid message"); |
| 19 | + } |
| 20 | + |
19 | 21 | return { |
20 | | - image: ctx.message ? ( |
21 | | - <div |
22 | | - style={{ |
23 | | - display: "flex", |
24 | | - flexDirection: "column", |
25 | | - }} |
26 | | - > |
27 | | - GM, {ctx.message.requesterUserData?.displayName}! Your FID is{" "} |
| 22 | + image: ( |
| 23 | + <div> |
| 24 | + Hello {ctx.message.requesterUserData?.displayName}! Your FID is{" "} |
28 | 25 | {ctx.message.requesterFid} |
29 | | - {", "} |
30 | | - {ctx.message.requesterFid < 20_000 |
31 | | - ? "you're OG!" |
32 | | - : "welcome to the Farcaster!"} |
33 | | - </div> |
34 | | - ) : ( |
35 | | - <div |
36 | | - style={{ |
37 | | - display: "flex", |
38 | | - flexDirection: "column", |
39 | | - }} |
40 | | - > |
41 | | - Say GM |
42 | 26 | </div> |
43 | 27 | ), |
44 | | - buttons: !ctx.url.searchParams.has("saidGm") |
45 | | - ? [ |
46 | | - <Button action="post" target={{ query: { saidGm: true } }}> |
47 | | - Say GM |
48 | | - </Button>, |
49 | | - ] |
50 | | - : [], |
| 28 | + buttons: [], |
51 | 29 | }; |
52 | 30 | }); |
53 | 31 |
|
|
0 commit comments