Code Monkey home page Code Monkey logo

chat-bot-sdk's Introduction

chat-bot-sdk

A simple chat bot SDK for [bitwave.tv]'s chat

Install it with.

npm install @bitwave/chat-bot-sdk

Design

The exported object has three key properties:

  • transformers - an array of functions taking a Message object and either returning it, or a falsy value. They serve to transform the message
  • filters - an array of functions taking a Message object and either returning it, or a falsy value. They serve to filter out messages
  • consumer - The unary function called after transformations and filtering.

Messages are first fed through transformers, then filtered, and then consumed.

Transformers are functions that change the message somehow. For example, one of the default ones turns received HTML into Markdown. A transformer can deny a message by returning a falsy value, which causes it to get dropped.

Filters are functions that approve messages according to a requirement. For example, one of the default ones checks if a message is visible. They do so by either returning the message (approve) or returning a falsy value (drop). They shouldn't change the message.

The consumer is a function that takes the filtered, transformed message. By default, this is a function that console.logs it and sends it to the command parser.

Command parser

The command parser is configured in the commandParserSettings object. It contains the message prefix, a map of commands (command name -> {command: function}).

The command function receives the message object that triggered it as the first parameter. Each whitespace-separated block is sent as a subsequent parameter. You can write ...rest to collect all the individual arguments into an array.

Command functions take two arguments: the message that triggered them, and an array of arguments.

chat-bot-sdk's People

Contributors

dependabot[bot] avatar diingus avatar dispatchcommit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.