Skip to content

Migrating from v2.x to v3.x

Go Hagiwara edited this page Aug 15, 2020 · 2 revisions

The third major version of go-sarah introduces better Slack support.

From 2019 to 2020, Slack is going through big changes, and those include migration from RTM API to Events API. While new Slack apps are strongly recommended to use Events API for better functionality, RTM API is still supported to work with apps behind firewalls. With go-sarah v3.0.0, developers can select which API to use.

Updates in v3

Adapter option

To provide the choice of API, an AdapterOption derived from the call to WithEventsPayloadHandler or WithRTMPayloadHandler is required.

RTM API

Below illustrates how to enable RTM API. By replacing slack.DefaultRTMPayloadHandler with a customized handler, one can change the behavior on how to receive the incoming events.

	// Setup slack adapter.
	slackConfig := slack.NewConfig()
	slackConfig.Token = "REPLACE THIS"
	adapter, err := slack.NewAdapter(slackConfig, slack.WithRTMPayloadHandler(slack.DefaultRTMPayloadHandler))

Events API

Below illustrates how to enable Events API. By replacing slack.DefaultEventsPayloadHandler with a customized handler, one can change the behavior on how to receive the incoming events.

	// Setup slack adapter.
	slackConfig := slack.NewConfig()
	slackConfig.Token = "REPLACE THIS"
	adapter, err := slack.NewAdapter(slackConfig, slack.WithRTMPayloadHandler(slack.DefaultEventsPayloadHandler))

sarah.Input implementation

Now the old slack.MessageInput is replaced with slack.Input that wraps the incoming event.

Clone this wiki locally