Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-alpha.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
nekofar committed Feb 4, 2024
2 parents 7a6509a + 31b68f8 commit 6155b45
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## [1.0.0-alpha.6] - 2024-02-04

### Refactor

- Enhance code with best practices and optimizations
- Add `FrameSignaturePacket` to the types

## [1.0.0-alpha.5] - 2024-02-04

### Features
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "farcaster-frames-template",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"keywords": [
"farcaster",
"frames",
Expand Down
55 changes: 29 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { serve } from '@hono/node-server'
import { Hono } from 'hono'
import { html } from 'hono/html'
import type { FrameSignaturePacket } from './types'

const app = new Hono()

app.get('/', (c) => {
const imageText = 'Hello World'
const frameImage = `https://placehold.co/600x400?text=${imageText}`
const frameImage = `https://placehold.co/600x400?text=Hello+World`
const framePostUrl = c.req.url

return c.html(html`
Expand All @@ -30,34 +30,37 @@ app.get('/', (c) => {
})

app.post('/', async (c) => {
const body = await c.req.json()
const {
untrustedData: { buttonIndex, inputText },
} = body
try {
const body = await c.req.json<FrameSignaturePacket>()
const { buttonIndex, inputText } = body.untrustedData

const backgroundColors = [undefined, 'green', 'purple', 'red', 'blue']
const backgroundColors = ['green', 'purple', 'red', 'blue']

const imageText = inputText || 'Hello World'
const imageColor = backgroundColors[buttonIndex]
const imageText = encodeURIComponent(inputText || 'Hello World')
const imageColor = backgroundColors[buttonIndex - 1] || 'white'

const frameImage = `https://placehold.co/600x400/${imageColor}/white?text=${imageText}`
const framePostUrl = c.req.url
const frameImage = `https://placehold.co/600x400/${imageColor}/white?text=${imageText}`
const framePostUrl = c.req.url

return c.html(html`
<html lang="en">
<head>
<meta property="fc:frame" content="vNext" />
<meta property="fc:frame:image" content="${frameImage}" />
<meta property="fc:frame:post_url" content="${framePostUrl}" />
<meta property="fc:frame:input:text" content="Enter a message" />
<meta property="fc:frame:button:1" content="Green" />
<meta property="fc:frame:button:2" content="Purple" />
<meta property="fc:frame:button:3" content="Red" />
<meta property="fc:frame:button:4" content="Blue" />
<title>Farcaster Frames</title>
</head>
</html>
`)
return c.html(html`
<html lang="en">
<head>
<meta property="fc:frame" content="vNext" />
<meta property="fc:frame:image" content="${frameImage}" />
<meta property="fc:frame:post_url" content="${framePostUrl}" />
<meta property="fc:frame:input:text" content="Enter a message" />
<meta property="fc:frame:button:1" content="Green" />
<meta property="fc:frame:button:2" content="Purple" />
<meta property="fc:frame:button:3" content="Red" />
<meta property="fc:frame:button:4" content="Blue" />
<title>Farcaster Frames</title>
</head>
</html>
`)
} catch (error) {
console.error(error)
return c.json({ error: 'Invalid request' }, 400)
}
})

const port = 3000
Expand Down
18 changes: 18 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export type FrameSignaturePacket = {
untrustedData: {
fid: number;
url: string;
messageHash: string;
timestamp: number;
network: number;
buttonIndex: number;
inputText?: string;
castId: {
fid: number;
hash: string;
};
};
trustedData: {
messageBytes: string;
};
};

0 comments on commit 6155b45

Please sign in to comment.