0.7.5 • Published 3 years ago

chatexchange v0.7.5

Weekly downloads
4
License
GPL-3.0-or-later
Repository
github
Last release
3 years ago

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:

0.7.5

3 years ago

0.6.6

3 years ago

0.7.1

3 years ago

0.7.4

3 years ago

0.6.5

3 years ago

0.7.0

3 years ago

0.6.3

3 years ago

0.6.2

3 years ago

0.6.4

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.2.1

4 years ago

0.3.0

4 years ago

0.2.4-dev

6 years ago

0.2.3-dev

7 years ago

0.2.2-dev

7 years ago

0.2.1-dev

7 years ago

0.2.0-dev

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

1.0.0

8 years ago