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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fb-live-stream-chatbot-module

v1.1.4

Published

Module to read and write to facebook live streams

Downloads

3

Readme

fb-live-stream-chatbot-module

Library that contains an extensible implementation for facebook gaming chatbots as well as a module to mangage them across several videos and pages.

NPM JavaScript Style Guide

Install

npm install --save fb-live-stream-chatbot-module

Goal

The goal of this library is to provide a simple interface for building facebook gaming chatbots and a straightforward way to use them.

Directions for creating and using chatbots

Creating a bot

There are two ways to create a bot.

  1. Create a factory class that extends the FacebookChatBotFactory and a class that extends the FaceBookChatBot class.

If you're extending the FaceBookChatBot then you may be required to set your commandMap manually if you require any internal scoping.

export class BlackJackBotFactory extends FaceBookChatBotFactory {
    createBot(videoId: string, accessToken: string) {
      return new BlackJackBot(super.name, videoId, accessToken);
    }
  }

export class BlackJackBot extends FaceBookChatBot {
  bjGames = new Map();
  constructor(name: string, videoId: string, accessToken: string) {
    super(name, videoId, accessToken);
    this.commandMap.set('!blackjack', {
      chatBot: (event: MessageEvent) => this.startGameCommand(event),
    });
    this.commandMap.set('!stand', {
      chatBot: (event: MessageEvent) => this.standCommand(event),
    });
    this.commandMap.set('!hit', {
      chatBot: (event: MessageEvent) => this.hitCommand(event),
    });
  }
  //... Method implementations, etc

}
  1. The second way to create a bot is to use the default FaceBookChatBotFactory and FaceBookChatBot implementations. While they don't allowing any internal scoping, you can pass in a Map<string,ChatBotCommand> that will act as the command handlers.
const commandMap = new Map<string, ChatBotCommand>();
commandMap.set('!testCommand1', {
    chatBot: (event: MessageEvent) => console.log("execute command1")
});
commandMap.set('!testCommand2', {
    chatBot: (event: MessageEvent) => console.log("execute command2")
});
const newFactory = new FaceBookChatFactory('testBot', commandMap);

Using the chat bot module

The module currently supports multiple event sources so internally maps EventSource instances to chatbots.

// initial the module, this module will handle all event sources, factories, and bots
const fbModule = new FaceBookChatBotModule();
// create the factory that we will register to the module
const chatBotFactory = new BlackJackBotFactory("blackJack");
// create and register the EvenSource for the video. A Page access token is required
// see here for details https://developers.facebook.com/docs/pages/access-tokens/
fbModule.registerEventSource(
    new EventSourceAdapter({videoId:"videoId", accessToken:"accessToken"}));
// Installs the BlackJackBotFactory we create earlier
fbModule.install(chatBotFactory);
// register the bot. Internally this calls the factory class to create the bot and link it with the event source
fbModule.registerBot("blackJack", "videoId", "accessToken");

Afer the setup the module will listen for events from the provided videoId and process commands from any messages it receives. When an EventSource is closed the module will clean up the EventSource and any chatbots current associated with it.

In the future there will also be an implementation that allows the module to control the chat bots at a page level vs a video level. This will allow for long living bots, but the implementer will have to manage the videoIds themselves as new live streams are created.

Also in the future, there will be the ability to have single instance chatbots accessible across multiple EventSource instances since not all chatbots will require a video/page level state.

Supporting 3rd party Chat Bots

As the chat bots grow, this list aims to serve as a central place for reference. This will hopefully allow contributers to create their own chatbot implementations that other users of this library will be able to leverage.

Current chat bots

  • BlackJackChatBot

MIT © jeremyheaton