Skip to content

Commit

Permalink
feat: 🎸 simplify crisp testing (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
OdapX committed Oct 18, 2023
1 parent 1594557 commit 4b27895
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ SLACK_VERIFICATION_TOKEN=XXX
# Notion
NOTION_CLIENT_ID= XXXXX
NOTION_CLIENT_SECRET= XXXXXX

# Crisp
CRISP_WEBSITE_ID= XXXXXX
54 changes: 54 additions & 0 deletions apps/dashboard/pages/api/crisp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Cors from 'cors';
import { NextApiResponse } from 'next';

import {
createAuthApiHandler,
respond,
} from '@chaindesk/lib/createa-api-handler';
import runMiddleware from '@chaindesk/lib/run-middleware';
import { AppNextApiRequest } from '@chaindesk/lib/types/index';

const cors = Cors({
methods: ['GET', 'HEAD'],
});

const handler = createAuthApiHandler();

export async function getCrisp(req: AppNextApiRequest, res: NextApiResponse) {
const crisp_website_id = process.env.CRISP_WEBSITE_ID;
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>Test Crisp</h1>
<script type="text/javascript">
window.$crisp = [];
window.CRISP_WEBSITE_ID = '${crisp_website_id}';
(function () {
d = document;
s = d.createElement('script');
s.src = 'https://client.crisp.chat/l.js';
s.async = 1;
d.getElementsByTagName('head')[0].appendChild(s);
})();
</script>
</body>
</html>
`);
}
handler.get(respond(getCrisp));

export default async function wrapper(
req: AppNextApiRequest,
res: NextApiResponse
) {
await runMiddleware(req, res, cors);

return handler(req, res);
}

1 comment on commit 4b27895

@vercel
Copy link

@vercel vercel bot commented on 4b27895 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.