Skip to content

Commit

Permalink
feat(moderation): support crisp tickets (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil authored Aug 29, 2024
1 parent 1bb32f8 commit 9dfd604
Show file tree
Hide file tree
Showing 95 changed files with 1,654 additions and 469 deletions.
9 changes: 7 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ API_AUTH_URL="http://localhost:6300"
API_AUTH_USERNAME="________________________"
CONSOLA_LEVEL="4"
COOKIE_ENCRYPTION_KEY="password_at_least_32_characters_long"
CRISP_BASE_URL="http://localhost:6400"
CRISP_IDENTIFIER="________-____-____-____-____________"
CRISP_KEY="________________________________________________________________"
CRISP_PLUGIN_URN="urn:_______:______________:_"
CRISP_USER_NICKNAME="______________"
CRISP_WEBSITE_ID="________-____-____-____-____________"
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres?schema=public"
ENTREPRISE_API_GOUV_TOKEN="____.____.____"
ENTREPRISE_API_GOUV_URL="http://localhost:6200"
HOST="https://hyyypertool-preprod.moncomptepro.beta.gouv.fr/proxy/localhost:3000"
SENTRY_DNS="https://[email protected]/____"
SYMMETRIC_ENCRYPTION_KEY="aTrueRandom32BytesLongBase64EncodedStringAA="
ZAMMAD_TOKEN="____"
ZAMMAD_URL="https://support.etalab.gouv.fr"

SYMMETRIC_ENCRYPTION_KEY="aTrueRandom32BytesLongBase64EncodedStringAA="
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
node_modules/

#
.env.local
.env.*.local

# Generated style
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions hyyypertool.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
{ "path": "packages/~/welcome", "name": "📦 welcome" },
{ "path": "packages/~/proxy", "name": "📦 proxy" },

//
//

{ "path": "packages/~/infra/moncomptepro", "name": "🏗️ moncomptepro" },
{ "path": "packages/~/infra/zammad", "name": "🏗️ zammad" },
{ "path": "packages/~/infra/crisp", "name": "🏗️ crisp" },

//
{ "path": "packages/~/config", "name": "⚙️ config" },
Expand Down
96 changes: 96 additions & 0 deletions mocks/api.crisp.chat/mockserverInitialization.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
[
{
"httpRequest": {
"method": "GET",
"path": "/v1/website/{website_id}/conversation/{session_id}",
"pathParameters": {
"session_id": ["[A-Z0-9\\-\\_]+"],
"website_id": ["[A-Z0-9\\-\\_]+"]
}
},
"httpResponse": {
"body": {
"data": {
"meta": {
"subjet": "Lorem Ipsum"
}
}
}
}
},
{
"httpRequest": {
"method": "POST",
"path": "/v1/website/{website_id}/conversation/{session_id}/message",
"pathParameters": {
"session_id": ["[A-Z0-9\\-\\_]+"],
"website_id": ["[A-Z0-9\\-\\_]+"]
}
},
"httpResponse": {
"body": {
"data": {
"fingerprint": "123456789"
}
}
}
},
{
"httpRequest": {
"method": "GET",
"path": "/v1/website/{website_id}/conversation/{session_id}/messages",
"pathParameters": {
"session_id": ["[A-Z0-9\\-\\_]+"],
"website_id": ["[A-Z0-9\\-\\_]+"]
}
},
"httpResponse": {
"body": {
"data": [
{
"content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"type": "text",
"timestamp": 1715097494011,
"user": {
"user_id": "123456789",
"nickname": "John User"
}
}
]
}
}
},
{
"httpRequest": {
"method": "GET",
"path": "/v1/website/{website_id}/operators/list",
"pathParameters": {
"website_id": ["[A-Z0-9\\-\\_]+"]
}
},
"httpResponse": {
"body": {
"data": [
{
"details": {
"email": "[email protected]",
"firstname": "John",
"lastname": "User",
"user_id": "123456789"
}
}
]
}
}
},
{
"httpRequest": {
"path": "/readyz"
},
"httpResponse": {
"body": "readyz check passed",
"reasonPhrase": "OK",
"statusCode": 200
}
}
]
11 changes: 11 additions & 0 deletions mocks/docker-compose.mocks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#

services:
api.crisp.chat:
image: mockserver/mockserver:5.15.0
command: -proxyRemoteHost api.crisp.chat -proxyRemotePort 443
environment:
MOCKSERVER_LOG_LEVEL: DEBUG
MOCKSERVER_INITIALIZATION_JSON_PATH: /config/mockserverInitialization.json
volumes:
- ./api.crisp.chat/mockserverInitialization.json:/config/mockserverInitialization.json
ports:
- 6400:1080

auth.agentconnect.gouv.fr:
image: mockserver/mockserver:5.15.0
command: -proxyRemoteHost fca.integ01.dev-agentconnect.fr -proxyRemotePort 443
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"packages/~/auth/*",
"packages/~/config/*",
"packages/~/infra/moncomptepro/*",
"packages/~/infra/crisp/*",
"packages/~/infra/zammad/*",
"packages/~/moderations/*",
"packages/~/organizations/*",
Expand Down Expand Up @@ -63,7 +64,7 @@
"consola": "3.2.3",
"dotenv": "16.4.5",
"hono": "4.5.9",
"tsx": "4.16.5"
"tsx": "4.19.0"
},
"devDependencies": {
"@csmith/release-it-calver-plugin": "2023.12.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/hono-slotify/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"outDir": "./node_modules/.cache/tsc",
"types": ["bun-types", "hono"]
},
"extends": "@~/config.typescript/tsx.json",
"extends": "@~/config.typescript/tsx/tsconfig.json",
"references": []
}
2 changes: 1 addition & 1 deletion packages/~/app/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"jsxImportSource": "hono/jsx",
"outDir": "./node_modules/.cache/tsc"
},
"extends": "@~/config.typescript/base.json",
"extends": "@~/config.typescript/base/tsconfig.json",
"references": [
{ "path": "../../auth/api/tsconfig.json" },
{ "path": "../../infra/moncomptepro/database/tsconfig.json" },
Expand Down
12 changes: 11 additions & 1 deletion packages/~/app/core/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { z } from "zod";
//

dotenv.config({
path: [`.env.${process.env.NODE_ENV}.local`, ".env.local", ".env"],
path: [
`.env.${process.env.NODE_ENV ?? "development"}.local`,
".env.local",
".env",
],
});

const pkg = await import(join(cwd(), "package.json"));
Expand Down Expand Up @@ -48,6 +52,12 @@ export const app_env = z.object({
.string()
.trim()
.default("password_at_least_32_characters_long"),
CRISP_BASE_URL: z.string().url().default("https://api.crisp.chat"),
CRISP_IDENTIFIER: z.string().trim(),
CRISP_KEY: z.string().trim(),
CRISP_PLUGIN_URN: z.string().trim(),
CRISP_USER_NICKNAME: z.string().trim(),
CRISP_WEBSITE_ID: z.string().trim(),
DATABASE_URL: z
.string()
.trim()
Expand Down
4 changes: 4 additions & 0 deletions packages/~/app/core/src/htmx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ export function prefix_id(name: string) {
export function is_htmx_request(req: Request) {
return req.headers.get("hx-request") === "true";
}

export const hx_disabled_form_elements = {
"hx-disabled-elt": ["button", "input", "textarea"].join(", "),
};
2 changes: 1 addition & 1 deletion packages/~/app/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"types": ["bun-types"],
"outDir": "./node_modules/.cache/tsc"
},
"extends": "@~/config.typescript/base.json"
"extends": "@~/config.typescript/base/tsconfig.json"
}
2 changes: 1 addition & 1 deletion packages/~/app/layout/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"lib": ["DOM"],
"types": ["bun-types", "hono"]
},
"extends": "@~/config.typescript/tsx.json",
"extends": "@~/config.typescript/tsx/tsconfig.json",
"references": [
{ "path": "../core/tsconfig.json" },
{ "path": "../middleware/tsconfig.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/~/app/middleware/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"jsxImportSource": "hono/jsx",
"outDir": "./node_modules/.cache/tsc"
},
"extends": "@~/config.typescript/base.json",
"extends": "@~/config.typescript/base/tsconfig.json",
"references": [
{ "path": "../core/tsconfig.json" },
{ "path": "../sentry/tsconfig.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/~/app/sentry/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"types": ["bun-types"],
"outDir": "./node_modules/.cache/tsc"
},
"extends": "@~/config.typescript/base.json"
"extends": "@~/config.typescript/base/tsconfig.json"
}
1 change: 1 addition & 0 deletions packages/~/app/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"devDependencies": {
"@~/config.happydom": "workspace:*",
"@~/config.tailwindcss": "workspace:*",
"@~/config.typescript": "workspace:*"
}
}
40 changes: 40 additions & 0 deletions packages/~/app/ui/src/links/OpenInCrisp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//

import type { Child } from "hono/jsx";

//
/**
*
* @example
* ```tsx
* <OpenInCrisp session_id={moderation.session_id}>
* #{moderation.session_id}
* </OpenInCrisp>
* ```
*/

export function OpenInCrisp({
base_url = "https://app.crisp.chat",
children,
session_id,
website_id,
}: {
base_url?: string;
children: Child;
session_id: string;
website_id: string;
}) {
return (
<a
href={`${base_url}/website/${website_id}/inbox/${session_id}`}
rel="noopener noreferrer"
target="_blank"
>
{children}
</a>
);
}

export function short_session_id(session_id: string) {
return session_id.replace("session_", "").slice(0, 7);
}
4 changes: 2 additions & 2 deletions packages/~/app/ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"compilerOptions": {
"jsx": "preserve",
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",
"lib": ["DOM"],
"outDir": "./node_modules/.cache/tsc",
"types": ["bun-types", "hono"]
},
"extends": "@~/config.typescript/tsx.json",
"extends": "@~/config.typescript/tsx/tsconfig.json",
"references": [
{ "path": "../../config/happydom/tsconfig.json" },
{ "path": "../core/tsconfig.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/~/app/urls/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"types": ["bun-types"],
"outDir": "./node_modules/.cache/tsc"
},
"extends": "@~/config.typescript/base.json"
"extends": "@~/config.typescript/base/tsconfig.json"
}
2 changes: 1 addition & 1 deletion packages/~/auth/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"outDir": "./node_modules/.cache/tsc"
},
"extends": "@~/config.typescript/api.json",
"extends": "@~/config.typescript/api/tsconfig.json",
"references": [
{ "path": "../../app/core/tsconfig.json" },
{ "path": "../../app/middleware/tsconfig.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/~/config/happydom/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"compilerOptions": {
"outDir": "./node_modules/.cache/tsc"
},
"extends": "@~/config.typescript/base.json"
"extends": "@~/config.typescript/base/tsconfig.json"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "API",
"extends": "./base.json",
"extends": "../base/tsconfig.json",
"compilerOptions": {
"exactOptionalPropertyTypes": false,
"jsx": "preserve",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Bun",
"extends": "./base.json",
"extends": "../base/tsconfig.json",
"compilerOptions": {
"types": ["bun-types"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "TSX",
"extends": "./base.json",
"extends": "../base/tsconfig.json",
"compilerOptions": {
"jsx": "preserve",
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@~/users.ui",
"name": "@~/crisp.lib",
"version": "1.0.0",
"private": true,
"type": "module",
Expand All @@ -11,7 +11,12 @@
"default": "./src/*.ts"
}
},
"dependencies": {},
"dependencies": {
"@numerique-gouv/crisp": "https://github.com/douglasduteil/crisp/releases/download/v1.6.1/douglasduteil-crisp-1.6.1.tgz",
"@~/app.core": "workspace:*",
"consola": "3.2.3",
"zod": "3.23.8"
},
"devDependencies": {
"@~/config.typescript": "workspace:*"
}
Expand Down
Loading

0 comments on commit 9dfd604

Please sign in to comment.