Giter VIP home page Giter VIP logo

assemble-chat-bot's Introduction

Assemble Chat Bot

This is a simple framework to enable simple creation of bots that connect to the Assemble Web Chat server.

Please fork and contribute your bot scripts!

Usage

First copy the config.sample.js file to config.js, then copy in a user token (the part after the # in the url) from the server you wish to connect to.

npm install
nodejs main-bot.js <bot-name> <room-names,...>

Creating a bot

To create a bot, add a .js file to the bots folder that exports the following function signatures.

exports.init = function(socket, rooms, config) {...};

exports.shutdown = function(socket, finished_callback) {...};

exports.onmessage = function(socket, mdata) {...};

(optional)
exports.onroomjoin = function(socket, name, room_id) {...}

Note: Its not necessary to store any of the init parameters except for the config.token value (if you wish to send messages back in-chat)

Example message send

exports.onmessage = function(socket, mdata) {
    if (mdata.m.indexOf("@echo")==0) {
        console.log("@echo:", mdata.nick, "-", mdata.m.substring(5));
        socket.emit('chatm', JSON.stringify({"t": token, "room": mdata.room, "m": mdata.m.substring(5), "dur":"1m"}));
    }
};

mdata example:

{ 
    avatar: '',
    dur: '48h',
    m: 'some message',
    msgid: 'XXXXXXXX-YYYY-ZZZZ-AAAA-VVVVVVVVVVVV',
    name: 'Lobby',
    room: 'lobby',
    nick: 'echobot',
    time: 1400030400,
    uid: 'XXXXXXXX-YYYY-ZZZZ-AAAA-VVVVVVVVVVVV' 
}

Note: There is no protection against infinite message loops. Likewise the onmessage function is called even for the bot's own messages. Be careful!

assemble-chat-bot's People

Watchers

 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.