@dkanest/whatsapp
TypeScript icon, indicating that this package has built-in type declarations

0.1.20 • Public • Published

Nest Logo

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');
    });
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @dkanest/whatsapp

Weekly Downloads

0

Version

0.1.20

License

MIT

Unpacked Size

195 kB

Total Files

31

Last publish

Collaborators

  • yovangga