Skip to content

laouji/lungfish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lungfish

A simplistic event-based framework for creating slackbots in golang

DESCRIPTION

lungfish makes it easy to create a chatbot that can respond to mentions using user-defined callbacks.

See example/example.go for a working implementation of the bot

ESTABLISHING A CONNECTION

package main

import (
	"github.com/laouji/lungfish"
)

func main() {
	token := "<YOUR SLACK API TOKEN>"
	channel := "#channel-name"

	conn := lungfish.NewConnection(token)

    // register the channel you want your bot to join
	conn.RegisterChannel(channel)

    // bot logic goes here

	err := conn.Run()
  if err != nil {
    // handle connection error
  }
}

REACTIONS

A reaction is a keyword and callback function pair that lets you define the way your bot responds to commands.

conn.RegisterReaction("hello", func(e *lungfish.Event) {
    conn.PostMessage("o hai")
})

51e4de98

COMMANDS

Here are some built-in API calls that come in handy in callbacks:

func (conn *Connection) PostMessage(text string)

Post a message to the registered channel:

conn.PostMessage("hello world")

func (conn *Connection) GetUserInfo(userId string) UsersInfoResponseData

Get information about the user from a user ID via https://api.slack.com/methods/users.info

userInfo := conn.GetUserInfo(e.UserId)

if !userInfo.Ok {
    log.Println("error: " + userInfo.Error)
} else {
    log.Println("user name is " + userInfo.User.Name)
}

INSTALLATION

go get github.com/laouji/lungfish

About

lungfish is a slackbot framework (WIP)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages