Giter Site home page Giter Site logo

dcsan / gitterbot Goto Github PK

View Code? Open in Web Editor NEW
61.0 15.0 83.0 15.12 MB

GitterBot / gitter chatbot with Wiki integration, and more!

Home Page: https://gitter.im/dcsan/gitterbot

JavaScript 90.85% CSS 0.27% HTML 4.02% Shell 2.97% Batchfile 0.04% CoffeeScript 1.85%

gitterbot's Introduction

NOTE: CamperBot contributions have moved to FreeCodeCamp/camperbot

Airtable recommendation

update: I'm using Airtable to store some data. It's a very cool 'google docs meets DB' service and if you sign up here, I'll get some credit on my account. Thanks! https://airtable.com/invite/bV2PbVkk

GitterBot!

This is a full featured bot for Gitter. Main features:

  • integration with github Wiki
  • search, find
  • wrapper for commands

Gitter

The GBot is integrated into FreeCodeCamp

Join us in Gitter to discuss! https://gitter.im/dcsan/gitterbot

Introducing GitterBot!

GitterBot is a full featured bot for Gitter.im First developed to integrate with the chatrooms for FreeCodeCamp, the largest online bootcamp in the world, where he supports more than 15,000 users in the main chatroom.

Github Wiki Search

You can search for articles in a projects github wiki

Share wiki summaries in chat

Use explain to pull a wiki summary right into the chat:

Points system

Allow your users to send points to each other to say 'thanks @friend'!

points

Fixed messages

Based on scannable expressions, send messages into the chat.

Extensible

Custom functions can easily be added. Check the System overview
or contact RIKAI Labs.

Installation instructions

To run GitterBot, you need Node.js before downloading the app.

Mac / Linux

  • To install Node, follow the instructions here

  • To make your file changes update the local server automatically, install nodemon (you may need sudo)

      sudo npm install -g nodemon
    
  • To download the app, clone the repository the bot is in:

      git clone [email protected]:dcsan/gitterbot.git
    
  • Run the following commands to run the app:

      cd gitterbot
      cd nap
      cp dot-EXAMPLE.env dot.env
      nodemon app.js
    
  • That's it! The app should be running at http://localhost:7891.

You can now chat to your gitterbot via Gitter at https://gitter.im/demobot/test

Windows

To install Node.js on Windows, follow these instructions.

  • To make your file changes update the local server automatically, install nodemon in an administrator console.

      npm install -g nodemon
    
  • To download the app, clone the repository the bot is in:

      git clone https://github.com/dcsan/gitterbot.git
    
  • Run the following commands to run the app:

     cd gitterbot
     cd nap
     ren dot-EXAMPLE.env dot.env
     nodemon app.js
    
  • That's it! The app should be running at http://localhost:7891.

You can now chat to your gitterbot via Gitter at https://gitter.im/demobot/test

Getting your own appID

The dot.env file you copied above contains login info. This is using shared "demobot" account so you may find yourself in a chatroom with other people using the same ID!

To setup this up and use your own gitter login info, you should create your own Gitter API key on their developer site, and replace the info in that .env file. Get your own API keys for gitter from: https://developer.gitter.im/apps

For more settings info, checkout the AppConfig.js and RoomData.js files. These define which rooms the bot will listen in to. You can ping us in the Dev Chatroom if you have problems gitterbot chatroom .

Running tests

There are other commands in bin for running tests with the right config files etc To run the tests with the right configs

$ bin/test.sh

Wiki Content

The wiki content is pulled in from FCC's wiki using a git submodule. But then we just copy it and commit it back to the main app as submodules are nasty to deal with on production servers.

bin/wiki-update.sh

System Overview

data/RoomData.js

The list of rooms your bot is going to join. Very starting your own bot, create a test room to enter and debug with. This needs to be changed so you would only join your own rooms, otherwise developers will get into a situation where everyone is joining the same rooms and the bots go crazy talking to each other!

lib/bot/BotCommands.js

This is where you add things that the bot can do. Some commands are broken into separate files such as cmds/thanks and cmds/about. Each command gets a input which is a blob of data including what the user entered, and a bot instance.

KBase.js

The Knowledge base. This is an interface to all the data in the wiki.

RoomMessages.js

This is for static messages that are fired based on regex matches. If you just want to add some basic responses, this is the place to edit.

How to add a new Bot Command

Look at BotCommands echo function. This is an example of a command being called. Anytime a user types a line starting with echo that will get passed to this function in input.

    echo: function(input, bot) {
        var username = input.message.model.fromUser.username;
        return "@" + username + " said: " + input.message.model.text;
    },

The input object contains keyword and params fields. If you type echo this you'll get

//input
{   
    keyword: 'echo',
    params: 'this'
}

From any command you just return the new string you want to output. So you can add new commands with this knowledge.

More detail on how commands are found and called

In GBot.js

    if (input.command) {
        // this looks up a command and calls it
        output = BotCommands[input.keyword](input, this);
    } else {

BotCommands is a list of functions, eg

BotCommands.thanks = function() { ... }

where input.keyword is thanks then

BotCommands[input.keyword] is like saying BotCommands.thanks()

so then the params get also added in (input, this) so its

BotCommands[input.keyword](input, this);
//becomes
BotCommands.thanks(input, bot);

All of the botCommands expect these two params eg in thanks.js

var commands = {
    thanks: function (input, bot) {

In RoomMessages.js we also have a table of regex and matching functions, and may switch all to just use this method in future. Would you like to help?

    {
        regex: /\bth?a?n?[xk]s?q?\b/gim,
        func: BotCommands.thanks
    }

environment notes

wiki data

we use git submodules for some wiki data. to get these submodules you would do:

git submodule init
git submodule update

ES6 and iojs

We downgraded the app to use basic node, so it should run even without iojs. But its recommended to run on iojs rather than the older node (until they merge the projects) To do this:

# ubuntu
sudo apt-get upgrade
sudo apt-get install build-essential

we're using n to update node article We use n to manage iojs and node:

sudo npm install -g n
sudo n io latest
iojs -v
    // should be at least v2.4.0

Contributing

have a look at the HelpWanted label issues and consider making some first steps! the labels, P1 = priority one, and 'S' means a small task, so good places to start. https://waffle.io/dcsan/gitterbot

Chat to us!

Ping me @dcsan in the gitterbot chatroom if you get stuck.

gitterbot's People

Contributors

abhisekp avatar benmcmahon100 avatar darthmeme avatar dcsan avatar dting avatar irinatag avatar kirah1314 avatar oab00 avatar opatel99 avatar saintpeter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gitterbot's Issues

fix links to MDN content

image

there are some methods in the main freecodecamp repo to convert the links in the content to actual MDN URLs.

Unexpected end of input

on response from about api call.

bot-0 (err): SyntaxError: Unexpected end of input
bot-0 (err):     at Object.parse (native)
bot-0 (err):     at IncomingMessage.<anonymous> (/home/freecodecamp/www/gitterbot/nap/lib/utils/HttpWrap.js:30:33)
bot-0 (err):     at emitNone (events.js:72:20)
bot-0 (err):     at IncomingMessage.emit (events.js:166:7)
bot-0 (err):     at endReadableNT (_stream_readable.js:889:12)
bot-0 (err):     at doNTCallback2 (node.js:430:9)
bot-0 (err):     at process._tickCallback (node.js:344:17)
bot-0 (err): connect.multipart() will be removed in connect 3.0
bot-0 (err): visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
bot-0 (err): connect.limit() will be removed in connect 3.0

bonfire command to set current bonfire / welcome message

eg

^bonfire mutations

set the current bonfire topic inside the bot
if bonfire room, send a detailed message with options
if mainchats, just send a short info message


bonfire: [mutations].

we have [four] hints.

  • hint will show a hint.
  • comments will show user comments
  • seed will remind you about the javascript

auth required sometimes?

is this an error type when a user doesn't exist?

bot-0 showInfo { error: 
   { name: 'Error',
     status: 401,
     message: 'Authorization Required',
     statusCode: 401,
     code: 'AUTHORIZATION_REQUIRED' } }

image

give karma system from the chats

when a user helps you in the chat, enable a way to give that user some karma

  • end of a chat user1 says “ktx @user
  • bot replies: give karma to $GITHUB_USERNAME?
    this sends karma to that user via an FCC api based on github username
  • log the conversation to our own DB, not just gitter IM
    from the beginning of that topic chat
    then need some way to summarize the chat and store it in the logs
    maybe later a way to edit these chats to pick the highlights, or use as material for machine learning/training.

merge help / find commands

its confusing whether to use find (search) or help(wiki page)
these could be merged

eg help js

find all titles with js in them
if more than one, show a list
if exactly one then show that entry right away

if its not an exact match it should still return options eg
help ternary should match js ternary
currently help just looks for an exact filename

ideally we could do some kind of fuzzy search for misspellings, and also rank the results, but that's way out.

search should deep search the content of all the articles, not just the titles.
find just looks at titles

image

refactor send thanks to send to multiple @mentionds

if you send karma to multiple people

ideally the calls to send karma should be refactored as they currently rely on returning their message.
simple fix: instead just use an async bot.says() so the messages can go out and control flow will continue to the next send event.

better fix maybe to create a single message like
dc sends karma to @user1 and @user2 if multiple users

auth required error

sending thanks to an unknown user gives this error

showInfo { error: 
   { name: 'Error',
     status: 401,
     message: 'Authorization Required',
     statusCode: 401,
     code: 'AUTHORIZATION_REQUIRED' } }

listen for FAQs and reply

[ Anyone know | can someone tell me how to | How do I ]
[ type code in the editor | .... ]

search for these FAQs and the bot can send a nice hint

maybe you're looking for this article? [how to enter code]

glossary feature

allows users to type in [keywords] like this to have an auto glossary come out
scan the user input for words surrounded by [ ]
lookup in the KBase a response
emit back just the first line of that entry
and use an indent > before the bot reply to make it indented

user:

You should read up on [undefined] some more.

bot:

>  **undefined** A primitive value automatically assigned to variables that have just been declared or to formal arguments for which there are no actual arguments.  [more info](https://github.com/freecodecamp/freecodecamp/wiki/undefined)

this will show up like

image

parse @mention thanks as well as thanks @mention

people often type like:

@terabyte thanks, will check out the readme

that should be picked up / filtered in the same way as normal thanks @xx
use a regex to match in the whole input.
we may have to add another part to the "parseInput" section to handle these

FCC Topic Specific Help chats

Topic Specific Help chats

  • sending data into the chatroom from FCC
  • button on FCC pages “chat about this topic”
  • loadup gitter
  • send to chat a relevant topic header
  • send to the chat: javascript? they’re currently editing (will require FCC integration)

test on API is timing out

any ideas why the call to the userinfo api would sometimes take > 2000ms? and sometimes not...

i have an Async test in there but i think the done() is in the right place.

"use strict";

var expect = require("chai").expect;

var HttpWrap = require("../lib/utils/HttpWrap.js"),
    Utils = require("../lib/utils/Utils"),
    TestHelper = require("./TestHelper");

function clog(msg, obj) {
    Utils.warn("HttpWrapSpec>", msg, obj);
}


// "no-unused-expressions": [0]

// var showInfo = function(input, bot, blob) {
//     clog("showInfo", blob);
//     expect(blob.about.username).to.equal("berkeleytrueX");
// };


describe("HttpWrap", function () {

    it("should load user info", function(done) {
        // var input = TestHelper.stubInput;
        // var bot = "dummyBot";
        var name = "berkeleytrue";
        var apiPath = '/api/users/about?username=' + name;
        HttpWrap.getApi(apiPath, function(apiResult) {
            console.log(apiResult);
            expect(apiResult.about.username).to.equal("berkeleytrue");
            expect(apiResult.about.github).to.equal("http://github.com/BerkeleyTrue");
            // expect(apiResult.about.bio).to.include("something");
            done();
        });

    });

});

helpbot

helpbot you can ask questions and it will answer on various topics, a little bit like unix man pages but for javascript

  • decide format for 'brain' files
  • repo for the “brain” (yaml format?)
  • simple query system with params

forking wiki

@QuincyLarson can you give me access to FCC main repo?
so i can read/write the wiki files from a local checkout.

it maybe best to setup the wiki content in a separate repo so we can allow edit/commit rights on that without changing permissions for main FCC repo, then you can allow other editors to check out the files locally and edit, not just via the browser UI.

there are other ways to fork wikis
https://gist.github.com/larrybotha/10650410

implement menu system

image

when a user gets a list of responses back, typing a single number eg 0 should be enough to select the next item to retrieve.

(nice tip we could also use 1️⃣ 2️⃣ ~ 9️⃣ emoji for menu items)

way to reset the send/receive log for testing

I confirmed you can't double send to the same user, but this makes it a bit hard to test as i can only use each user once.

would be great to have a way to reset the log so I can resend

or add a secret force:true option for testing, to ignore the log check

hello world response

very simple first feature to respond to hello world differently from just hello

api/users/about should have bio info

I don't see any bio info coming back from the API

request:

{ host: 'beta.freecodecamp.com',
  port: 80,
  path: '/api/users/about?username=quincylarson' }


response:
 { about: { username: 'quincylarson', github: '', browniePoints: 137 } }

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.