npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

w-api-wrapper

v1.0.0

Published

Uma biblioteca JavaScript para integração com a API do WhatsApp W-API

Readme

W-API Wrapper

Uma biblioteca JavaScript para integração com a API do WhatsApp W-API. Essa biblioteca facilita o envio de mensagens, criação de grupos e gerenciamento de instâncias do WhatsApp.

Instalação

npm install w-api-wrapper

Uso Básico

const { WApiClient } = require('w-api-wrapper');

// Inicialize o cliente com sua API key e Instance ID
const client = new WApiClient('sua-api-key', 'seu-instance-id');

// Exemplo: Enviar uma mensagem de texto
async function enviarMensagem() {
  try {
    const resultado = await client.sendTextMessage('[email protected]', 'Olá, esta é uma mensagem de teste!');
    console.log('Mensagem enviada:', resultado);
  } catch (error) {
    console.error('Erro ao enviar mensagem:', error);
  }
}

enviarMensagem();

Exemplos de Uso

Inicializar uma Instância

async function inicializarInstancia() {
  try {
    const resultado = await client.initInstance();
    console.log('Instância inicializada:', resultado);
  } catch (error) {
    console.error('Erro ao inicializar instância:', error);
  }
}

Obter QR Code para Autenticação

async function obterQRCode() {
  try {
    const qrCode = await client.getQrCode();
    console.log('QR Code:', qrCode);
  } catch (error) {
    console.error('Erro ao obter QR code:', error);
  }
}

Enviar Mensagem com Imagem

async function enviarImagem() {
  try {
    const resultado = await client.sendImageMessage(
      '[email protected]',
      'Confira esta imagem!',
      'https://exemplo.com/imagem.jpg'
    );
    console.log('Imagem enviada:', resultado);
  } catch (error) {
    console.error('Erro ao enviar imagem:', error);
  }
}

Enviar Mensagem com Botões

async function enviarBotoes() {
  try {
    const botoes = [
      { id: 'btn1', text: 'Opção 1' },
      { id: 'btn2', text: 'Opção 2' },
      { id: 'btn3', text: 'Opção 3' }
    ];
    
    const resultado = await client.sendButtonMessage(
      '[email protected]',
      'Escolha uma opção',
      'Por favor, selecione uma das opções abaixo:',
      botoes,
      'Responda clicando em um botão'
    );
    console.log('Mensagem com botões enviada:', resultado);
  } catch (error) {
    console.error('Erro ao enviar mensagem com botões:', error);
  }
}

Criar um Grupo

async function criarGrupo() {
  try {
    const participantes = ['[email protected]', '[email protected]'];
    const resultado = await client.createGroup('Nome do Grupo', participantes);
    console.log('Grupo criado:', resultado);
  } catch (error) {
    console.error('Erro ao criar grupo:', error);
  }
}

Integração com Sistema de Agendamento

Para integrar com um sistema de agendamento em seu site, você pode usar o seguinte exemplo:

// Quando um cliente fizer um agendamento em seu site
async function notificarAgendamento(dadosAgendamento) {
  try {
    const { nome, telefone, data, hora, servico } = dadosAgendamento;
    
    // Formatar o número do telefone para o formato do WhatsApp (com @c.us no final)
    const numeroFormatado = telefone.replace(/\D/g, '') + '@c.us';
    
    // Criar a mensagem de confirmação
    const mensagem = `Olá ${nome}, seu agendamento foi confirmado!\n\nServiço: ${servico}\nData: ${data}\nHorário: ${hora}\n\nAguardamos você!`;
    
    // Enviar a mensagem para o cliente
    const resultado = await client.sendTextMessage(numeroFormatado, mensagem);
    console.log('Notificação de agendamento enviada:', resultado);
    
    return resultado;
  } catch (error) {
    console.error('Erro ao enviar notificação de agendamento:', error);
    throw error;
  }
}

Métodos Disponíveis

Instâncias

  • getInstance() - Obter informações da instância
  • initInstance() - Inicializar uma instância
  • getQrCode() - Obter o QR code para autenticação
  • logout() - Desconectar da instância

Mensagens

  • sendTextMessage(to, body) - Enviar mensagem de texto
  • sendImageMessage(to, caption, url) - Enviar mensagem com imagem
  • sendFileMessage(to, caption, url) - Enviar mensagem com arquivo
  • sendButtonMessage(to, title, description, buttons, footer) - Enviar mensagem com botões

Grupos

  • createGroup(name, participants) - Criar um grupo
  • addGroupParticipants(groupId, participants) - Adicionar participantes a um grupo
  • removeGroupParticipants(groupId, participants) - Remover participantes de um grupo

Contatos e Chats

  • getContacts() - Obter lista de contatos
  • getChats() - Obter lista de chats

Licença

MIT