Add Metamigo webhooks

This commit is contained in:
Darren Clarke 2024-04-21 08:11:24 +02:00
parent 87c2c2f8b7
commit 242f3cf6b8
15 changed files with 81 additions and 76 deletions

View file

@ -12,7 +12,7 @@ import { LeafcutterProvider } from "leafcutter-ui/components/LeafcutterProvider"
import { NextAppDirEmotionCacheProvider } from "tss-react/next/appDir";
import en from "leafcutter-ui/locales/en.json";
import fr from "leafcutter-ui/locales/fr.json";
import { LicenseInfo } from "@mui/x-date-pickers-pro";
import { LicenseInfo } from "@mui/x-license";
LicenseInfo.setLicenseKey(
"7c9bf25d9e240f76e77cbf7d2ba58a23Tz02NjU4OCxFPTE3MTU4NjIzMzQ2ODgsUz1wcm8sTE09c3Vic2NyaXB0aW9uLEtWPTI=",

View file

@ -10,7 +10,7 @@ import { GraphQLClient } from "graphql-request";
import { I18n } from "react-polyglot";
import { AdapterDateFns } from "@mui/x-date-pickers-pro/AdapterDateFnsV3";
import { LocalizationProvider } from "@mui/x-date-pickers-pro";
import { LicenseInfo } from "@mui/x-date-pickers-pro";
import { LicenseInfo } from "@mui/x-license";
import { locales, LeafcutterProvider } from "leafcutter-ui";
LicenseInfo.setLicenseKey(

View file

@ -71,7 +71,7 @@ export const List: FC<ListProps> = ({ title, entity, rows, columns }) => {
pageSizeOptions={[5, 10, 25]}
paginationMode="client"
sx={{ height: "100vh" }}
rowBuffer={30}
// rowBuffer={30}
rowHeight={46}
scrollbarSize={0}
disableVirtualization

View file

@ -43,9 +43,36 @@ interface Database {
WhatsAppBot: {
id: GeneratedAlways<string>;
userId: string;
phone: string;
password: string;
name: string;
phoneNumber: string;
createdBy: string;
createdAt: Date;
updatedAt: Date;
};
FacebookBot: {
id: GeneratedAlways<string>;
name: string;
createdBy: string;
createdAt: Date;
updatedAt: Date;
};
VoiceBot: {
id: GeneratedAlways<string>;
name: string;
createdBy: string;
createdAt: Date;
updatedAt: Date;
};
SignalBot: {
id: GeneratedAlways<string>;
name: string;
phoneNumber: string;
createdBy: string;
createdAt: Date;
updatedAt: Date;
};
}

View file

@ -67,6 +67,27 @@ const deleteBot = async (req: NextRequest) => {
return NextResponse.json({ response: "ok" });
};
const handleWebhook = async (req: NextRequest) => {
console.log({ req });
const { searchParams } = req.nextUrl;
const token = searchParams.get("hub.verify_token");
if (token !== process.env.FB_VERIFY_TOKEN) {
// return NextResponse.error("Invalid token", { status: 403 });
}
if (searchParams.get("hub.mode") === "subscribe") {
const challenge = searchParams.get("hub.challenge");
console.log(token);
console.log(challenge);
return new Response(challenge, { status: 200 }) as NextResponse;
}
return NextResponse.json({ response: "ok" });
};
export const Facebook: Service = {
getAllBots,
getOneBot,
@ -79,4 +100,5 @@ export const Facebook: Service = {
refreshBot,
createBot,
deleteBot,
handleWebhook,
};

View file

@ -45,3 +45,6 @@ export const createBot = async (req: NextRequest): Promise<NextResponse> =>
export const deleteBot = async (req: NextRequest): Promise<NextResponse> =>
getService(req)?.deleteBot(req);
export const handleWebhook = async (req: NextRequest): Promise<NextResponse> =>
getService(req)?.handleWebhook(req);

View file

@ -12,4 +12,5 @@ export interface Service {
refreshBot: (req: NextRequest) => Promise<NextResponse>;
createBot: (req: NextRequest) => Promise<NextResponse>;
deleteBot: (req: NextRequest) => Promise<NextResponse>;
handleWebhook: (req: NextRequest) => Promise<NextResponse>;
}

View file

@ -0,0 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
const handleRequest = async (req: NextRequest, res: NextResponse) => {
return NextResponse.json({ message: "ok" });
};
export { handleRequest as GET, handleRequest as POST };

View file

@ -1,6 +1,6 @@
import type { Metadata } from "next";
import { InternalLayout } from "./_components/InternalLayout";
import { LicenseInfo } from "@mui/x-date-pickers-pro";
import { LicenseInfo } from "@mui/x-license";
LicenseInfo.setLicenseKey("7c9bf25d9e240f76e77cbf7d2ba58a23Tz02NjU4OCxFPTE3MTU4NjIzMzQ2ODgsUz1wcm8sTE09c3Vic2NyaXB0aW9uLEtWPTI=");

View file

@ -1,3 +1,6 @@
export default function Page() {
import { db } from "@/app/_lib/database";
export default async function Page() {
const rows = await db.selectFrom("WhatsAppBot").
return <h1>Whatsapp View</h1>;
}

View file

@ -2,8 +2,9 @@
import { GridColDef } from "@mui/x-data-grid-pro";
import { List } from "ui";
import { db } from "@/app/_lib/database";
export default function Page() {
export default async function Page() {
const columns: GridColDef[] = [
{
field: "id",
@ -31,75 +32,14 @@ export default function Page() {
},
];
const rows = [
{
id: 1,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: 2,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: 3,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: 4,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: 5,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: 6,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: 7,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: 8,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: 9,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: 10,
phoneNumber: "1234567890",
createdAt: new Date(),
updatedAt: new Date(),
},
];
const rows = await db.selectFrom("WhatsAppBot").selectAll().execute();
return (
<List
title="Whatsapp Bots"
entity="whatsapp"
rows={rows}
columns={columns}
onRowClick={() => {}}
/>
);
}

View file

@ -19,6 +19,7 @@
"@mui/material-nextjs": "^5.15.11",
"@mui/x-data-grid-pro": "^7.1.1",
"@mui/x-date-pickers-pro": "^7.1.1",
"@mui/x-license": "^7.1.1",
"date-fns": "^3.6.0",
"kysely": "^0.26.1",
"material-ui-popup-state": "^5.1.0",
@ -42,7 +43,7 @@
"@types/react-dom": "^18",
"eslint": "^9",
"eslint-config-next": "14.1.4",
"typescript": "^5",
"ts-config": "*"
"ts-config": "*",
"typescript": "^5"
}
}