Documentation ¶
Index ¶
- Constants
- type ChannelCreated
- type ChannelCreatedEvent
- type ChannelJoinedEvent
- type Client
- type DesktopNotificationEvent
- type ErrorEvent
- type Event
- type EventType
- type HelloEvent
- type ImCreatedEvent
- type MemberJoinedchannel
- type MessageEvent
- type Option
- type PongEvent
- type PresenceChangeEvent
- type ReconnectURLEvent
- type UserTypingEvent
Examples ¶
Constants ¶
View Source
const ( AccountsChangedTypeKey = "accounts_changed" BotAddedTypeKey = "bot_added" BotChangedTypeKey = "bot_changed" ChannelArchiveTypeKey = "channel_archive" ChannelCreatedTypeKey = "channel_created" ChannelDeletedTypeKey = "channel_deleted" ChannelHistoryChangedTypeKey = "channel_history_changed" ChannelJoinedTypeKey = "channel_joined" ChannelLeftTypeKey = "channel_left" ChannelMarkedTypeKey = "channel_marked" ChannelRenameTypeKey = "channel_rename" ChannelUnarchiveTypeKey = "channel_unarchive" CommandsChangedTypeKey = "commands_changed" DndUpdatedTypeKey = "dnd_updated" DndUpdatedUserTypeKey = "dnd_updated_user" EmailDomainChangedTypeKey = "email_domain_changed" EmojiChangedTypeKey = "emoji_changed" ErrorTypeKey = "error" FileChangeTypeKey = "file_change" FileCommentAddedTypeKey = "file_comment_added" FileCommentDeletedTypeKey = "file_comment_deleted" FileCommentEditedTypeKey = "file_comment_edited" FileCreatedTypeKey = "file_created" FileDeletedTypeKey = "file_deleted" FilePublicTypeKey = "file_public" GoodbyeTypeKey = "goodbye" GroupArchiveTypeKey = "group_archive" GroupCloseTypeKey = "group_close" GroupHistoryChangedTypeKey = "group_history_changed" GroupJoinedTypeKey = "group_joined" GroupLeftTypeKey = "group_left" GroupMarkedTypeKey = "group_marked" GroupOpenTypeKey = "group_open" GroupRenameTypeKey = "group_rename" GroupUnarchiveTypeKey = "group_unarchive" HelloTypeKey = "hello" ImCloseTypeKey = "im_close" ImCreatedTypeKey = "im_created" ImHistoryChangedTypeKey = "im_history_changed" ImMarkedTypeKey = "im_marked" ImOpenTypeKey = "im_open" ManualPresenceChangeTypeKey = "manual_presence_change" MessageTypeKey = "message" PinAddedTypeKey = "pin_added" PinRemovedTypeKey = "pin_removed" PrefChangeTypeKey = "pref_change" PresenceChangeTypeKey = "presence_change" PongTypeKey = "pong" ReactionAddedTypeKey = "reaction_added" ReactionRemovedTypeKey = "reaction_removed" ReconnectURLTypeKey = "reconnect_url" StarAddedTypeKey = "star_added" StarRemovedTypeKey = "star_removed" SubteamCreatedTypeKey = "subteam_created" SubteamSelfAddedTypeKey = "subteam_self_added" SubteamSelfRemovedTypeKey = "subteam_self_removed" SubteamUpdatedTypeKey = "subteam_updated" TeamDomainChangeTypeKey = "team_domain_change" TeamJoinTypeKey = "team_join" TeamMigrationStartedTypeKey = "team_migration_started" TeamPlanChangeTypeKey = "team_plan_change" TeamPrefChangeTypeKey = "team_pref_change" TeamProfileChangeTypeKey = "team_profile_change" TeamProfileDeleteTypeKey = "team_profile_delete" TeamProfileReorderTypeKey = "team_profile_reorder" TeamRenameTypeKey = "team_rename" UserChangeTypeKey = "user_change" UserTypingTypeKey = "user_typing" )
These constants match the event types generated by Slack
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelCreated ¶
type ChannelCreated struct { Created objects.EpochTime `json:"created"` ID string `json:"id"` IsIM bool `json:"is_im"` IsOpen bool `json:"is_open"` LastRead string `json:"last_read"` Latest *objects.Message `json:"latest"` UnreadCount int `json:"unread_count"` UnreadCountDisplay int `json:"unread_count_display"` User string `json:"user"` }
type ChannelCreatedEvent ¶
type ChannelCreatedEvent struct { Channel ChannelCreated `json:"channel"` EventTimestamp string `json:"event_ts"` }
type ChannelJoinedEvent ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "context" "fmt" "github.com/lestrrat-go/slack" "github.com/lestrrat-go/slack/rtm" ) func processMessageEvent(e *rtm.MessageEvent) { // Dummy } func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() // Create a new Slack REST client. This is required, // as the RTM client needs to hit the rtm.start API // endpoint in order to initiate a websocket session restcl := slack.New(slackToken) // Create a new Slack RTM client. Use `Run()` to start // listening to incoming events. If you need to stop the // RTM client, use the cancel function for the context.Context // object that you passed rtmcl := rtm.New(restcl) go rtmcl.Run(ctx) // Now, consume your events. They come from a channel. // If you care about properly bailing out of a processing // loop like below, you should be using select {} on the // channel returned by `rtmcl.Events()` for e := range rtmcl.Events() { // Event types are listed in event_types.go file, which // is auto-generated from Slack's web page describing // the events. switch typ := e.Type(); typ { case rtm.MessageType: // It's a message. Event objects carry a unique payload // depending on the event type, so you will have to do // a type assertion. // TODO: come up with a mapping of Type -> Data's underlying // type, so it's easier for the users to see processMessageEvent(e.Data().(*rtm.MessageEvent)) default: fmt.Printf("Unhandled event: %s", typ) } } }
Output:
type DesktopNotificationEvent ¶
type DesktopNotificationEvent struct { AvatarImage string `json:"avatar_image"` Channel string `json:"channel"` Content string `json:"content"` EventTimestamp string `json:"event_ts"` ImageURI string `json:"image_uri"` LaunchURI string `json:"launch_uri"` Msg string `json:"msg"` Title string `json:"title"` SsbFilename string `json:"ssb_filename"` Subtitle string `json:"subtitle"` }
This event is... not in the events list... (as of Apr 3, 2017) https://api.slack.com/events
type ErrorEvent ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
func (*Event) UnmarshalJSON ¶
type EventType ¶
type EventType int
const ( InvalidEventType EventType = iota ClientConnectingEventType // internal ClientDisconnectedEventType // internal AccountsChangedType BotAddedType BotChangedType ChannelArchiveType ChannelCreatedType ChannelDeletedType ChannelHistoryChangedType ChannelJoinedType ChannelLeftType ChannelMarkedType ChannelRenameType ChannelUnarchiveType CommandsChangedType DndUpdatedType DndUpdatedUserType EmailDomainChangedType EmojiChangedType ErrorType FileChangeType FileCommentAddedType FileCommentDeletedType FileCommentEditedType FileCreatedType FileDeletedType FilePublicType GoodbyeType GroupArchiveType GroupCloseType GroupHistoryChangedType GroupJoinedType GroupLeftType GroupMarkedType GroupOpenType GroupRenameType GroupUnarchiveType HelloType ImCloseType ImCreatedType ImHistoryChangedType ImMarkedType ImOpenType ManualPresenceChangeType MessageType PinAddedType PinRemovedType PrefChangeType PresenceChangeType PongType ReactionAddedType ReactionRemovedType ReconnectURLType StarAddedType StarRemovedType SubteamCreatedType SubteamSelfAddedType SubteamSelfRemovedType SubteamUpdatedType TeamDomainChangeType TeamJoinType TeamMigrationStartedType TeamPlanChangeType TeamPrefChangeType TeamProfileChangeType TeamProfileDeleteType TeamProfileReorderType TeamRenameType UserChangeType UserTypingType )
type HelloEvent ¶
type HelloEvent struct{}
type ImCreatedEvent ¶
type ImCreatedEvent struct { User string `json:"user"` Channel ChannelCreated `json:"channel"` }
type MemberJoinedchannel ¶
type MemberJoinedchannel struct { EventTimestamp string `json:"event_ts"` Channel string `json:"channel"` ChannelType string `json:"channel_type"` User string `json:"user"` }
This event is... not in the events list... (as of Apr 3, 2017) https://api.slack.com/events
type MessageEvent ¶
type Option ¶
type Option interface { Name() string Value() interface{} }
Option defines an interface of optional parameters to the `rtm.New` constructor.
func WithBackOffStrategy ¶
WithBackOffStrategy creates a new option that defines the backoff strategy to be used when connections to the slack RTM server fails.
func WithPingInterval ¶
WithPingInterval creates a new option that defines the length of intervals between each successive pings.
type PresenceChangeEvent ¶
type ReconnectURLEvent ¶
type ReconnectURLEvent struct {
URL string `json:"url"`
}
type UserTypingEvent ¶
Click to show internal directories.
Click to hide internal directories.