hipbot

package module
v0.0.0-...-8cdb171 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2014 License: Unlicense Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Very simple Hipchat bot library.

Docs: http://godoc.org/github.com/jonvaldes/hipbot

Example:

package main

import (
    "github.com/jonvaldes/hipbot"
)

func main() {

    bot, err := hipbot.NewBot("MYUSERID@chat.hipchat.com", "NICKNAME", "PASS")
    if err != nil {
        panic(err)
    }
    bot.JoinRoom("ROOMNAME@conf.hipchat.com")

    mux := hipbot.NewMux()

    mux.AddHandler(`^echo *`, func(b *hipbot.Bot, m hipbot.Msg) {
        b.Answer(m, "Echo "+m.Text)
    })

    bot.KeepAlive() // So Hipchat doesn't kick us out after 3 minutes

    if err := bot.Listen(mux); err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

Bot is the main object used to interact with Hipchat

func NewBot

func NewBot(userJabberID, nickname, password string) (*Bot, error)

NewBot creates a new Bot instance. Please note that Jabber ID and nickname must match the ones in the Hipchat acoount settings

func (*Bot) Answer

func (b *Bot) Answer(m Msg, text string)

Answer sends a message back to a room if the original message was a chatgroup, or directly to a user otherwise

func (*Bot) JoinRoom

func (b *Bot) JoinRoom(roomJabberID string)

JoinRoom tries to make the bot join a specific room. Room ID must match the one reported in the hipchat website

func (*Bot) KeepAlive

func (b *Bot) KeepAlive()

KeepAlive launches a goroutine that keeps the connection from closing

func (*Bot) Listen

func (b *Bot) Listen(l Listener) error

Listen waits forever for incoming messages and relays them to the passed-in listener

func (*Bot) SendDirect

func (b *Bot) SendDirect(userJabberID, message string)

SendDirect sends a message directly to one user

func (*Bot) SendRoom

func (b *Bot) SendRoom(roomJabberID, message string)

SendRoom sends a message to a room

type HandleFunc

type HandleFunc func(b *Bot, m Msg)

HandleFunc is the type of functions

type Listener

type Listener interface {
	HandleMsg(b *Bot, m Msg)
}

Listener is the interface used to handle incoming messages

type Msg

type Msg struct {
	Remote string
	Type   string
	Text   string
}

Msg represents a message send or received

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

Mux works pretty similarly to gorilla-mux and similar constructs. You can register pairs of regex-function, so each time an incoming message matches a regex, the relevant function will be called

func NewMux

func NewMux() *Mux

NewMux creates a new Mux instance

func (*Mux) AddHandler

func (m *Mux) AddHandler(regex string, f HandleFunc)

AddHandler registers a function to be called when an incoming message matches the regex

func (*Mux) HandleMsg

func (m *Mux) HandleMsg(c *Bot, msg Msg)

HandleMsg receives the incoming messages

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址