Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Allow Protocol Argument Passing #112

Merged

Conversation

toolateforteddy
Copy link
Contributor

@toolateforteddy toolateforteddy commented Jul 24, 2019

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
}

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
}
bot.go Outdated Show resolved Hide resolved
bot.go Show resolved Hide resolved
bot.go Outdated Show resolved Hide resolved
bot.go Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Jul 24, 2019

Coverage Status

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

@fabioxgn fabioxgn merged commit 4dad28f into go-chat-bot:master Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants