Socket
Socket
Sign inDemoInstall

chatexchange

Package Overview
Dependencies
56
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chatexchange

A node.js wrapper for talking to Stack Exchange chat


Version published
Weekly downloads
21
decreased by-52.27%
Maintainers
3
Install size
8.64 MB
Created
Weekly downloads
 

Readme

Source

ChatExchange

Build Build Status Coverage Status

A Node.js API for talking to Stack Exchange chat (Largely based on ChatExchange for python)

Installation

Using NPM:

$ npm i chatexchange

Example

const Client = require("chatexchange");

const { ChatEventType } = require("chatexchange");

const main = async () => {
  const client = new Client("stackoverflow.com");

  await client.login("EMAIL", "PASSWORD");

  const me = await client.getMe();

  const myProfile = await client.getProfile(me);

  const { roomCount } = myProfile;
  console.log(`Rooms I am in: ${roomCount}`);

  const room = client.getRoom(167908);

  room.ignore(ChatEventType.FILE_ADDED);

  const joined = await client.joinRoom(room);
  if(joined) {
    room.on("message", async (msg) => {
        console.log("Got Message", msg);

        const { eventType, targetUserId } = msg;

        if (eventType === ChatEventType.USER_MENTIONED && targetUserId === me.id) {
            await msg.reply("Hello World!");
        }

        if(eventType === ChatEventType.USER_LEFT) {
            await msg.send("See you around!", room);
        }
    });

    // Leave the room after five minutes
    setTimeout(async () => {
        await room.sendMessage("Bye everyone!");
        await client.leaveRoom(room);
    }, 3e5);

    // Connect to the room, and listen for new events
    await room.watch();
    return;
  }

  await client.logout();
};

main();

Implementations

Featured projects using ChatExchange:

FAQs

Last updated on 23 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc