feat: SMS campaigns for people or leads with filters and batching
Add audience tabs, province/city filters, select-all ids, dynamic SMS tokens, and 50-sized create/send chunks. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
ArrayMaxSize,
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsDateString,
|
||||
@@ -21,12 +22,14 @@ import {
|
||||
ValidateIf,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { SMS_CAMPAIGN_CHUNK_SIZE } from '@mento/shared';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { CurrentUser } from '../auth/current-user.decorator';
|
||||
import { Roles } from '../auth/roles.decorator';
|
||||
import { RolesGuard } from '../auth/roles.guard';
|
||||
import { OrgModuleGuard } from '../billing/org-module.guard';
|
||||
import { RequireOrgModule } from '../billing/org-module.decorator';
|
||||
import type { Actor } from '../common/record-scope';
|
||||
import { SmsCampaignsService } from './sms-campaigns.service';
|
||||
|
||||
class CreateSmsCampaignDto {
|
||||
@@ -40,9 +43,17 @@ class CreateSmsCampaignDto {
|
||||
@MaxLength(900)
|
||||
body!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ArrayMaxSize(SMS_CAMPAIGN_CHUNK_SIZE)
|
||||
@IsString({ each: true })
|
||||
personIds!: string[];
|
||||
personIds?: string[];
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ArrayMaxSize(SMS_CAMPAIGN_CHUNK_SIZE)
|
||||
@IsString({ each: true })
|
||||
leadIds?: string[];
|
||||
|
||||
@IsOptional()
|
||||
@ValidateIf((_, v) => v !== '' && v != null)
|
||||
@@ -54,6 +65,20 @@ class CreateSmsCampaignDto {
|
||||
queueNow?: boolean;
|
||||
}
|
||||
|
||||
class AddRecipientsDto {
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ArrayMaxSize(SMS_CAMPAIGN_CHUNK_SIZE)
|
||||
@IsString({ each: true })
|
||||
personIds?: string[];
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ArrayMaxSize(SMS_CAMPAIGN_CHUNK_SIZE)
|
||||
@IsString({ each: true })
|
||||
leadIds?: string[];
|
||||
}
|
||||
|
||||
class ListQueryDto {
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@@ -105,19 +130,17 @@ export class SmsCampaignsController {
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(
|
||||
@CurrentUser()
|
||||
user: { organizationId: string; userId: string; role: string },
|
||||
@Body() dto: CreateSmsCampaignDto,
|
||||
create(@CurrentUser() user: Actor, @Body() dto: CreateSmsCampaignDto) {
|
||||
return this.campaigns.create(user, dto);
|
||||
}
|
||||
|
||||
@Post(':id/recipients')
|
||||
addRecipients(
|
||||
@CurrentUser() user: Actor,
|
||||
@Param('id') id: string,
|
||||
@Body() dto: AddRecipientsDto,
|
||||
) {
|
||||
return this.campaigns.create(
|
||||
{
|
||||
organizationId: user.organizationId,
|
||||
userId: user.userId,
|
||||
role: user.role as 'owner' | 'admin' | 'sales' | 'support',
|
||||
},
|
||||
dto,
|
||||
);
|
||||
return this.campaigns.addRecipients(user, id, dto);
|
||||
}
|
||||
|
||||
@Post(':id/queue')
|
||||
|
||||
Reference in New Issue
Block a user