This application allows users to generate social media posts using OpenAI's API and save them to a Google Spreadsheet. It's built with Next.js 14 app router and TypeScript.
- Generate social media posts using OpenAI's API
- Save generated posts to a Google Spreadsheet
- The Generated posts are saved to the Google Spreadsheet only when the user clicks on the save button.
- User can copy the generated post to the clipboard by clicking on the copy button.
- Retrieve and display saved posts (Bonus feature)
- Error handling and user feedback for API requests (Bonus feature)
- Responsive design
- Toast notifications for user feedback
You can view and edit the Google Spreadsheet used for storing posts here.
Here's a brief overview of the folder structure:
-
app/
: Contains the main pages and API routes.page.tsx
: The home page with the post generation interface.posts/page.tsx
: Displays retrieved posts (Bonus feature).api/
: Contains API route handlers.chat/route.ts
: Handles post generation using OpenAI API.sheet/route.ts
: POST handler Manages saving posts to Google Sheets.sheet/route.ts
: GET handler Retrieves posts from Google Sheets (Bonus feature).
-
components/
: Contains reusable React components.ChatForm.tsx
: The form for entering prompts.header.tsx
: The header component.HowToSteps.tsx
: The steps for generating posts.PostCard.tsx
: Displays a single post.sidebar.tsx
: The sidebar component.message-item.tsx
: Displays chat messages.WelcomeSection.tsx
: The welcome section in chat.ui/
: Contains UI components.
-
lib/
: Contains utility functions and server actions.utils.ts
: Utility functions used across the application./actions/actions.ts
: Contains Next.js Server actions .
-
public/
: Stores static assets.
This application is deployed using Vercel. You can access it at https://moondev-theta.vercel.app/.
- Fork this repository to your GitHub account.
- Sign up for a Vercel account if you haven't already.
- Create a new project in Vercel and import your forked repository.
- Set up the following environment variables in your Vercel project settings:
OPENAI_API_KEY
: Your OpenAI API keyGOOGLE_SHEETS_PRIVATE_KEY
: Your Google service account private keyGOOGLE_SHEETS_CLIENT_EMAIL
: Your Google service account emailGOOGLE_SHEETS_SPREADSHEET_ID
: Your Google Spreadsheet ID
- Deploy the project.
- Clone the repository:
git clone https://github.com/Mriganka5137/moondev.git
cd moondev
- Install dependencies:
pnpm install
- Set up the following environment variables in a
.env.local
file:OPENAI_API_KEY
: Your OpenAI API keyGOOGLE_SHEETS_PRIVATE_KEY
: Your Google service account private keyGOOGLE_SHEETS_CLIENT_EMAIL
: Your Google service account emailGOOGLE_SHEETS_SPREADSHEET_ID
: Your Google Spreadsheet ID
- Run the development server:
pnpm run dev
- Open http://localhost:3000 with your browser to see the result.
- Implemented retrieval and display of generated posts from the Google Spreadsheet.
- Added error handling and user feedback for API requests.
The API keys used in this project are for development purposes only. In a production environment, these should be kept secure and not exposed in the client-side code.