Spaces:
Sleeping
Sleeping
Download src/modules/label/label.controller.ts from jinksQspider/openWa: direct link, hf CLI and curl.
- Browser
- Download file 3.68 kB
-
https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/label/label.controller.ts
- Command line
-
hf download hf://spaces/jinksQspider/openWa/src/modules/label/label.controller.ts
-
curl -L -o label.controller.ts https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/label/label.controller.ts
3.68 kB
| import { Controller, Get, Post, Delete, Param, Body, BadRequestException, NotFoundException } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger'; | |
| import { SessionService } from '../session/session.service'; | |
| ('labels') | |
| ('sessions/:sessionId/labels') | |
| export class LabelController { | |
| constructor(private readonly sessionService: SessionService) {} | |
| private getEngine(sessionId: string) { | |
| const engine = this.sessionService.getEngine(sessionId); | |
| if (!engine) { | |
| throw new BadRequestException('Session is not started'); | |
| } | |
| return engine; | |
| } | |
| () | |
| ({ summary: 'Get all labels (WhatsApp Business only)' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ | |
| status: 200, | |
| description: 'List of labels', | |
| }) | |
| ({ status: 400, description: 'Session not ready or not a business account' }) | |
| ({ status: 404, description: 'Session not found' }) | |
| async findAll(('sessionId') sessionId: string) { | |
| const engine = this.getEngine(sessionId); | |
| return engine.getLabels(); | |
| } | |
| (':labelId') | |
| ({ summary: 'Get a specific label by ID' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'labelId', description: 'Label ID' }) | |
| ({ | |
| status: 200, | |
| description: 'Label details', | |
| }) | |
| ({ status: 404, description: 'Label not found' }) | |
| async findOne(('sessionId') sessionId: string, ('labelId') labelId: string) { | |
| const engine = this.getEngine(sessionId); | |
| const label = await engine.getLabelById(labelId); | |
| if (!label) { | |
| throw new NotFoundException(`Label ${labelId} not found`); | |
| } | |
| return label; | |
| } | |
| ('chat/:chatId') | |
| ({ summary: 'Get labels for a specific chat' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'chatId', description: 'Chat ID' }) | |
| ({ | |
| status: 200, | |
| description: 'List of labels for the chat', | |
| }) | |
| async getChatLabels(('sessionId') sessionId: string, ('chatId') chatId: string) { | |
| const engine = this.getEngine(sessionId); | |
| return engine.getChatLabels(chatId); | |
| } | |
| ('chat/:chatId') | |
| ({ summary: 'Add a label to a chat' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'chatId', description: 'Chat ID' }) | |
| ({ | |
| schema: { | |
| type: 'object', | |
| properties: { | |
| labelId: { type: 'string', description: 'Label ID to add' }, | |
| }, | |
| required: ['labelId'], | |
| }, | |
| }) | |
| ({ | |
| status: 200, | |
| description: 'Label added to chat', | |
| }) | |
| async addLabelToChat( | |
| ('sessionId') sessionId: string, | |
| ('chatId') chatId: string, | |
| () body: { labelId: string }, | |
| ) { | |
| const engine = this.getEngine(sessionId); | |
| await engine.addLabelToChat(chatId, body.labelId); | |
| return { success: true }; | |
| } | |
| ('chat/:chatId/:labelId') | |
| ({ summary: 'Remove a label from a chat' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'chatId', description: 'Chat ID' }) | |
| ({ name: 'labelId', description: 'Label ID to remove' }) | |
| ({ | |
| status: 200, | |
| description: 'Label removed from chat', | |
| }) | |
| async removeLabelFromChat( | |
| ('sessionId') sessionId: string, | |
| ('chatId') chatId: string, | |
| ('labelId') labelId: string, | |
| ) { | |
| const engine = this.getEngine(sessionId); | |
| await engine.removeLabelFromChat(chatId, labelId); | |
| return { success: true }; | |
| } | |
| } | |