A Next.js chat application that uses Adaptive Cards to generate and render dynamic, interactive responses. Learn more about Adaptive Cards
- Chat interface with AI-powered responses
- Dynamic rendering of Adaptive Cards for structured data (Generative UX)
- Interactive card elements (buttons, forms, etc.) supported by adaptive cards
- Card action handling via API endpoints
Adaptive Cards are a platform-agnostic way to exchange content in a common and consistent way. They are:
- Portable - Cards render natively across platforms and applications
- Expressive - Cards support rich layouts, inputs, and actions
- Open - The format is open-source and standardized
This project implements Adaptive Cards in a chat interface using:
- Next.js App Router for the application framework
- AI SDK for chat functionality
- Adaptive Cards SDK for rendering interactive cards
- Tailwind CSS for styling
-
AdaptiveCard Component (
app/adaptive-card.tsx
)- Renders Adaptive Cards from JSON
- Handles card actions and user interactions
- Communicates with the backend API
-
Chat API (
app/api/chat/route.ts
)- Processes chat messages
- Instructs the AI model to generate Adaptive Cards when appropriate
- Provides a welcome card for new users
-
Card Action API (
app/api/card-action/route.ts
)- Handles actions from Adaptive Cards (form submissions, button clicks, etc.)
- Processes different action types (feedback, quizzes, to-do items, etc.)
-
Adaptive Cards Utilities (
lib/adaptive-cards.ts
)- Provides card templates for common use cases
- Includes utility functions for working with cards
- Handles variable replacement in templates
Here's an example of a simple Adaptive Card:
{
"type": "AdaptiveCard",
"version": "1.5",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "Card Title"
},
{
"type": "TextBlock",
"text": "This is a simple Adaptive Card with text content.",
"wrap": true
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit",
"data": {
"action": "submitAction"
}
}
]
}
- Start a conversation in the chat interface
- For certain types of information, the AI will respond with an Adaptive Card
- Interact with the card elements (buttons, forms, etc.)
- Card actions will be processed by the backend API
- Node.js 18+
- npm or pnpm
-
Clone the repository
-
Install dependencies:
npm install
or
pnpm install
-
Create a
.env
file with your API keys:OPENAI_API_KEY=your_openai_api_key
-
Start the development server:
npm run dev
or
pnpm dev
-
Open http://localhost:3000 in your browser