beepboophq / go-slackbot Goto Github PK
View Code? Open in Web Editor NEWGo module for building slackbot
License: MIT License
Go module for building slackbot
License: MIT License
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
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.
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
Line 19 in 58027c0
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?
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.