Giter Club home page Giter Club logo

wa-web-api's Introduction

WhatsApp Web API - TypeScript/JavaScript

WhatsApp Web API ini ditenagai oleh library: Baileys

Instalasi

Menggunakan Npm

npm i @danitech/wa-web-api

Atau Menggunakan Yarn

yarn add @danitech/wa-web-api

Contoh Kode

./package.json

{
  "name": "whatsapp-bot",
  "version": "0.0.0",
  "private": true,
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  },
  "dependencies": {
    "@danitech/wa-web-api": "latest"
  },
  "devDependencies": {
    "nodemon": "~3.0.1"
  }
}

./nodemon.json

{
  "ignore": ["index.js"],
  "ext": "js"
}

./index.js

const wwa = require('@danitech/wa-web-api');
const fs = require('fs');
const chalk = require('chalk');
const config = require('./config/settings.js');
const client = require('./includes/client.js');

const {
  makeWASocket
} = wwa;

const startServer = (config, client) => {
  return makeWASocket(config, client);
};

startServer(config, client);

./config/settings.js

module.exports = {
  pairing_mode: true,
  session_folder_name: 'session',
  browser: ["Chrome (Linux)"],
  public_mode: true,
  prefix: '.',
  bot: {
    name: 'Bot Name'
  },
  owner: {
    name: 'Owner Name',
    number: '628xxx'
  }
};

./includes/client.js

const chalk = require('chalk');
const config = require('../config/settings.js');

module.exports = async ({
  client,
  messages
}) => {
  try {
    const body = messages.mtype === 'conversation' ? messages.message.conversation : messages.mtype === 'extendedTextMessage' ? messages.message.extendedTextMessage.text : '';
    const budy = typeof messages.text === 'string' ? messages.text : '';
    const command = body.startsWith(config.prefix) ? body.replace(config.prefix, '').trim().split(/ +/).shift().toLowerCase() : '';
    const cleanCommand = command.replace(config.prefix, '');
    const args = body.trim().split(/ +/).slice(1);
    const query = q = args.join(' ');
    const query1 = q1 = query.split('|')[0]
    const query2 = q2 = query.split('|')[1]

    const ownerNumbers = config.owner.number;
    const senderNumber = messages.sender.replace(/\D/g, '');
    const senderName = messages.pushName || 'Undefined';
    const isOwner = ownerNumbers.includes(messages.sender);

    if (!config.public_mode) {
      if (!messages.key.fromMe) {
        return;
      };
    };

    if (messages.message) {
      client.readMessages([messages.key]);

      console.log(
        chalk.bgMagenta(' [New Message] '),
        chalk.cyanBright('Time: ') + chalk.greenBright(new Date()) + '\n',
        chalk.cyanBright('Message: ') + chalk.greenBright(budy || messages.mtype) + '\n' +
        chalk.cyanBright('From:'), chalk.greenBright(senderName), chalk.yellow('- ' + senderNumber) + '\n' +
        chalk.cyanBright('Chat Type:'), chalk.greenBright(!messages.isGroup ? 'Private Chat' : 'Group Chat - ' + chalk.yellow(messages.chat))
      );
    };

    if (!body.startsWith(config.prefix) || body === config.prefix) {
      return;
    };

    switch (cleanCommand) {
      case 'test': {
        messages.reply('Ok, Success!');
        break;
      };
      
      default: {
        messages.reply(`Command: ${config.prefix}${cleanCommand}, tidak tersedia!`);
      };
    };
  } catch (error) {
    messages.reply('Terjadi kesalahan pada server.');
    console.error(error);
  };
};

Contoh kode/skrip bot WhatsApp lengkap

Klik disini untuk mengunduh proyek.

Informasi

  • Pembuat / Pengembang: Dani Ramdani (Dani Techno.) - FullStack Engineer
  • Kontak Pembuat / Pengembang: 0895 1254 5999 (WhatsApp), [email protected] (Email)

Terimakasih Kepada

  • Dani Techno. - FullStack Engineer (Pembuat / Pengembang)
  • @whiskeysockets/baileys (Penyedia Library "Baileys")

wa-web-api's People

Contributors

danitechnology avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.