Spaces:
Runtime error
Runtime error
File size: 3,136 Bytes
46252cd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | import { Controller, Get, Post, Param, Body, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { CatalogService } from './catalog.service';
import { SendProductDto, SendCatalogDto, ProductQueryDto } from './dto/send-product.dto';
import { RequireRole } from '../auth/decorators/auth.decorators';
import { ApiKeyRole } from '../auth/entities/api-key.entity';
@ApiTags('catalog')
@Controller('sessions/:sessionId')
export class CatalogController {
constructor(private readonly catalogService: CatalogService) {}
@Get('catalog')
@ApiOperation({ summary: 'Get business catalog info (not implemented by any engine)' })
@ApiResponse({
status: 200,
description: 'Always null on whatsapp-web.js: catalog reads are not implemented on either engine.',
})
@ApiResponse({
status: 501,
description: 'Not supported by the active engine: Baileys does not implement catalog reads.',
})
async getCatalog(@Param('sessionId') sessionId: string) {
return this.catalogService.getCatalog(sessionId);
}
@Get('catalog/products')
@ApiOperation({ summary: 'List catalog products (not implemented by any engine)' })
@ApiResponse({
status: 200,
description: 'Always an empty page on whatsapp-web.js: catalog reads are not implemented on either engine.',
})
@ApiResponse({
status: 501,
description: 'Not supported by the active engine: Baileys does not implement catalog reads.',
})
async getProducts(@Param('sessionId') sessionId: string, @Query() query: ProductQueryDto) {
return this.catalogService.getProducts(sessionId, query.page, query.limit);
}
@Get('catalog/products/:productId')
@ApiOperation({ summary: 'Get a specific product (not implemented by any engine)' })
@ApiResponse({
status: 200,
description: 'Always null on whatsapp-web.js: catalog reads are not implemented on either engine.',
})
@ApiResponse({
status: 501,
description: 'Not supported by the active engine: Baileys does not implement catalog reads.',
})
async getProduct(@Param('sessionId') sessionId: string, @Param('productId') productId: string) {
return this.catalogService.getProduct(sessionId, productId);
}
@Post('messages/send-product')
@RequireRole(ApiKeyRole.OPERATOR)
@ApiOperation({ summary: 'Send a product message (not supported by any engine)' })
@ApiResponse({ status: 501, description: 'Not supported by the active engine: no engine can send product messages.' })
async sendProduct(@Param('sessionId') sessionId: string, @Body() dto: SendProductDto) {
return this.catalogService.sendProduct(sessionId, dto.chatId, dto.productId, dto.body);
}
@Post('messages/send-catalog')
@RequireRole(ApiKeyRole.OPERATOR)
@ApiOperation({ summary: 'Send catalog link (not supported by any engine)' })
@ApiResponse({ status: 501, description: 'Not supported by the active engine: no engine can send catalog links.' })
async sendCatalog(@Param('sessionId') sessionId: string, @Body() dto: SendCatalogDto) {
return this.catalogService.sendCatalog(sessionId, dto.chatId, dto.body);
}
}
|