Skip to content

Commit

Permalink
Add GET /checkNumberStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
allburov committed Sep 27, 2022
1 parent ac865ab commit 5fb5eac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/api/all.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export class SessionQuery {
sessionName: string = WHATSAPP_DEFAULT_SESSION_NAME;
}

export class CheckNumberStatusQuery extends SessionQuery {
@IsString()
phone: string
}

export class MessageTextQuery extends SessionQuery {
@IsString()
phone: string
Expand Down
15 changes: 15 additions & 0 deletions src/api/chatting.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Body, Controller, Get, NotImplementedException, Post, Query} from '@nest
import {ApiOperation, ApiTags} from "@nestjs/swagger";
import {
ChatRequest,
CheckNumberStatusQuery,
MessageContactVcard,
MessageFile,
MessageImage,
Expand All @@ -19,6 +20,20 @@ export class ChattingController {
constructor(private whatsappSessionManager: WhatsappSessionManager) {
}

@Get('/checkNumberStatus')
@ApiOperation({summary: 'Check number status'})
async checkNumberStatus(
@Query() request: CheckNumberStatusQuery,
) {
const whatsapp = this.whatsappSessionManager.getSession(request.sessionName)
try {
const result = await whatsapp.checkNumberStatus(ensureSuffix(request.phone))
return {numberExists: result['numberExists']}
} catch (e) {
return {numberExists: false}
}
}

@Post('/sendContactVcard')
sendContactVcard(@Body() message: MessageContactVcard) {
const whatsapp = this.whatsappSessionManager.getSession(message.sessionName)
Expand Down

0 comments on commit 5fb5eac

Please sign in to comment.