Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b82f76668 | ||
|
|
5fb5eace6e |
No files matched your search
@@ -116,6 +116,7 @@ If you try to send an image the "echo server" will send a path to the downloaded
|
||||
- `DEBUG` - show debug and verbose logs, set in any value
|
||||
- `WHATSAPP_API_PORT` - listen port for HTTP server (default: `3000`)
|
||||
- `WHATSAPP_API_HOSTNAME` - Hostname for HTTP server (default: `localhost`)
|
||||
- `WHATSAPP_START_SESSION` - start session with that name right after launching the app
|
||||
|
||||
## Webhooks
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
@@ -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)
|
||||
|
||||
@@ -46,6 +46,10 @@ export class WhatsappConfigService {
|
||||
return types ? types.split(',') : null
|
||||
}
|
||||
|
||||
get startSession(): string | undefined {
|
||||
return this.configService.get('WHATSAPP_START_SESSION', undefined)
|
||||
}
|
||||
|
||||
get(name: string): any {
|
||||
return this.configService.get(name)
|
||||
}
|
||||
|
||||
@@ -221,6 +221,9 @@ export class WhatsappSessionManager implements OnApplicationShutdown {
|
||||
this.log.setContext('WhatsappSessionManager')
|
||||
this.cleanDownloadsFolder(this.config.filesFolder)
|
||||
this.sessions = {}
|
||||
if (config.startSession) {
|
||||
this.startSession(config.startSession)
|
||||
}
|
||||
}
|
||||
|
||||
async startSession(name: string) {
|
||||
|
||||
Reference in new issue
Block a user