Git Product home page Git Product logo

gobot's Introduction

gobot

gobot is a Simple chatbot written in golang

Initail work based on: https://github.com/mattn/go-xmpp/blob/master/example/example.go

gobot is under active development, the api may change w/out warning.

By itself, gobot just sits and listens for incoming messages. When a message is received, gobot passes the message on to any number of plugins. The plugins provide all the features of the chatbot.

Installing gobot

First, you'll need to have golang installed: http://golang.org/doc/install

Then, once that is working, all you need to do is:

$ go get github.com/gabeguz/gobot/cmd/gobot

Running a bot

gobot supports both slack and XMPP (jabber).

To connect to slack you'll need an API token, directions for getting one can be found at https://api.slack.com/bot-users aside from that, pick a name for your bot and enter the room you would like your bot to join.

$ gobot -protocol=slack -user=herman -pass=<slack api token> -room=bottest -name=herman

For xmpp you need a few extra bits of information. The hostname with port, the abber user, the users password, and the full address to the MUC you'd like the bot to join:

$ gobot -protocol=xmpp -host="jabber.my.domain:5222" -user="[email protected]" -pass="hunter2" -room="#[email protected]" -name="gobot"

Creating A Plugin

Creating a plugin is pretty easy, you just need to import the gobot library:

import (
	"github.com/gabeguz/gobot"
)

And then implement 2 exported methods so that you conform to the bot.Plugin interface:

type MyPlugin struct {}

func (p MyPlugin) Name() string {
	return "MyPlugin v1.0"
}

func (p MyPlugin) Execute(msg bot.Message, bot bot.Bot) error {
	if msg.From() != bot.FullName() {
		bot.Send("Why, hello!")
	}
	return nil
}

One last step, edit gobot/cmd/main.go and add a call to your new plugin to the []gb.Plugin slice:

plugins := []gb.Plugin{
	myplugin.MyPlugin{},
}

and import the code in the import statement at the top of the file.

Finally, reinstall gobot $ cd $GOPATH/src/github/gabeguz/gobot/cmd && go install ./...

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.