Skip to content

Commit 9965461

Browse files
authored
Merge pull request #267 from framesjs/docs/hub-context-middleware
docs: farcasterHubContext middleware usage instructions
2 parents 6c4d048 + 6c1a22c commit 9965461

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

.changeset/four-cheetahs-tease.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"docs": patch
3+
---
4+
5+
docs: improve farcasterHubContext docs

docs/pages/middleware/farcasterHubContext.mdx

+24-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
Fetches additional context about the message from a Farcaster hub.
44

5-
## Usage
5+
## Setup
6+
7+
Add the `farcasterHubContext` middleware to your `createFrames` call:
68

7-
```tsx
9+
```tsx [frames.ts]
810
// ...
911
import { farcasterHubContext } from "frames.js/middleware";
1012

@@ -18,6 +20,26 @@ const frames = createFrames({
1820
});
1921
```
2022

23+
## Usage
24+
25+
Use the added context in your message handler:
26+
27+
```tsx [route.tsx]
28+
import { frames } from "./frames";
29+
30+
export const POST = frames(async (ctx) => {
31+
if (!ctx.message?.isValid) {
32+
throw new Error("Invalid message");
33+
}
34+
35+
return {
36+
image: <div tw="flex">Message from {ctx.message?.requesterFid}</div>,
37+
};
38+
});
39+
```
40+
41+
For all the added context see the [`getFrameMessage`](/reference/js/getFrameMessage) function reference.
42+
2143
## Options
2244

2345
### `hubHttpUrl`

0 commit comments

Comments
 (0)