Event Examples

Customize your app's behavior in response to activities in Slack. Here are a few event handling examples to help you get started.

Before you can handle an event, subscribe to the event in your app manifest and register the event handler.

Most of these examples are available in the sample Apex SDK for Slack app.

This example displays a message in the App Home.

The app_home view is published using Slack.ViewsPublishRequest and Slack.ViewsPublishResponse.

Set the expression values in the event handler using the Slack.ViewReference class.

This example responds to a channel (public or private) rename by posting a message.

Get the event parameters using the Slack.Event class and check if the event is an instance of the Slack.ChannelRenameEvent or Slack.GroupRenameEvent class.

This example responds to a user adding and removing an emoji on an item.

Get the event parameters using the Slack.Event class and check if the event is an instance of the Slack.ReactionAddedEvent or Slack.ReactionRemovedEvent class.

This example creates a channel based on a user's message post containing the string "create channel [channel name]" where [channel name] is the name of the channel that will be joined by dashes. For example, "create channel demo channel" creates a channel called #demo-channel. You can also automatically add the user who issued the message to the new channel.

Create the specified channel using the Slack.ConversationsCreateResponse and Slack.ConversationsCreateRequest.

Next, invite the user who issued the command to the new channel using Slack.ConversationsInviteResponse and Slack.ConversationsInviteRequest.