Code Monkey home page Code Monkey logo

go-slackbot's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar

go-slackbot's Issues

[Feature] Allow users to inject context

It would be nice if users of this package were allowed to inject context. I'm running into a issue where I'd like some of my context values in handlers.

Maybe we can add a context arg to New

slackbot.New(slackToken string, ctx context.Context)

Then in Run we check for a user provided context if not we create a fresh context.

DirectMentions are never detected

When using the starter-go-bot, it creates a subrouter with bot.Messages(slackbot.DirectMessage, slackbot.DirectMention).Subrouter(). Direct messages work fine, but direct mentions do not. At the point when Hear is called on this router, the botID of the bot is not set, and so neither is the botID of the route or the router. However, when the bot is run, the botID of the routers still never gets set. So when Utils.IsDirectMention is called, it's always checking for the regex ^<@>.*.

This can be fixed if you add the line b.SimpleRouter.SetBotID(ID) to Bot.setBotID, then when the bot is run and initialized, it sets the ID for all the existing routers and routes.

Obsolete wit.go API

I have an up to date fork https://github.com/christianrondeau/go-wit and I also have a working version of wit.go. I'm open to providing a PR if you'll consider it.

Right now, it's kind of working, but not so much :) I had some trouble running the samples. See wit-ai/wit#231

To be more precise, the MessageRequest function is deprecated, and the response format does not have Outcomes anymore.

Latest version of nlopse/slack breaks go-slackbot

Updated to the v 0.4.0 release of https://github.com/nlopes/slack and it breaks go-slackbot:

# gsg/loki/vendor/github.com/BeepBoopHQ/go-slackbot
src/gsg/loki/vendor/github.com/BeepBoopHQ/go-slackbot/bot.go:124:40: cannot use "" (type string) as type slack.MsgOption in argument to b.Client.PostMessage
src/gsg/loki/vendor/github.com/BeepBoopHQ/go-slackbot/bot.go:124:40: cannot use params (type slack.PostMessageParameters) as type slack.MsgOption in argument to b.Client.PostMessage

Use an interface on bot to allow mocking and unit testing

TL;DR: I'd like a BotInterface :)

I'm trying out go-slackbot, and as a TDD user, I want to test my handlers. Right now, I have two choices; either I wrap the https://github.com/BeepBoopHQ/go-slackbot/blob/master/bot.go type in my own, or I create a SomethingHandler than then calls a SomethingHandlerImpl, which abstracts away the slackbot.Bot type.

I think a simpler solution would be to reference to an interface instead of a concrete struct type, and add a New overload that receives the bot. Something like:

func New(slackToken string) *BotInterface {
	b := &Bot{Client: slack.New(slackToken)}
	return b
}

interface BotInterface interface {
    // This is what would be passed around
}

type Bot struct {
    // Nothing else changes...
}

I could just make the interface myself, but then I also need to mock MessageHandler (because

type MessageHandler func(ctx context.Context, bot *Bot, msg *slack.MessageEvent)
references directly the concrete type), so it becomes complicated :)

The code might not be perfect, but you get the idea. I can then do:

func TestHelloHandler(t *testing.T) {
    ctx := context.TODO()
    bot := MyBotMock{}
    evt := slack.MessageEvent{}

    HelloHandler(ctx, &bot, &evt)

    // Some assertion...
}

What do you think?

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.