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 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-rchat-bot

v1.0.0

Published

RChat Bot Client SDK for Node.js

Readme

node-rchat-bot 🤖

Node.js Bot SDK for RChat — Bangun bot interaktif yang kaya fitur untuk platform RChat dengan sintaks yang intuitif, modern, dan mirip Telegram Bot API / Telegraf.

Node.js Socket.IO License


🌟 Fitur Utama

  • ⚡ Realtime WebSocket Connection — Menggunakan Socket.IO (/bot namespace) untuk penerimaan pesan berkecepatan tinggi dengan latensi rendah.
  • 🎯 Context-Driven API (ctx) — Pola ctx.reply(), ctx.replyWithPhoto(), dan ctx.answerCallbackQuery() yang ramah developer.
  • 🎛️ Inline Keyboards & Callback Queries — Tombol interaktif langsung di bawah bubble chat dengan aksi callback atau URL.
  • ⌨️ Custom Reply Keyboard — Tombol menu bawah kustom pengganti keyboard standar.
  • ⚡ Quick Action Buttons — Tombol native 1-ketuk untuk:
    • Salin teks / kode (1-tap copy)
    • Buka tautan web (external URL)
    • Melakukan panggilan telepon (dialer)
    • Mengirim query balik (callback)
  • 🌐 Interactive In-Bubble Widgets — Sematkan antarmuka web interaktif (HTML/CSS/JS atau URL eksternal) langsung di dalam bubble chat RChat, lengkap dengan mode fullscreen, minimize, dan callback query dua arah.
  • 📁 Media Upload & Streaming — Unggah dan kirim foto, audio, voice note, video, dan dokumen secara otomatis melalui multipart form data.

📦 Instalasi

Install melalui npm di dalam proyek Anda:

npm install socket.io-client

Atau salin folder node-rchat-bot ke dalam project Anda:

cd node-rchat-bot
npm install

🚀 Memulai Cepat (Quick Start)

1. Dapatkan Token Bot

Buka aplikasi RChat, buat bot melalui BotFather RChat atau pengaturan Bot API untuk mendapatkan Bot Token Anda:

Contoh Token: rc_123456:abcdefghijklmnopqrstuvwxyz7890

2. Buat Bot Pertama Anda (bot.js)

const RChatBot = require("node-rchat-bot");

// Inisialisasi Bot
const bot = new RChatBot("YOUR_BOT_TOKEN", {
  apiUrl: "https://apirchat.ryudev.site" // atau http://localhost:5000 saat lokal
});

// Event saat bot berhasil terkoneksi & terotentikasi
bot.on("ready", () => {
  console.log("✅ RChat Bot aktif dan siap menerima pesan!");
});

// Tangani pesan masuk
bot.on("message", async (ctx) => {
  const text = ctx.message.body?.trim();

  if (text === "/start") {
    await ctx.reply(`Halo ${ctx.message.sender?.displayName || "Teman"}! Selamat datang di bot RChat. 🚀`);
  } else if (text === "/ping") {
    await ctx.reply("Pong! 🏓");
  }
});

// Jalankan bot
bot.launch();

Jalankan dengan Node.js:

node bot.js

📖 Panduan Penggunaan & Fitur Lengkap

1. Inline Keyboard & Callback Query

Inline keyboard muncul langsung menempel di bawah bubble pesan.

bot.on("message", async (ctx) => {
  if (ctx.message.body === "/menu") {
    await ctx.reply("Silakan pilih salah satu opsi di bawah:", {
      reply_markup: {
        inline_keyboard: [
          [
            { text: "🔔 Kirim Toast", callback_data: "btn_toast" },
            { text: "⚠️ Tampilkan Alert", callback_data: "btn_alert" }
          ],
          [
            { text: "🌐 Buka Website", url: "https://ryudev.site" }
          ]
        ]
      }
    });
  }
});

// Menangkap event klik tombol callback
bot.on("callback_query", async (ctx) => {
  const data = ctx.callbackQuery.data;

  if (data === "btn_toast") {
    // Menampilkan toast di aplikasi pengguna
    await ctx.answerCallbackQuery("Ini adalah notifikasi toast! 🎉");
  } else if (data === "btn_alert") {
    // Menampilkan modal dialog / alert box di aplikasi pengguna
    await ctx.answerCallbackQuery("Perhatian: Ini adalah dialog peringatan modal!", {
      show_alert: true
    });
  }
});

2. Custom Reply Keyboard

Reply keyboard menggantikan keyboard mengetik pengguna dengan grid tombol pintasan.

bot.on("message", async (ctx) => {
  if (ctx.message.body === "/keyboard") {
    await ctx.reply("Keyboard menu diaktifkan:", {
      reply_markup: {
        keyboard: [
          [{ text: "📦 Cek Saldo" }, { text: "🎁 Promo Hari Ini" }],
          [{ text: "📞 Bantuan CS" }, { text: "❌ Tutup Menu" }]
        ],
        resize_keyboard: true
      }
    });
  }

  // Tangani saat pengguna menekan tombol tutup
  if (ctx.message.body === "❌ Tutup Menu") {
    await ctx.reply("Keyboard ditutup.", {
      reply_markup: {
        keyboard: [] // Mengosongkan keyboard kustom
      }
    });
  }
});

3. Native Action Buttons (1-Tap Actions)

Tombol aksi native modern yang dirancang untuk konversi tinggi (misal: tombol salin kupon atau kode bayar):

bot.on("message", async (ctx) => {
  if (ctx.message.body === "/tagihan") {
    await ctx.replyWithButtons(
      "Tagihan Anda telah dibuat:\nNomor VA: 880192837465\nTotal: Rp 50.000",
      [
        {
          type: "copy",
          text: "📋 Salin No. VA",
          value: "880192837465"
        },
        {
          type: "url",
          text: "💳 Bayar Sekarang",
          value: "https://checkout.example.com/pay"
        },
        {
          type: "call",
          text: "📞 Hubungi CS",
          value: "+628123456789"
        }
      ]
    );
  }
});

4. Interactive In-Bubble Widgets (Mini Web Apps)

Sematkan mini web application langsung di dalam bubble chat! Pengguna dapat berinteraksi dengan form, kalkulator, grafik, atau game tanpa keluar dari percakapan.

bot.on("message", async (ctx) => {
  if (ctx.message.body === "/widget") {
    await ctx.replyWithWidget({
      title: "Kalkulator Mini RChat",
      height: 280,
      canMinimize: true,
      html: `
        <!DOCTYPE html>
        <html>
        <head>
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <style>
            body { font-family: sans-serif; padding: 15px; margin: 0; background: #111b21; color: white; text-align: center; }
            button { background: #25d366; color: black; border: none; padding: 10px 18px; border-radius: 8px; font-weight: bold; cursor: pointer; }
          </style>
        </head>
        <body>
          <h3>Mini App RChat</h3>
          <p>Kirim event balik ke bot langsung dari dalam WebView:</p>
          <button onclick="window.RChatWidget?.sendData('ORDER_CONFIRMED')">Konfirmasi Sekarang</button>
        </body>
        </html>
      `
    });
  }
});

5. Mengunggah & Mengirim Media

Bot dapat mengirim gambar, video, dan audio dari path file lokal maupun Buffer.

// Kirim Foto dari file lokal
await ctx.replyWithPhoto("./assets/banner.png", {
  caption: "Promo menarik minggu ini!"
});

// Kirim Audio / Musik
await ctx.replyWithAudio("./assets/greeting.mp3", {
  caption: "Audio sambutan resmi"
});

// Kirim Video
await ctx.replyWithVideo("./assets/demo.mp4", {
  caption: "Panduan penggunaan aplikasi"
});

6. Edit Pesan (Live Updates)

Ubah teks atau markup tombol pesan yang sudah terkirim (berguna untuk polling, counter live, atau wizard interaktif):

bot.on("callback_query", async (ctx) => {
  if (ctx.callbackQuery.data === "refresh_data") {
    await ctx.editMessageText("🔄 Data telah diperbarui pada " + new Date().toLocaleTimeString(), {
      reply_markup: {
        inline_keyboard: [
          [{ text: "🔄 Refresh Lagi", callback_data: "refresh_data" }]
        ]
      }
    });
  }
});

📚 Referensi API

new RChatBot(token, [options])

  • token (String): Bot API Token dari RChat.
  • options (Object):
    • apiUrl (String): URL server backend RChat (Default: http://localhost:5000). Gunakan https://apirchat.ryudev.site untuk server produksi.

Event Emitter

  • bot.on("ready", () => {}) — Terpanggil saat bot berhasil terhubung dan diautentikasi.
  • bot.on("message", (ctx) => {}) — Terpanggil saat ada pesan masuk baru.
  • bot.on("callback_query", (ctx) => {}) — Terpanggil saat tombol inline ditekan.
  • bot.on("error", (err) => {}) — Terpanggil jika terjadi error koneksi / socket.
  • bot.on("disconnect", (reason) => {}) — Terpanggil saat koneksi socket terputus.

Context Object (ctx)

| Method | Deskripsi | | :--- | :--- | | ctx.reply(text, [extra]) | Mengirim pesan balasan ke chat terkait. | | ctx.replyWithPhoto(file, [extra]) | Mengirim gambar (filePath string atau Buffer). | | ctx.replyWithAudio(file, [extra]) | Mengirim file audio. | | ctx.replyWithVideo(file, [extra]) | Mengirim file video. | | ctx.replyWithMedia(mediaIds, [extra]) | Mengirim media berdasarkan media ID yang telah diunggah. | | ctx.replyWithButtons(text, buttons, [extra]) | Mengirim pesan dengan tombol 1-ketuk (copy, url, call, callback). | | ctx.replyWithWidget(options, [extra]) | Mengirim pesan dengan in-bubble web widget (HTML / URL). | | ctx.answerCallbackQuery(text, [extra]) | Menjawab query tombol inline (toast notification atau alert dialog). | | ctx.editMessageText(text, [extra]) | Mengedit isi teks pesan yang ada. | | ctx.editMessageReplyMarkup(replyMarkup) | Mengedit hanya tombol/markup dari pesan yang ada. |


🛠️ Menjalankan Script Uji Bawaan

SDK ini dilengkapi dengan file pengujian interaktif test.js:

# Menjalankan ke server lokal
node test.js <TOKEN_BOT_ANDA>

# Menjalankan ke server VPS / Production
RCHAT_API_URL=https://apirchat.ryudev.site node test.js <TOKEN_BOT_ANDA>

📄 Lisensi

Proyek ini dilisensikan di bawah MIT License. Dikembangkan untuk ekosistem aplikasi RChat.