-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from framesjs/feat/cast-actions-support
feat: cast actions support
- Loading branch information
Showing
9 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"frames.js": minor | ||
--- | ||
|
||
feat: allow arbitrary response in frames handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"framesjs-starter": patch | ||
--- | ||
|
||
feat: cast actions example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: "Cast Actions" | ||
description: "A guide to demonstrate how to create cast actions with Frames.js" | ||
--- | ||
|
||
# Cast Actions | ||
|
||
The [Cast Actions](https://warpcast.notion.site/Frames-Cast-Actions-v1-84d5a85d479a43139ea883f6823d8caa) specification lets you define actions that can be performed on a cast. This guide will show you how to create cast actions with Frames.js. | ||
|
||
## Example | ||
|
||
[See the example on GitHub](https://github.com/framesjs/frames.js/tree/main/examples/framesjs-starter/app/examples/new-api-cast-actions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
examples/framesjs-starter/app/examples/new-api-cast-actions/frames/frames.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createFrames } from "frames.js/next"; | ||
|
||
export const frames = createFrames({ | ||
basePath: "/examples/new-api-cast-actions/frames", | ||
}); |
31 changes: 31 additions & 0 deletions
31
examples/framesjs-starter/app/examples/new-api-cast-actions/frames/route.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable react/jsx-key */ | ||
import { Button } from "frames.js/next"; | ||
import { frames } from "./frames"; | ||
import { constructCastActionUrl } from "../utils"; | ||
|
||
export const GET = frames(async (ctx) => { | ||
const currentUrl = new URL(ctx.url.toString()); | ||
currentUrl.pathname = "/examples/new-api-cast-actions/frames"; | ||
|
||
const installActionUrl = constructCastActionUrl({ | ||
actionType: "post", | ||
icon: "number", | ||
name: "Check FID", | ||
postUrl: currentUrl.toString(), | ||
}); | ||
|
||
return { | ||
image: <div>FID Action</div>, | ||
buttons: [ | ||
<Button action="link" target={installActionUrl}> | ||
Install | ||
</Button>, | ||
], | ||
}; | ||
}); | ||
|
||
export const POST = frames(async (ctx) => { | ||
return Response.json({ | ||
message: `The user's FID is ${ctx.message?.castId?.fid}`, | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
examples/framesjs-starter/app/examples/new-api-cast-actions/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Link from "next/link"; | ||
import { currentURL, vercelURL } from "../../utils"; | ||
import { createDebugUrl } from "../../debug"; | ||
import type { Metadata } from "next"; | ||
import { fetchMetadata } from "frames.js/next"; | ||
|
||
export async function generateMetadata(): Promise<Metadata> { | ||
return { | ||
title: "New api example", | ||
description: "This is a new api example", | ||
other: { | ||
...(await fetchMetadata( | ||
new URL( | ||
"/examples/new-api-cast-actions/frames", | ||
vercelURL() || "http://localhost:3000" | ||
) | ||
)), | ||
}, | ||
}; | ||
} | ||
|
||
export default async function Home() { | ||
const url = currentURL("/examples/new-api-cast-actions"); | ||
|
||
return ( | ||
<div> | ||
New api cast actions example.{" "} | ||
<Link href={createDebugUrl(url)} className="underline"> | ||
Debug | ||
</Link> | ||
</div> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
examples/framesjs-starter/app/examples/new-api-cast-actions/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
type CastActionParams = { | ||
/** The action name. Must be less than 30 characters. */ | ||
name: string; | ||
/** An [Octicons](https://primer.style/foundations/icons) icon name. */ | ||
icon: string; | ||
/** The action type. (Same type options as frame buttons). Only post is accepted in V1. */ | ||
actionType: "post"; | ||
postUrl: string; | ||
}; | ||
export function constructCastActionUrl(params: CastActionParams): string { | ||
// Validate the input parameters | ||
if (params.name.length > 30) { | ||
throw new Error("The action name must be less than 30 characters."); | ||
} | ||
|
||
if (params.actionType.toLowerCase() !== "post") { | ||
throw new Error('The action type must be "post" in V1.'); | ||
} | ||
|
||
// Construct the URL | ||
const baseUrl = "https://warpcast.com/~/add-cast-action"; | ||
const urlParams = new URLSearchParams({ | ||
name: params.name, | ||
icon: params.icon, | ||
actionType: params.actionType, | ||
postUrl: params.postUrl, | ||
}); | ||
|
||
return `${baseUrl}?${urlParams.toString()}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters