Skip to content

Commit

Permalink
Merge pull request #1 from rifont/upgrade-framework
Browse files Browse the repository at this point in the history
refactor(api): streamline API routes and workflows
  • Loading branch information
rifont authored Jul 2, 2024
2 parents e4273f7 + 8129706 commit c925d4e
Show file tree
Hide file tree
Showing 19 changed files with 4,902 additions and 4,620 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/novu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Novu Sync

on:
workflow_dispatch:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
# https://github.com/novuhq/actions-novu-sync
- name: Sync State to Novu
uses: novuhq/actions-novu-sync@v2
with:
# The secret key used to authenticate with Novu Cloud
# To get the secret key, go to https://web.novu.co/api-keys.
# Required.
secret-key: ${{ secrets.NOVU_SECRET_KEY }}

# The publicly available endpoint hosting the bridge application
# where notification entities (eg. workflows, topics) are defined.
# Required.
bridge-url: https://novu-ai-digest.vercel.app/api/novu

# The Novu Cloud API URL to sync with.
# Optional.
# Defaults to https://api.novu.co
api-url: https://api.novu.co
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# AI Notification Digest

This is a [Novu](https://novu.co/) project bootstrapped with [`create-novu-app`](https://www.npmjs.com/package/create-novu-app).

![alt text](website.png)

## Getting Started

First, run the development server:
Start the Novu Dev Studio:

```bash
npx novu@latest dev
```

Then, run the development server:

```bash
npm run dev
Expand All @@ -14,23 +24,19 @@ pnpm dev
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
Open [http://localhost:4000](http://localhost:4000) in your browser to view the application.

## Learn More

To learn more about Next.js, take a look at the following resources:
To learn more about Novu, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
- [Novu Documentation](https://docs.novu.co/) - learn about Novu features and API.
- [Novu Quickstarts](https://docs.novu.co/quickstarts/overview) - an interactive Novu tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
You can check out [the Novu GitHub repository](https://github.com/novuhq/novu) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-novu-app&utm_campaign=create-novu-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
4 changes: 0 additions & 4 deletions app/api/echo/route.ts

This file was deleted.

10 changes: 3 additions & 7 deletions app/api/messages/route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { SUBSCRIBER_ID } from '@/constants/subscriber';
import { Novu } from '@novu/node';

const novu = new Novu(process.env.NOVU_API_KEY as string);
import { aiDigest } from '@/lib/novu/workflows';

export async function POST(request: Request) {
const res = await request.json();

await novu.trigger('ai-digest', {
to: {
subscriberId: SUBSCRIBER_ID,
},
await aiDigest.trigger({
to: [SUBSCRIBER_ID],
payload: {
message: res.message,
digestDuration: res.digestDuration,
Expand Down
18 changes: 2 additions & 16 deletions app/api/notifications/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { notificationSchemaJson } from '@/lib/novu/workflows';
import { OpenAI } from 'openai';

const openai = new OpenAI({
Expand All @@ -22,22 +23,7 @@ export async function GET(request: Request) {
{
name: "create_sample_notification",
description: "A sample notification for a user.",
parameters: {
type: "object",
properties: {
message: {
type: "string",
description: "The message to be sent."
},
category: {
type: "string",
enum: ["Urgent", "Important", "Normal", "Low"],
description: "The priority of the message."
}
},
required: ["message", "category"],
additionalProperties: false,
}
parameters: notificationSchemaJson
}
],
});
Expand Down
4 changes: 4 additions & 0 deletions app/api/novu/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { serve } from "@novu/framework/next";
import { aiDigest } from "@/lib/novu/workflows";

export const { GET, POST, OPTIONS } = serve({ workflows: [aiDigest] });
155 changes: 0 additions & 155 deletions app/echo/client.ts

This file was deleted.

Loading

0 comments on commit c925d4e

Please sign in to comment.