Spaces:
Sleeping
Sleeping
Download src/modules/channel/channel.controller.ts from jinksQspider/openWa: direct link, hf CLI and curl.
- Browser
- Download file 3.79 kB
-
https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/channel/channel.controller.ts
- Command line
-
hf download hf://spaces/jinksQspider/openWa/src/modules/channel/channel.controller.ts
-
curl -L -o channel.controller.ts https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/channel/channel.controller.ts
3.79 kB
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Delete, | |
| Param, | |
| Body, | |
| Query, | |
| BadRequestException, | |
| NotFoundException, | |
| } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody, ApiQuery } from '@nestjs/swagger'; | |
| import { SessionService } from '../session/session.service'; | |
| ('channels') | |
| ('sessions/:sessionId/channels') | |
| export class ChannelController { | |
| 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 subscribed channels/newsletters' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ | |
| status: 200, | |
| description: 'List of subscribed channels', | |
| }) | |
| ({ status: 400, description: 'Session not ready' }) | |
| async findAll(('sessionId') sessionId: string) { | |
| const engine = this.getEngine(sessionId); | |
| return engine.getSubscribedChannels(); | |
| } | |
| (':channelId') | |
| ({ summary: 'Get a specific channel by ID' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'channelId', description: 'Channel ID' }) | |
| ({ | |
| status: 200, | |
| description: 'Channel details', | |
| }) | |
| ({ status: 404, description: 'Channel not found' }) | |
| async findOne(('sessionId') sessionId: string, ('channelId') channelId: string) { | |
| const engine = this.getEngine(sessionId); | |
| const channel = await engine.getChannelById(channelId); | |
| if (!channel) { | |
| throw new NotFoundException(`Channel ${channelId} not found`); | |
| } | |
| return channel; | |
| } | |
| (':channelId/messages') | |
| ({ summary: 'Get messages from a channel' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'channelId', description: 'Channel ID' }) | |
| ({ name: 'limit', required: false, type: Number, description: 'Max messages to return (default 50)' }) | |
| ({ | |
| status: 200, | |
| description: 'List of channel messages', | |
| }) | |
| async getMessages( | |
| ('sessionId') sessionId: string, | |
| ('channelId') channelId: string, | |
| ('limit') limit?: string, | |
| ) { | |
| const engine = this.getEngine(sessionId); | |
| return engine.getChannelMessages(channelId, limit ? parseInt(limit, 10) : undefined); | |
| } | |
| ('subscribe') | |
| ({ summary: 'Subscribe to a channel using invite code' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ | |
| schema: { | |
| type: 'object', | |
| properties: { | |
| inviteCode: { | |
| type: 'string', | |
| description: 'Channel invite code (from channel link)', | |
| example: 'ABC123xyz', | |
| }, | |
| }, | |
| required: ['inviteCode'], | |
| }, | |
| }) | |
| ({ | |
| status: 201, | |
| description: 'Successfully subscribed to channel', | |
| }) | |
| async subscribe(('sessionId') sessionId: string, () body: { inviteCode: string }) { | |
| const engine = this.getEngine(sessionId); | |
| return engine.subscribeToChannel(body.inviteCode); | |
| } | |
| (':channelId') | |
| ({ summary: 'Unsubscribe from a channel' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'channelId', description: 'Channel ID to unsubscribe from' }) | |
| ({ | |
| status: 200, | |
| description: 'Successfully unsubscribed from channel', | |
| }) | |
| async unsubscribe(('sessionId') sessionId: string, ('channelId') channelId: string) { | |
| const engine = this.getEngine(sessionId); | |
| await engine.unsubscribeFromChannel(channelId); | |
| return { success: true }; | |
| } | |
| } | |