Add whatsapp, Device functions
This commit is contained in:
1 parent
70487d2ee5
commit
c6ef18bae7
10 files changed
+1399
-86
No files matched your search
@@ -1,3 +1,5 @@
|
||||
tokens
|
||||
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
|
||||
Generated
+1318
-61
File diff suppressed because it is too large.
Load diff
+2
-1
@@ -29,7 +29,8 @@
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^6.5.4",
|
||||
"swagger-ui-express": "^4.1.4"
|
||||
"swagger-ui-express": "^4.1.4",
|
||||
"venom-bot": "^2.0.16"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^7.0.0",
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export class Message {
|
||||
export class MessageOut {
|
||||
readonly chatId: string;
|
||||
readonly text: string;
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import {Injectable} from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class ApiService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,13 @@
|
||||
import {Body, Controller, Post} from '@nestjs/common';
|
||||
import {ApiService} from './api.service';
|
||||
import {ApiOperation, ApiTags} from "@nestjs/swagger";
|
||||
import {Message, MessageReply} from "./all.dto";
|
||||
import {MessageOut, MessageReply} from "./all.dto";
|
||||
|
||||
@Controller('api')
|
||||
@ApiTags('chatting')
|
||||
export class ChattingController {
|
||||
constructor(private readonly apiService: ApiService) {
|
||||
}
|
||||
|
||||
@Post('/sendText')
|
||||
@ApiOperation({summary: 'Send a text message'})
|
||||
sendText(@Body() message: Message) {
|
||||
sendText(@Body() message: MessageOut) {
|
||||
return `You've sent: ${message.chatId} - ${message.text}`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,48 @@
|
||||
import {Controller, Get} from '@nestjs/common';
|
||||
import {Controller, Get, Inject, Post} from '@nestjs/common';
|
||||
import {ApiTags} from "@nestjs/swagger";
|
||||
import {Whatsapp} from "venom-bot";
|
||||
|
||||
|
||||
@Controller('api')
|
||||
@ApiTags('device')
|
||||
export class DeviceController {
|
||||
constructor(@Inject('WHATSAPP') private whatsapp: Whatsapp) {
|
||||
}
|
||||
|
||||
@Post('/killServiceWorker')
|
||||
killServiceWorker() {
|
||||
return this.whatsapp.killServiceWorker()
|
||||
}
|
||||
|
||||
@Post('/restartService')
|
||||
restartService() {
|
||||
return this.whatsapp.restartService()
|
||||
}
|
||||
|
||||
@Get('/getHostDevice')
|
||||
getHostDevice(): string {
|
||||
return 'hostDevice'
|
||||
getHostDevice() {
|
||||
return this.whatsapp.getHostDevice()
|
||||
}
|
||||
|
||||
@Get('/getConnectionState')
|
||||
getConnectionState(): string {
|
||||
return 'getConnectionState'
|
||||
getConnectionState() {
|
||||
return this.whatsapp.getConnectionState()
|
||||
}
|
||||
|
||||
@Get('/getBatteryLevel')
|
||||
getBatteryLevel() {
|
||||
return this.whatsapp.getBatteryLevel()
|
||||
}
|
||||
|
||||
@Get('/isConnected')
|
||||
isConnected() {
|
||||
return this.whatsapp.isConnected()
|
||||
}
|
||||
|
||||
@Get('/getWAVersion')
|
||||
getWAVersion(): string {
|
||||
return 'getWAVersion'
|
||||
getWAVersion() {
|
||||
return this.whatsapp.getWAVersion()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
import {Module} from '@nestjs/common';
|
||||
import {ChattingController} from './api/chattingController';
|
||||
import {ApiService} from './api/api.service';
|
||||
import {DeviceController} from "./api/device.controller";
|
||||
import {whatsappProvider, WhatsappService} from "./whatsapp.service";
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [ChattingController, DeviceController],
|
||||
providers: [ApiService],
|
||||
providers: [whatsappProvider, WhatsappService],
|
||||
})
|
||||
export class AppModule {
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import {DocumentBuilder, SwaggerModule} from "@nestjs/swagger";
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.enableShutdownHooks();
|
||||
const options = new DocumentBuilder()
|
||||
.setTitle('WhatsApp HTTP API')
|
||||
.setDescription('WhatsApp HTTP API that you can configure in a click')
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import {create, Whatsapp} from "venom-bot";
|
||||
import {Inject, Injectable, OnApplicationShutdown} from "@nestjs/common";
|
||||
|
||||
export const whatsappProvider = {
|
||||
provide: 'WHATSAPP',
|
||||
useFactory: async () => create('sessionName',
|
||||
(base64Qr, asciiQR) => {
|
||||
console.log(asciiQR);
|
||||
},
|
||||
(statusFind) => {
|
||||
console.log(statusFind);
|
||||
},
|
||||
{
|
||||
headless: true,
|
||||
devtools: false,
|
||||
useChrome: true,
|
||||
debug: false,
|
||||
logQR: true,
|
||||
browserArgs: ["--no-sandbox"],
|
||||
autoClose: 60000,
|
||||
disableSpins: true,
|
||||
createPathFileToken: true,
|
||||
puppeteerOptions: {},
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class WhatsappService implements OnApplicationShutdown {
|
||||
constructor(@Inject('WHATSAPP') private whatsapp: Whatsapp) {
|
||||
}
|
||||
|
||||
onApplicationShutdown(signal?: string): any {
|
||||
console.log('Close a browser...')
|
||||
return this.whatsapp.close()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user