Add Metamigo webhooks
This commit is contained in:
parent
87c2c2f8b7
commit
242f3cf6b8
15 changed files with 81 additions and 76 deletions
|
|
@ -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=",
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
@ -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=");
|
||||
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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={() => {}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
package-lock.json
generated
1
package-lock.json
generated
|
|
@ -136,6 +136,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",
|
||||
|
|
|
|||
|
|
@ -71,7 +71,6 @@ export const List: FC<ListProps> = ({ title, rows, columns, onRowClick, buttons
|
|||
pageSizeOptions={[5, 10, 25]}
|
||||
paginationMode="client"
|
||||
sx={{ height: "100vh" }}
|
||||
rowBuffer={30}
|
||||
rowHeight={46}
|
||||
scrollbarSize={0}
|
||||
disableVirtualization
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue