JSPM

whatsapp-web-api

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14
  • Score
    100M100P100Q60887F
  • License ISC

WhatsApp Web API - TypeScript/JavaScript. ditenagai oleh library: Baileys.

Package Exports

  • whatsapp-web-api
  • whatsapp-web-api/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (whatsapp-web-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

WhatsApp Web API - TypeScript/JavaScript

WhatsApp Web API ini ditenagai oleh library: Baileys

Instalasi

Menggunakan Npm

npm i whatsapp-web-api

Atau Menggunakan Yarn

yarn add whatsapp-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": {
    "whatsapp-web-api": "latest"
  },
  "devDependencies": {
    "nodemon": "~3.0.1"
  }
}

./nodemon.json

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

./index.js

const wwa = require('whatsapp-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: '.'
};

./includes/client.js

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

module.exports = async ({
  client,
  msg,
  store
}) => {
  try {
    const body = msg.mtype === 'conversation' ? msg.message.conversation : msg.mtype === 'extendedTextMessage' ? msg.message.extendedTextMessage.text : '';
    const budy = typeof msg.text === 'string' ? msg.text : '';
    const isCommand = body.startsWith(config.prefix) ? body.replace(config.prefix, '').trim().split(/ +/).shift().toLowerCase() : '';
    const command = isCommand.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 quoted = msg[0];

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

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

      console.log(
        chalk.bgMagenta(' [New Message] '),
        chalk.cyanBright('Time: ') + chalk.greenBright(new Date()) + '\n',
        chalk.cyanBright('Message: ') + chalk.greenBright(budy || msg.mtype) + '\n' +
        chalk.cyanBright('From:'), chalk.greenBright(msg.pushName), chalk.yellow('- ' + msg.sender.split('@')[0]) + '\n' +
        chalk.cyanBright('Chat Type:'), chalk.greenBright(!msg.isGroup ? 'Private Chat - ' + chalk.yellow(client.user.id.split(':')[0]) : 'Group Chat - ' + chalk.yellow(msg.chat.split('@')[0]))
      );
    };

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

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

Contoh kode/skrip bot WhatsApp lengkap

Klik disini untuk mengunduh proyek.

Informasi

  • Pembuat / Pengembang: Dani Technology (Dani Ramdani) - FullStack Engineer
  • Kontak Pembuat / Pengembang: 0895 3416 24750 (WhatsApp), contact@danitechno.com (Email)

Terimakasih Kepada

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