Skip to content

Commit 88f2d1b

Browse files
committed
πŸ†•πŸ”— typebot
1 parent e71a9f9 commit 88f2d1b

4 files changed

Lines changed: 700 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
3+
* β”‚ @author jrCleber β”‚
4+
* β”‚ @filename message.model.ts β”‚
5+
* β”‚ Developed by: Cleber Wilson β”‚
6+
* β”‚ Creation date: Dez 07, 2023 β”‚
7+
* β”‚ Contact: contato@codechat.dev β”‚
8+
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
9+
* β”‚ @copyright Β© Cleber Wilson 2022. All rights reserved. β”‚
10+
* β”‚ Licensed under the Apache License, Version 2.0 β”‚
11+
* β”‚ β”‚
12+
* β”‚ @license "https://github.com/code-chat-br/whatsapp-api/blob/main/LICENSE" β”‚
13+
* β”‚ β”‚
14+
* β”‚ You may not use this file except in compliance with the License. β”‚
15+
* β”‚ You may obtain a copy of the License at β”‚
16+
* β”‚ β”‚
17+
* β”‚ http://www.apache.org/licenses/LICENSE-2.0 β”‚
18+
* β”‚ β”‚
19+
* β”‚ Unless required by applicable law or agreed to in writing, software β”‚
20+
* β”‚ distributed under the License is distributed on an "AS IS" BASIS, β”‚
21+
* β”‚ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. β”‚
22+
* β”‚ β”‚
23+
* β”‚ See the License for the specific language governing permissions and β”‚
24+
* β”‚ limitations under the License. β”‚
25+
* β”‚ β”‚ β”‚
26+
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
27+
* β”‚ @important β”‚
28+
* β”‚ For any future changes to the code in this file, it is recommended to β”‚
29+
* β”‚ contain, together with the modification, the information of the developer β”‚
30+
* β”‚ who changed it and the date of modification. β”‚
31+
* β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
32+
*/
33+
34+
export type RichText = {
35+
type: string;
36+
text: string;
37+
children: {
38+
text: string;
39+
type: string;
40+
children: RichText[];
41+
}[];
42+
};
43+
44+
export type Content = {
45+
richText: RichText[];
46+
url?: string;
47+
id?: string;
48+
type?: string;
49+
height?: number;
50+
aspectRatio?: string;
51+
maxWidth?: string;
52+
};
53+
54+
export type ResponseMessage = {
55+
id: string;
56+
type: string;
57+
content: Content;
58+
};
59+
60+
export type Input = {
61+
id: string;
62+
type: string;
63+
options: {
64+
labels: {
65+
placeholder: string;
66+
};
67+
};
68+
};
69+
70+
export type Typebot = {
71+
id: string;
72+
theme: object;
73+
settings: object;
74+
};
75+
76+
export type Response = {
77+
messages: ResponseMessage[];
78+
input: Input;
79+
sessionId: string;
80+
typebot: Typebot;
81+
resultId: string;
82+
code: string;
83+
} & SessionNotFound;
84+
85+
export type SessionNotFound = {
86+
message: string;
87+
code: string;
88+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
3+
* β”‚ @author jrCleber β”‚
4+
* β”‚ @filename message.model.ts β”‚
5+
* β”‚ Developed by: Cleber Wilson β”‚
6+
* β”‚ Creation date: Dez 07, 2023 β”‚
7+
* β”‚ Contact: contato@codechat.dev β”‚
8+
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
9+
* β”‚ @copyright Β© Cleber Wilson 2022. All rights reserved. β”‚
10+
* β”‚ Licensed under the Apache License, Version 2.0 β”‚
11+
* β”‚ β”‚
12+
* β”‚ @license "https://github.com/code-chat-br/whatsapp-api/blob/main/LICENSE" β”‚
13+
* β”‚ β”‚
14+
* β”‚ You may not use this file except in compliance with the License. β”‚
15+
* β”‚ You may obtain a copy of the License at β”‚
16+
* β”‚ β”‚
17+
* β”‚ http://www.apache.org/licenses/LICENSE-2.0 β”‚
18+
* β”‚ β”‚
19+
* β”‚ Unless required by applicable law or agreed to in writing, software β”‚
20+
* β”‚ distributed under the License is distributed on an "AS IS" BASIS, β”‚
21+
* β”‚ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. β”‚
22+
* β”‚ β”‚
23+
* β”‚ See the License for the specific language governing permissions and β”‚
24+
* β”‚ limitations under the License. β”‚
25+
* β”‚ β”‚ β”‚
26+
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
27+
* β”‚ @important β”‚
28+
* β”‚ For any future changes to the code in this file, it is recommended to β”‚
29+
* β”‚ contain, together with the modification, the information of the developer β”‚
30+
* β”‚ who changed it and the date of modification. β”‚
31+
* β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
32+
*/
33+
34+
export class TypebotDto {
35+
publicId?: string;
36+
typebotUrl?: string;
37+
enabled?: boolean;
38+
instanceName?: string;
39+
}
40+
41+
export type TypebotActionSession = 'open' | 'closed' | 'paused';
42+
43+
export class TypebotUpdateSessionDto {
44+
sessionId: string;
45+
remoteJid: string;
46+
action: TypebotActionSession;
47+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
3+
* β”‚ @author jrCleber β”‚
4+
* β”‚ @filename message.model.ts β”‚
5+
* β”‚ Developed by: Cleber Wilson β”‚
6+
* β”‚ Creation date: Dez 07, 2023 β”‚
7+
* β”‚ Contact: contato@codechat.dev β”‚
8+
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
9+
* β”‚ @copyright Β© Cleber Wilson 2022. All rights reserved. β”‚
10+
* β”‚ Licensed under the Apache License, Version 2.0 β”‚
11+
* β”‚ β”‚
12+
* β”‚ @license "https://github.com/code-chat-br/whatsapp-api/blob/main/LICENSE" β”‚
13+
* β”‚ β”‚
14+
* β”‚ You may not use this file except in compliance with the License. β”‚
15+
* β”‚ You may obtain a copy of the License at β”‚
16+
* β”‚ β”‚
17+
* β”‚ http://www.apache.org/licenses/LICENSE-2.0 β”‚
18+
* β”‚ β”‚
19+
* β”‚ Unless required by applicable law or agreed to in writing, software β”‚
20+
* β”‚ distributed under the License is distributed on an "AS IS" BASIS, β”‚
21+
* β”‚ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. β”‚
22+
* β”‚ β”‚
23+
* β”‚ See the License for the specific language governing permissions and β”‚
24+
* β”‚ limitations under the License. β”‚
25+
* β”‚ β”‚
26+
* β”‚ @class S3Router β”‚ β”‚
27+
* β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
28+
* β”‚ @important β”‚
29+
* β”‚ For any future changes to the code in this file, it is recommended to β”‚
30+
* β”‚ contain, together with the modification, the information of the developer β”‚
31+
* β”‚ who changed it and the date of modification. β”‚
32+
* β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
33+
*/
34+
35+
import { RequestHandler, Router } from 'express';
36+
import { TypebotDto, TypebotUpdateSessionDto } from './dto/typebot.dto';
37+
import {
38+
typebotFindSessionSchema,
39+
typebotSchema,
40+
typebotUpdateSchema,
41+
typebotUpdateSessionSchema,
42+
} from '../../validate/validate.schema';
43+
import { HttpStatus } from '../../app.module';
44+
import { TypebotService } from './typebot.service';
45+
import { dataValidate, routerPath } from '../../validate/router.validate';
46+
47+
export function TypebotRouter(
48+
typebotService: TypebotService,
49+
...guards: RequestHandler[]
50+
) {
51+
const router = Router()
52+
.post(routerPath('create'), ...guards, async (req, res) => {
53+
const response = await dataValidate<TypebotDto>({
54+
request: req,
55+
schema: typebotSchema,
56+
execute: (instance, data) =>
57+
typebotService.createBotInstance(instance.instanceName, data),
58+
});
59+
60+
return res.status(HttpStatus.CREATED).json(response);
61+
})
62+
.put(routerPath('update'), ...guards, async (req, res) => {
63+
const response = await dataValidate<TypebotDto>({
64+
request: req,
65+
schema: typebotUpdateSchema,
66+
execute: (instance, data) =>
67+
typebotService.updateBotInstance(instance.instanceName, data),
68+
});
69+
70+
return res.status(HttpStatus.OK).json(response);
71+
})
72+
.get(routerPath('find'), ...guards, async (req, res) => {
73+
const response = await dataValidate({
74+
request: req,
75+
schema: null,
76+
execute: (instance) => typebotService.getBotInstance(instance.instanceName),
77+
});
78+
79+
return res.status(HttpStatus.OK).json(response?.['Typebot']);
80+
})
81+
.delete(routerPath('delete'), ...guards, async (req, res) => {
82+
const response = await dataValidate({
83+
request: req,
84+
schema: null,
85+
execute: (instance) => typebotService.deleteBotInstance(instance.instanceName),
86+
});
87+
88+
return res.status(HttpStatus.OK).json(response?.['Typebot']);
89+
})
90+
.post(routerPath('sessions/find'), ...guards, async (req, res) => {
91+
const response = await dataValidate<TypebotUpdateSessionDto>({
92+
request: req,
93+
schema: typebotFindSessionSchema,
94+
execute: (instance, data) =>
95+
typebotService.findSessionsRegistered(instance.instanceName, data),
96+
});
97+
98+
return res.status(HttpStatus.OK).json(response);
99+
})
100+
.patch(routerPath('sessions/update'), ...guards, async (req, res) => {
101+
const response = await dataValidate<TypebotUpdateSessionDto>({
102+
request: req,
103+
schema: typebotUpdateSessionSchema,
104+
execute: (instance, data) =>
105+
typebotService.updateSessionRegistered(instance.instanceName, data),
106+
});
107+
108+
return res.status(HttpStatus.OK).json(response);
109+
});
110+
111+
return router;
112+
}

0 commit comments

Comments
Β (0)