@dkanest/mqtt
v0.0.6
Published
<p align="center"> <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a> </p>
Downloads
62
Readme
Description
Nest framework TypeScript library Whatsapp
Project setup
$ yarn add @dkanest/whatsapp
On Module
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 {}
On Service
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');
});
}
}