Nest framework TypeScript library Whatsapp
$ yarn add @dkanest/whatsapp
import { Module } from '@nestjs/common';
import { WhatsAppModule } from '@dkanest/whatsapp';
import { ModuleService } from './module.service';
@Module({
imports: [
WhatsAppModule.forRoot(
`<your host>`,
{
noDelay: true,
auth: {
username: `<user>`,
password: `<pass>`,
},
dbName: `<db_name>`,
},
),
],
providers: [ModuleService],
})
export class ModuleModule {}
import { Injectable, OnModuleInit } from '@nestjs/common';
import { generate } from 'qrcode-terminal';
import { WhatsAppService } from '@dkanest/whatsapp';
@Injectable()
export class ModuleService implements OnModuleInit {
constructor(private readonly WhatsApp: WhatsAppService) {
this.WhatsApp.register.on('qr', (qr: string) => {
generate(qr, { small: true });
});
}
onModuleInit() {
this.WhatsApp.register.on('message', (message) => {
console.log('from example', message.body);
});
this.WhatsApp.register.on('ready', () => {
console.log('from module:engine ready');
});
}
}