-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
700 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.