Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tools-automation-api): initialize notion service #3492

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/tools-automation-api/.env.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Crisp marketplace key & identifier to use crisp api
CRISP_TOKEN_IDENTIFIER=
CRISP_TOKEN_KEY=

14 changes: 11 additions & 3 deletions apps/tools-automation-api/Earthfile
Original file line number Diff line number Diff line change
@@ -30,14 +30,22 @@ docker:
deploy: ## Déploie le backend dans une app Koyeb existante
ARG --required KOYEB_API_KEY
ARG --required DEPLOYMENT_TIMESTAMP
ARG SERVICE_NAME=$ENV_NAME-tools-automation-api
ARG SERVICE_NAME=$ENV_NAME-tools-autom-api ## Max 23 characters
FROM ../../+koyeb --KOYEB_API_KEY=$KOYEB_API_KEY

RUN ./koyeb services update $SERVICE_NAME/tools-automation-api \
--debug \
--docker $BACKEND_IMG_NAME \
--docker $TOOLS_AUTOMATION_API_IMG_NAME \
--env ENV_NAME=$ENV_NAME \
--env DEPLOYMENT_TIMESTAMP=$DEPLOYMENT_TIMESTAMP
--env DEPLOYMENT_TIMESTAMP=$DEPLOYMENT_TIMESTAMP \
--env CRISP_TOKEN_IDENTIFIER=@CRISP_TOKEN_IDENTIFIER_$ENV_NAME \
--env CRISP_TOKEN_KEY=@CRISP_TOKEN_KEY_$ENV_NAME \
--env NOTION_TOKEN=@NOTION_TOKEN_$ENV_NAME \
--env NOTION_BUG_DATABASE_ID=@NOTION_BUG_DATABASE_ID_$ENV_NAME \
--env NOTION_BUG_EPIC_ID=@NOTION_BUG_EPIC_ID_$ENV_NAME \
--env NOTION_BUG_TEMPLATE_ID=@NOTION_BUG_TEMPLATE_ID_$ENV_NAME \
--env TET_API_URL=@TET_API_URL_$ENV_NAME \
--env TET_API_TOKEN=@SUPABASE_JWT_SECRET_$ENV_NAME

test-build: ## construit une image pour exécuter les tests du backend
FROM ../../+front-deps
28 changes: 28 additions & 0 deletions apps/tools-automation-api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Module } from '@nestjs/common';

import { ConfigModule } from '@nestjs/config';
import configuration from './config/configuration';
import { ConfigurationModule } from './config/configuration.module';
import { CrispModule } from './crisp/crisp.module';
import { NotionModule } from './notion/notion.module';
import { SentryModule } from './sentry/sentry.module';
import { UtilsModule } from './utils/utils.module';
import { VersionController } from './utils/version/version.controller';

@Module({
imports: [
ConfigModule.forRoot({
ignoreEnvFile: process.env.NODE_ENV === 'production', // In production, environment variables are set by the deployment
// validate: validateBackendConfiguration,
load: [configuration],
}),
ConfigurationModule,
UtilsModule,
NotionModule,
CrispModule,
SentryModule,
],
controllers: [VersionController],
providers: [],
})
export class AppModule {}
22 changes: 0 additions & 22 deletions apps/tools-automation-api/src/app/app.controller.spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions apps/tools-automation-api/src/app/app.controller.ts

This file was deleted.

11 changes: 0 additions & 11 deletions apps/tools-automation-api/src/app/app.module.ts

This file was deleted.

21 changes: 0 additions & 21 deletions apps/tools-automation-api/src/app/app.service.spec.ts

This file was deleted.

8 changes: 0 additions & 8 deletions apps/tools-automation-api/src/app/app.service.ts

This file was deleted.

38 changes: 38 additions & 0 deletions apps/tools-automation-api/src/config/configuration.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { z } from 'zod';

export const toolsAutomationApiConfigurationSchema = z.object({
CRISP_TOKEN_IDENTIFIER: z
.string()
.min(1)
.describe("Token identifier pour l'authentification à l'API Crisp"),
CRISP_TOKEN_KEY: z
.string()
.min(1)
.describe("Token key pour l'authentification à l'API Crisp"),
NOTION_TOKEN: z
.string()
.min(1)
.describe(
"Token key pour l'authentification à l'API Notion pour la création de bug"
),
NOTION_BUG_DATABASE_ID: z
.string()
.min(1)
.describe('ID de la base de données Notion dans laquelle créer les bugs'),
NOTION_BUG_EPIC_ID: z
.string()
.min(1)
.describe("ID de l'épic Notion dans laquel créer les bugs"),
NOTION_BUG_TEMPLATE_ID: z
.string()
.min(1)
.describe('ID du template de bug Notion'),
TET_API_TOKEN: z
.string()
.min(1)
.describe("Token pour l'authentification à l'API TeT"),
TET_API_URL: z.string().min(1).describe("Url de l'API TeT"),
});
export type ToolsAutomationApiConfigurationType = z.infer<
typeof toolsAutomationApiConfigurationSchema
>;
10 changes: 10 additions & 0 deletions apps/tools-automation-api/src/config/configuration.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import ConfigurationService from './configuration.service';

@Module({
imports: [ConfigModule.forRoot()],
providers: [ConfigurationService],
exports: [ConfigurationService],
})
export class ConfigurationModule {}
21 changes: 21 additions & 0 deletions apps/tools-automation-api/src/config/configuration.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ToolsAutomationApiConfigurationType } from './configuration.model';

@Injectable()
export default class ConfigurationService {
private readonly logger = new Logger(ConfigurationService.name);

constructor(
private readonly configService: ConfigService<
ToolsAutomationApiConfigurationType,
true
>
) {
this.logger.log(`Initializing configuration service`);
}

get(key: keyof ToolsAutomationApiConfigurationType) {
return this.configService.get(key);
}
}
5 changes: 5 additions & 0 deletions apps/tools-automation-api/src/config/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { toolsAutomationApiConfigurationSchema } from './configuration.model';

export default () => ({
...toolsAutomationApiConfigurationSchema.parse(process.env),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Body, Controller, Post } from '@nestjs/common';

import { CrispService } from '../services/crisp.service';

@Controller('crisp')
export class CrispController {
constructor(private readonly crispService: CrispService) {}

@Post('sessions/callback')
handleSessionChange(@Body() body: any) {
return this.crispService.handleSessionChange(body);
}
}
12 changes: 12 additions & 0 deletions apps/tools-automation-api/src/crisp/crisp.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { ConfigurationModule } from '../config/configuration.module';
import { NotionModule } from '../notion/notion.module';
import { CrispController } from './controllers/crisp.controller';
import { CrispService } from './services/crisp.service';

@Module({
imports: [ConfigurationModule, NotionModule],
controllers: [CrispController],
providers: [CrispService],
})
export class CrispModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface CrispEventRequest<TEventData> {
website_id: string;
event: string;
data: TEventData;
timestamp: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface CrispSessionEventDataDto {
website_id: string;
session_id: string;
data: { [key: string]: string | number };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
export interface GetCrispSessionMessagesResponse {
error: boolean;
reason: string;
data: CrispSessionMessage[];
}

export interface CrispSessionMessage {
session_id: string;
website_id: string;
fingerprint: number;
type: CrispSessionMessageType;
from: From;
origin: Delivered;
content: CrispSessionMessageContent | string;
user: User;
original?: Original;
delivered: Delivered;
read: Delivered;
preview: PreviewElement[];
mentions: any[];
stamped: boolean;
timestamp: number;
}

export interface CrispSessionMessageContent {
namespace?: string;
text?: string;
name?: string;
url?: string;
type?: string;
}

export enum Delivered {
Chat = 'chat',
Email = 'email',
Empty = '',
}

export enum From {
Operator = 'operator',
User = 'user',
}

export interface Original {
original_id: string;
}

export interface PreviewElement {
url: string;
website: string;
title: string;
preview: PreviewPreview;
}

export interface PreviewPreview {
excerpt: string;
image: string;
}

export enum CrispSessionMessageType {
Event = 'event',
File = 'file',
Text = 'text',
}

export interface User {
user_id?: string;
nickname: string;
type?: string;
}
Loading
Loading