Skip to content

Commit

Permalink
πŸ†•πŸ”— typebot
Browse files Browse the repository at this point in the history
  • Loading branch information
jrCleber committed Dec 9, 2023
1 parent e71a9f9 commit 88f2d1b
Show file tree
Hide file tree
Showing 4 changed files with 700 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/integrations/typebot/dto/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
* β”‚ @author jrCleber β”‚
* β”‚ @filename message.model.ts β”‚
* β”‚ Developed by: Cleber Wilson β”‚
* β”‚ Creation date: Dez 07, 2023 β”‚
* β”‚ Contact: [email protected] β”‚
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
* β”‚ @copyright Β© Cleber Wilson 2022. All rights reserved. β”‚
* β”‚ Licensed under the Apache License, Version 2.0 β”‚
* β”‚ β”‚
* β”‚ @license "https://github.com/code-chat-br/whatsapp-api/blob/main/LICENSE" β”‚
* β”‚ β”‚
* β”‚ You may not use this file except in compliance with the License. β”‚
* β”‚ You may obtain a copy of the License at β”‚
* β”‚ β”‚
* β”‚ http://www.apache.org/licenses/LICENSE-2.0 β”‚
* β”‚ β”‚
* β”‚ Unless required by applicable law or agreed to in writing, software β”‚
* β”‚ distributed under the License is distributed on an "AS IS" BASIS, β”‚
* β”‚ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. β”‚
* β”‚ β”‚
* β”‚ See the License for the specific language governing permissions and β”‚
* β”‚ limitations under the License. β”‚
* β”‚ β”‚ β”‚
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
* β”‚ @important β”‚
* β”‚ For any future changes to the code in this file, it is recommended to β”‚
* β”‚ contain, together with the modification, the information of the developer β”‚
* β”‚ who changed it and the date of modification. β”‚
* β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

export type RichText = {
type: string;
text: string;
children: {
text: string;
type: string;
children: RichText[];
}[];
};

export type Content = {
richText: RichText[];
url?: string;
id?: string;
type?: string;
height?: number;
aspectRatio?: string;
maxWidth?: string;
};

export type ResponseMessage = {
id: string;
type: string;
content: Content;
};

export type Input = {
id: string;
type: string;
options: {
labels: {
placeholder: string;
};
};
};

export type Typebot = {
id: string;
theme: object;
settings: object;
};

export type Response = {
messages: ResponseMessage[];
input: Input;
sessionId: string;
typebot: Typebot;
resultId: string;
code: string;
} & SessionNotFound;

export type SessionNotFound = {
message: string;
code: string;
};
47 changes: 47 additions & 0 deletions src/integrations/typebot/dto/typebot.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
* β”‚ @author jrCleber β”‚
* β”‚ @filename message.model.ts β”‚
* β”‚ Developed by: Cleber Wilson β”‚
* β”‚ Creation date: Dez 07, 2023 β”‚
* β”‚ Contact: [email protected] β”‚
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
* β”‚ @copyright Β© Cleber Wilson 2022. All rights reserved. β”‚
* β”‚ Licensed under the Apache License, Version 2.0 β”‚
* β”‚ β”‚
* β”‚ @license "https://github.com/code-chat-br/whatsapp-api/blob/main/LICENSE" β”‚
* β”‚ β”‚
* β”‚ You may not use this file except in compliance with the License. β”‚
* β”‚ You may obtain a copy of the License at β”‚
* β”‚ β”‚
* β”‚ http://www.apache.org/licenses/LICENSE-2.0 β”‚
* β”‚ β”‚
* β”‚ Unless required by applicable law or agreed to in writing, software β”‚
* β”‚ distributed under the License is distributed on an "AS IS" BASIS, β”‚
* β”‚ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. β”‚
* β”‚ β”‚
* β”‚ See the License for the specific language governing permissions and β”‚
* β”‚ limitations under the License. β”‚
* β”‚ β”‚ β”‚
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
* β”‚ @important β”‚
* β”‚ For any future changes to the code in this file, it is recommended to β”‚
* β”‚ contain, together with the modification, the information of the developer β”‚
* β”‚ who changed it and the date of modification. β”‚
* β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

export class TypebotDto {
publicId?: string;
typebotUrl?: string;
enabled?: boolean;
instanceName?: string;
}

export type TypebotActionSession = 'open' | 'closed' | 'paused';

export class TypebotUpdateSessionDto {
sessionId: string;
remoteJid: string;
action: TypebotActionSession;
}
112 changes: 112 additions & 0 deletions src/integrations/typebot/typebot.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
* β”‚ @author jrCleber β”‚
* β”‚ @filename message.model.ts β”‚
* β”‚ Developed by: Cleber Wilson β”‚
* β”‚ Creation date: Dez 07, 2023 β”‚
* β”‚ Contact: [email protected] β”‚
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
* β”‚ @copyright Β© Cleber Wilson 2022. All rights reserved. β”‚
* β”‚ Licensed under the Apache License, Version 2.0 β”‚
* β”‚ β”‚
* β”‚ @license "https://github.com/code-chat-br/whatsapp-api/blob/main/LICENSE" β”‚
* β”‚ β”‚
* β”‚ You may not use this file except in compliance with the License. β”‚
* β”‚ You may obtain a copy of the License at β”‚
* β”‚ β”‚
* β”‚ http://www.apache.org/licenses/LICENSE-2.0 β”‚
* β”‚ β”‚
* β”‚ Unless required by applicable law or agreed to in writing, software β”‚
* β”‚ distributed under the License is distributed on an "AS IS" BASIS, β”‚
* β”‚ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. β”‚
* β”‚ β”‚
* β”‚ See the License for the specific language governing permissions and β”‚
* β”‚ limitations under the License. β”‚
* β”‚ β”‚
* β”‚ @class S3Router β”‚ β”‚
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
* β”‚ @important β”‚
* β”‚ For any future changes to the code in this file, it is recommended to β”‚
* β”‚ contain, together with the modification, the information of the developer β”‚
* β”‚ who changed it and the date of modification. β”‚
* β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

import { RequestHandler, Router } from 'express';
import { TypebotDto, TypebotUpdateSessionDto } from './dto/typebot.dto';
import {
typebotFindSessionSchema,
typebotSchema,
typebotUpdateSchema,
typebotUpdateSessionSchema,
} from '../../validate/validate.schema';
import { HttpStatus } from '../../app.module';
import { TypebotService } from './typebot.service';
import { dataValidate, routerPath } from '../../validate/router.validate';

export function TypebotRouter(
typebotService: TypebotService,
...guards: RequestHandler[]
) {
const router = Router()
.post(routerPath('create'), ...guards, async (req, res) => {
const response = await dataValidate<TypebotDto>({
request: req,
schema: typebotSchema,
execute: (instance, data) =>
typebotService.createBotInstance(instance.instanceName, data),
});

return res.status(HttpStatus.CREATED).json(response);
})
.put(routerPath('update'), ...guards, async (req, res) => {
const response = await dataValidate<TypebotDto>({
request: req,
schema: typebotUpdateSchema,
execute: (instance, data) =>
typebotService.updateBotInstance(instance.instanceName, data),
});

return res.status(HttpStatus.OK).json(response);
})
.get(routerPath('find'), ...guards, async (req, res) => {
const response = await dataValidate({
request: req,
schema: null,
execute: (instance) => typebotService.getBotInstance(instance.instanceName),
});

return res.status(HttpStatus.OK).json(response?.['Typebot']);
})
.delete(routerPath('delete'), ...guards, async (req, res) => {
const response = await dataValidate({
request: req,
schema: null,
execute: (instance) => typebotService.deleteBotInstance(instance.instanceName),
});

return res.status(HttpStatus.OK).json(response?.['Typebot']);
})
.post(routerPath('sessions/find'), ...guards, async (req, res) => {
const response = await dataValidate<TypebotUpdateSessionDto>({
request: req,
schema: typebotFindSessionSchema,
execute: (instance, data) =>
typebotService.findSessionsRegistered(instance.instanceName, data),
});

return res.status(HttpStatus.OK).json(response);
})
.patch(routerPath('sessions/update'), ...guards, async (req, res) => {
const response = await dataValidate<TypebotUpdateSessionDto>({
request: req,
schema: typebotUpdateSessionSchema,
execute: (instance, data) =>
typebotService.updateSessionRegistered(instance.instanceName, data),
});

return res.status(HttpStatus.OK).json(response);
});

return router;
}
Loading

0 comments on commit 88f2d1b

Please sign in to comment.