go-chat-bot / bot

IRC, Slack, Telegram and RocketChat bot written in go
MIT License
824 stars 194 forks source link

Allow Protocol Argument Passing #112

Closed toolateforteddy closed 4 years ago

toolateforteddy commented 5 years ago

Due to the generic nature of this framework, platform specific behaviors are hard to take advantage of. With this PR, protocol plugins can offer additional information for message handlers to read, and accept additional information as well.

In particular, this change was tested to allow a Slack response to be made as a threaded reply, instead of only ever in the main channel.

EG:

func threadedEcho(cmd *bot.Cmd) (bot.CmdResult, error) {
    var params *slack.PostMessageParameters
    if ev, ok := cmd.MessageData.ProtoMsg.(*slack.MessageEvent); ok {
        params = &slack.PostMessageParameters{
            AsUser:          true,
            ThreadTimestamp: ev.Timestamp,
        }
    }
    return bot.CmdResult{
        Message:     fmt.Sprintf("%s: %s", cmd.User.Nick, cmd.Raw),
        Channel:     cmd.Channel,
        ProtoParams: params,
    }, nil
}
coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.2%) to 96.97% when pulling 9be1dd531c325d87d46f7fa8f3bab4c1794d9595 on toolateforteddy:allowProtocolArgumentPassing into 9b89c724b743da76eab1b98a2ff3f43f07bd6878 on go-chat-bot:master.