Documentation
¶
Index ¶
- Constants
- Variables
- type ApiRequest
- type ApiResponse
- type Attachment
- type AttachmentField
- type Bot
- type Brain
- type Broker
- func (b *Broker) DeRegisterCallback(callback interface{}) error
- func (b *Broker) DefaultChannel() string
- func (b *Broker) EventCallback(key string, val string) *EventCallback
- func (b *Broker) GetDM(ID string) string
- func (b *Broker) LinkCallback(p string, f ...func(http.ResponseWriter, *http.Request)) *LinkCallback
- func (b *Broker) MessageCallback(pattern string, respond bool, channel ...string) *MessageCallback
- func (b *Broker) NextMID() int32
- func (b *Broker) QuestionCallback(user string, prompt string) *QuestionCallback
- func (b *Broker) Register(things ...interface{})
- func (b *Broker) RegisterCallback(callback interface{}) error
- func (b *Broker) Respond(text string, thing *interface{}, isReply bool) chan map[string]interface{}
- func (b *Broker) Say(s string, channel ...string) chan map[string]interface{}
- func (b *Broker) Send(e *Event) chan map[string]interface{}
- func (broker *Broker) Start()
- func (b *Broker) StartHttp()
- func (b *Broker) StartModules()
- func (broker *Broker) Stop()
- func (b *Broker) This(thingy map[string]interface{})
- func (b *Broker) TimerCallback(schedule string) *TimerCallback
- type Channel
- type Config
- type Event
- type EventCallback
- type Group
- type IM
- type Icon
- type LinkCallback
- type MessageCallback
- type Module
- type PatternMatch
- type QuestionCallback
- type QuestionQueue
- type QuestionThread
- type ReadFilter
- type Self
- type Team
- type TimerCallback
- type Topic
- type User
- type WriteFilter
- type WriteThread
Constants ¶
const E = "events"
const L = "links"
const M = "messages"
These contstats define the four types of callbacks that lazlo can hand you
const Q = "questions"
const T = "timers"
Variables ¶
var Logger = newLogger()
Logger is a global reference to our logging object
Functions ¶
This section is empty.
Types ¶
type ApiRequest ¶
ApiRequest contains everything we need to make.. well an api request
type ApiResponse ¶
type ApiResponse struct {
Bots []Bot `json:"bots,omitempty"`
CacheVersion string `json:"cache_version,omitempty"`
Channels []Channel `json:"channels,omitempty"`
Channel Channel `json:"channel,omitempty"`
Groups []Group `json:"groups,omitempty"`
Group Group `json:"group,omitempty"`
IMs []IM `json:"ims,omitempty"`
LatestEventTs string `json:"latest_event_ts,omitempty"`
Latest string `json:"latest,omitempty"`
Ok bool `json:"ok,omitempty"`
ReplyTo int32 `json:"reply_to,omitempty"`
Error string `json:"error,omitempty"`
HasMore bool `json:"has_more,omitempty"`
Self Self `json:"self,omitempty"`
Team Team `json:"team,omitempty"`
URL string `json:"url,omitempty"`
Users []User `json:"users,omitempty"`
User User `json:"user,omitempty"`
Messages []Event `json:"messages,omitempty"`
}
func MakeAPIReq ¶
func MakeAPIReq(req ApiRequest) (*ApiResponse, error)
MakeAPIReq takes an ApiRequest, adds auth if necessary and POSTs it to the slack web-api.
func (*ApiResponse) GetChannel ¶
func (meta *ApiResponse) GetChannel(id string) *Channel
GetChannel is a convienence function to fetch a pointer to a channel object given its ID
func (*ApiResponse) GetChannelByName ¶
func (meta *ApiResponse) GetChannelByName(name string) *Channel
GetChannel is a convienence function to fetch a pointer to a channel object given its Name
func (*ApiResponse) GetUser ¶
func (meta *ApiResponse) GetUser(id string) *User
GetUser is a convienence function to return a pointer to a user object given its ID.
func (*ApiResponse) GetUserByName ¶
func (meta *ApiResponse) GetUserByName(name string) *User
GetUserByName is a convience function to return a pointer to a user object given its Name
func (*ApiResponse) GetUserName ¶
func (meta *ApiResponse) GetUserName(id string) string
GetUserName is a convience function to return a user's Name field given its ID.
type Attachment ¶
type Attachment struct {
Fallback string `json:"fallback"`
Color string `json:"color,omitempty"`
Pretext string `json:"pretext,omitempty"`
AuthorName string `json:"author_name,omitempty"`
AuthorLink string `json:"author_link,omitempty"`
AuthorIcon string `json:"author_icon,omitempty"`
Title string `json:"title,omitempty"`
TitleLink string `json:"title_link,omitempty"`
Text string `json:"text,omitempty"`
Fields []AttachmentField `json:"fields,omitempty"`
ImageUrl string `json:"image_url,omitempty"`
ThumbUrl string `json:"thumb_url,omitempty"`
MarkdownIn []string `json:"mrkdwn_in,omitempty"`
}
type AttachmentField ¶
type Bot ¶
type Bot struct {
Created float64 `json:"created,omitempty"`
Deleted bool `json:"deleted,omitempty"`
Icons Icon `json:"icons,omitempty"`
ID string `json:"id,omitempty"`
IsIm bool `json:"is_im,omitempty"`
IsUserDeleted bool `json:"is_user_deleted,omitempty"`
User string `json:"user,omitempty"`
Name string `json:"name,omitempty"`
Extra map[string]interface{}
}
type Brain ¶
type Brain interface {
Open() error
Close() error
Get(string) ([]byte, error)
Set(key string, data []byte) error
Delete(string) error
}
Top-level exported Store interface for storage backends to implement
type Broker ¶
type Broker struct {
SlackMeta *ApiResponse
Config *Config
Socket *websocket.Conn
Modules map[string]*Module
Brain Brain
ApiResponses map[int32]chan map[string]interface{}
ReadFilters []*ReadFilter
WriteFilters []*WriteFilter
MID int32
WriteThread *WriteThread
QuestionThread *QuestionThread
SigChan chan os.Signal
SyncChan chan bool
ThreadCount int32
// contains filtered or unexported fields
}
Broker is the all-knowing repository of references
func (*Broker) DeRegisterCallback ¶
func (*Broker) DefaultChannel ¶
returns the Team's default channel
func (*Broker) EventCallback ¶
func (b *Broker) EventCallback(key string, val string) *EventCallback
func (*Broker) LinkCallback ¶
func (b *Broker) LinkCallback(p string, f ...func(http.ResponseWriter, *http.Request)) *LinkCallback
func (*Broker) MessageCallback ¶
func (b *Broker) MessageCallback(pattern string, respond bool, channel ...string) *MessageCallback
func (*Broker) NextMID ¶
NextMID() ensures our outbound messages have a unique ID number (a requirement of the slack rtm api)
func (*Broker) QuestionCallback ¶
func (b *Broker) QuestionCallback(user string, prompt string) *QuestionCallback
func (*Broker) Register ¶
func (b *Broker) Register(things ...interface{})
broker.Register() registers user-provided plug-ins
func (*Broker) RegisterCallback ¶
func (*Broker) Respond ¶
send a reply to any sort of thingy that contains an ID and Channel attribute
func (*Broker) Send ¶
this is the primary interface to Slack's write socket. Use this to send events.
func (*Broker) StartModules ¶
func (b *Broker) StartModules()
StartModules launches each user-provided plugin registered in loadMOdules.go
func (*Broker) This ¶
broker.This() takes an inbound thingy of unknown type and brokers it to wherever it needs to go
func (*Broker) TimerCallback ¶
func (b *Broker) TimerCallback(schedule string) *TimerCallback
type Channel ¶
type Channel struct {
Created float64 `json:"created,omitempty"`
Creator string `json:"creator,omitempty"`
ID string `json:"id,omitempty"`
IsArchived bool `json:"is_archived,omitempty"`
IsChannel bool `json:"is_channel,omitempty"`
IsGeneral bool `json:"is_general,omitempty"`
IsMember bool `json:"is_member,omitempty"`
LastRead string `json:"last_read,omitempty"`
Latest Event `json:"latest,omitempty"`
Members []string `json:"members,omitempty"`
Name string `json:"name,omitempty"`
Purpose Topic `json:"purpose,omitempty"`
Topic Topic `json:"topic,omitempty"`
UnreadCount float64 `json:"unread_count,omitempty"`
Extra map[string]interface{}
}
type Config ¶
type Config struct {
Name string `env:"key=LAZLO_NAME default=lazlo"`
Token string `env:"key=LAZLO_TOKEN"`
URL string `env:"key=LAZLO_URL default=http://localhost"`
LogLevel string `env:"key=LAZLO_LOG_LEVEL default=info"`
RedisURL string `env:"key=LAZLO_REDIS_URL"`
RedisPW string `env:"key=LAZLO_REDIS_PW"`
Port string `env:"key=PORT"`
}
Config struct
type Event ¶
type Event struct {
ID int32 `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Channel string `json:"channel,omitempty"`
Text string `json:"text,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
User string `json:"user,omitempty"`
UserName string `json:"username,omitempty"`
BotID string `json:"bot_id,omitempty"`
Subtype string `json:"subtype,omitempty"`
Ts string `json:"ts,omitempty"`
Broker *Broker
CallBackCode string `json:"callbackcode,omitempty"`
Extra map[string]interface{}
}
func (*Event) RespondAttachments ¶
func (event *Event) RespondAttachments(a []Attachment) chan map[string]interface{}
RespondAttachments is a function to RESPOND WITH ATTACHMENTS to a given event object
type EventCallback ¶
type Group ¶
type Group struct {
Created int64 `json:"created,omitempty"`
Creator string `json:"creator,omitempty"`
ID string `json:"id,omitempty"`
IsArchived bool `json:"is_archived,omitempty"`
IsGroup bool `json:"is_group,omitempty"`
Members []string `json:"members,omitempty"`
Name string `json:"name,omitempty"`
Purpose Topic `json:"purpose,omitempty"`
Topic Topic `json:"topic,omitempty"`
Extra map[string]interface{}
}
type Icon ¶
type Icon struct {
Image192 string `json:"image_132,omitempty"`
Image132 string `json:"image_132,omitempty"`
Image102 string `json:"image_102,omitempty"`
Image88 string `json:"image_88,omitempty"`
Image68 string `json:"image_68,omitempty"`
Image48 string `json:"image_48,omitempty"`
Image44 string `json:"image_44,omitempty"`
Image34 string `json:"image_34,omitempty"`
ImageDefault bool `json:"image_default,omitempty"`
}
type LinkCallback ¶
type LinkCallback struct {
ID string
Path string // the computed URL
URL string
Handler func(res http.ResponseWriter, req *http.Request)
Chan chan *http.Request
// contains filtered or unexported fields
}
func (*LinkCallback) Delete ¶
func (l *LinkCallback) Delete()
type MessageCallback ¶
type MessageCallback struct {
ID string
Pattern string
Respond bool // if true, only respond if the bot is mentioned by name
Chan chan PatternMatch
SlackChan string // if set filter message callbacks to this Slack channel
}
type Module ¶
The Module type represents a user-defined plug-in. Build one of these and add it to loadModules.go for Lazlo to run your thingy on startup
type PatternMatch ¶
type QuestionCallback ¶
type QuestionQueue ¶
type QuestionQueue struct {
// contains filtered or unexported fields
}
func (*QuestionQueue) Launch ¶
func (qq *QuestionQueue) Launch(b *Broker)
QuestionQueue.Launch is a worker that serializes questions to one person
type QuestionThread ¶
type QuestionThread struct {
// contains filtered or unexported fields
}
The QuestionThread serializes questions and sends questions to users
func (*QuestionThread) Start ¶
func (qt *QuestionThread) Start()
QuestionThread.Start() starts the question-serializer service
type ReadFilter ¶
type ReadFilter struct {
Name string
Usage string
Run func(thingy map[string]interface{}) map[string]interface{}
}
ReadFilter is a yet-to-be-implemented hook run on all inbound events from slack before the broker gets a hold of them
type Self ¶
type Self struct {
Created float64 `json:"created,omitempty"`
ID string `json:"id,omitempty"`
ManualPresence string `json:"manual_presence,omitempty"`
Name string `json:"name,omitempty"`
Prefs struct {
AllChannelsLoud bool `json:"all_channels_loud,omitempty"`
ArrowHistory bool `json:"arrow_history,omitempty"`
AtChannelSuppressedChannels string `json:"at_channel_suppressed_channels,omitempty"`
AutoplayChatSounds bool `json:"autoplay_chat_sounds,omitempty"`
Collapsible bool `json:"collapsible,omitempty"`
CollapsibleByClick bool `json:"collapsible_by_click,omitempty"`
ColorNamesInList bool `json:"color_names_in_list,omitempty"`
CommaKeyPrefs bool `json:"comma_key_prefs,omitempty"`
ConvertEmoticons bool `json:"convert_emoticons,omitempty"`
DisplayRealNamesOverride float64 `json:"display_real_names_override,omitempty"`
DropboxEnabled bool `json:"dropbox_enabled,omitempty"`
EmailAlerts string `json:"email_alerts,omitempty"`
EmailAlertsSleepUntil float64 `json:"email_alerts_sleep_until,omitempty"`
EmailMisc bool `json:"email_misc,omitempty"`
EmailWeekly bool `json:"email_weekly,omitempty"`
EmojiMode string `json:"emoji_mode,omitempty"`
EnterIsSpecialInTbt bool `json:"enter_is_special_in_tbt,omitempty"`
ExpandInlineImgs bool `json:"expand_inline_imgs,omitempty"`
ExpandInternalInlineImgs bool `json:"expand_internal_inline_imgs,omitempty"`
ExpandNonMediaAttachments bool `json:"expand_non_media_attachments,omitempty"`
ExpandSnippets bool `json:"expand_snippets,omitempty"`
FKeySearch bool `json:"f_key_search,omitempty"`
FullTextExtracts bool `json:"full_text_extracts,omitempty"`
FuzzyMatching bool `json:"fuzzy_matching,omitempty"`
GraphicEmoticons bool `json:"graphic_emoticons,omitempty"`
GrowlsEnabled bool `json:"growls_enabled,omitempty"`
HasCreatedChannel bool `json:"has_created_channel,omitempty"`
HasInvited bool `json:"has_invited,omitempty"`
HasUploaded bool `json:"has_uploaded,omitempty"`
HighlightWords string `json:"highlight_words,omitempty"`
KKeyOmnibox bool `json:"k_key_omnibox,omitempty"`
LastSnippetType string `json:"last_snippet_type,omitempty"`
LoudChannels string `json:"loud_channels,omitempty"`
LoudChannelsSet string `json:"loud_channels_set,omitempty"`
LsDisabled bool `json:"ls_disabled,omitempty"`
MacSpeakSpeed float64 `json:"mac_speak_speed,omitempty"`
MacSpeakVoice string `json:"mac_speak_voice,omitempty"`
MacSsbBounce string `json:"mac_ssb_bounce,omitempty"`
MacSsbBullet bool `json:"mac_ssb_bullet,omitempty"`
MarkMsgsReadImmediately bool `json:"mark_msgs_read_immediately,omitempty"`
MessagesTheme string `json:"messages_theme,omitempty"`
MuteSounds bool `json:"mute_sounds,omitempty"`
MutedChannels string `json:"muted_channels,omitempty"`
NeverChannels string `json:"never_channels,omitempty"`
NewMsgSnd string `json:"new_msg_snd,omitempty"`
NoCreatedOverlays bool `json:"no_created_overlays,omitempty"`
NoJoinedOverlays bool `json:"no_joined_overlays,omitempty"`
NoMacssb1Banner bool `json:"no_macssb1_banner,omitempty"`
NoTextInNotifications bool `json:"no_text_in_notifications,omitempty"`
ObeyInlineImgLimit bool `json:"obey_inline_img_limit,omitempty"`
PagekeysHandled bool `json:"pagekeys_handled,omitempty"`
PostsFormattingGuide bool `json:"posts_formatting_guide,omitempty"`
PrivacyPolicySeen bool `json:"privacy_policy_seen,omitempty"`
PromptedForEmailDisabling bool `json:"prompted_for_email_disabling,omitempty"`
PushAtChannelSuppressedChannels string `json:"push_at_channel_suppressed_channels,omitempty"`
PushDmAlert bool `json:"push_dm_alert,omitempty"`
PushEverything bool `json:"push_everything,omitempty"`
PushIdleWait float64 `json:"push_idle_wait,omitempty"`
PushLoudChannels string `json:"push_loud_channels,omitempty"`
PushLoudChannelsSet string `json:"push_loud_channels_set,omitempty"`
PushMentionAlert bool `json:"push_mention_alert,omitempty"`
PushMentionChannels string `json:"push_mention_channels,omitempty"`
PushSound string `json:"push_sound,omitempty"`
RequireAt bool `json:"require_at,omitempty"`
SearchExcludeBots bool `json:"search_exclude_bots,omitempty"`
SearchExcludeChannels string `json:"search_exclude_channels,omitempty"`
SearchOnlyMyChannels bool `json:"search_only_my_channels,omitempty"`
SearchSort string `json:"search_sort,omitempty"`
SeenChannelMenuTipCard bool `json:"seen_channel_menu_tip_card,omitempty"`
SeenChannelsTipCard bool `json:"seen_channels_tip_card,omitempty"`
SeenDomainInviteReminder bool `json:"seen_domain_invite_reminder,omitempty"`
SeenFlexpaneTipCard bool `json:"seen_flexpane_tip_card,omitempty"`
SeenMemberInviteReminder bool `json:"seen_member_invite_reminder,omitempty"`
SeenMessageInputTipCard bool `json:"seen_message_input_tip_card,omitempty"`
SeenSearchInputTipCard bool `json:"seen_search_input_tip_card,omitempty"`
SeenSsbPrompt bool `json:"seen_ssb_prompt,omitempty"`
SeenTeamMenuTipCard bool `json:"seen_team_menu_tip_card,omitempty"`
SeenUserMenuTipCard bool `json:"seen_user_menu_tip_card,omitempty"`
SeenWelcome2 bool `json:"seen_welcome_2,omitempty"`
ShowMemberPresence bool `json:"show_member_presence,omitempty"`
ShowTyping bool `json:"show_typing,omitempty"`
SidebarBehavior string `json:"sidebar_behavior,omitempty"`
SidebarTheme string `json:"sidebar_theme,omitempty"`
SidebarThemeCustomValues string `json:"sidebar_theme_custom_values,omitempty"`
SnippetEditorWrapLongLines bool `json:"snippet_editor_wrap_long_lines,omitempty"`
SpeakGrowls bool `json:"speak_growls,omitempty"`
SsEmojis bool `json:"ss_emojis,omitempty"`
StartScrollAtOldest bool `json:"start_scroll_at_oldest,omitempty"`
TabUiReturnSelects bool `json:"tab_ui_return_selects,omitempty"`
Time24 bool `json:"time24,omitempty"`
Tz string `json:"tz,omitempty"`
UserColors string `json:"user_colors,omitempty"`
WebappSpellcheck bool `json:"webapp_spellcheck,omitempty"`
WelcomeMessageHidden bool `json:"welcome_message_hidden,omitempty"`
WinSsbBullet bool `json:"win_ssb_bullet,omitempty"`
} `json:"prefs,omitempty"`
}
type Team ¶
type Team struct {
Domain string `json:"domain,omitempty"`
EmailDomain string `json:"email_domain,omitempty"`
Icon Icon `json:"icon,omitempty"`
ID string `json:"id,omitempty"`
MsgEditWindowMins float64 `json:"msg_edit_window_mins,omitempty"`
Name string `json:"name,omitempty"`
OverStorageLimit bool `json:"over_storage_limit,omitempty"`
Prefs struct {
AllowMessageDeletion bool `json:"allow_message_deletion,omitempty"`
DefaultChannels []string `json:"default_channels,omitempty"`
DisplayRealNames bool `json:"display_real_names,omitempty"`
DmRetentionDuration float64 `json:"dm_retention_duration,omitempty"`
DmRetentionType float64 `json:"dm_retention_type,omitempty"`
GatewayAllowIrcPlain float64 `json:"gateway_allow_irc_plain,omitempty"`
GatewayAllowIrcSsl float64 `json:"gateway_allow_irc_ssl,omitempty"`
GatewayAllowXmppSsl float64 `json:"gateway_allow_xmpp_ssl,omitempty"`
GroupRetentionDuration float64 `json:"group_retention_duration,omitempty"`
GroupRetentionType float64 `json:"group_retention_type,omitempty"`
HideReferers bool `json:"hide_referers,omitempty"`
MsgEditWindowMins float64 `json:"msg_edit_window_mins,omitempty"`
RequireAtForMention bool `json:"require_at_for_mention,omitempty"`
RetentionDuration float64 `json:"retention_duration,omitempty"`
RetentionType float64 `json:"retention_type,omitempty"`
WhoCanArchiveChannels string `json:"who_can_archive_channels,omitempty"`
WhoCanAtChannel string `json:"who_can_at_channel,omitempty"`
WhoCanAtEveryone string `json:"who_can_at_everyone,omitempty"`
WhoCanCreateChannels string `json:"who_can_create_channels,omitempty"`
WhoCanCreateGroups string `json:"who_can_create_groups,omitempty"`
WhoCanKickChannels string `json:"who_can_kick_channels,omitempty"`
WhoCanKickGroups string `json:"who_can_kick_groups,omitempty"`
WhoCanPostGeneral string `json:"who_can_post_general,omitempty"`
} `json:"prefs,omitempty"`
Extra map[string]interface{}
}
type TimerCallback ¶
type TimerCallback struct {
ID string
Schedule string
State string
Next time.Time
Chan chan time.Time
// contains filtered or unexported fields
}
func (*TimerCallback) Run ¶
func (t *TimerCallback) Run(dur time.Duration)
wait for the timer to expire, callback to the module, and reschedule
func (*TimerCallback) Start ¶
func (t *TimerCallback) Start() error
verify the schedule and start the timer
func (*TimerCallback) Stop ¶
func (t *TimerCallback) Stop()
type User ¶
type User struct {
Color string `json:"color,omitempty"`
Deleted bool `json:"deleted,omitempty"`
HasFiles bool `json:"has_files,omitempty"`
ID string `json:"id,omitempty"`
IsAdmin bool `json:"is_admin,omitempty"`
IsBot bool `json:"is_bot,omitempty"`
IsOwner bool `json:"is_owner,omitempty"`
IsPrimaryOwner bool `json:"is_primary_owner,omitempty"`
IsRestricted bool `json:"is_restricted,omitempty"`
IsUltraRestricted bool `json:"is_ultra_restricted,omitempty"`
Name string `json:"name,omitempty"`
Phone interface{} `json:"phone,omitempty"`
Presence string `json:"presence,omitempty"`
Profile struct {
Email string `json:"email,omitempty"`
FirstName string `json:"first_name,omitempty"`
Image192 string `json:"image_192,omitempty"`
Image24 string `json:"image_24,omitempty"`
Image32 string `json:"image_32,omitempty"`
Image48 string `json:"image_48,omitempty"`
Image72 string `json:"image_72,omitempty"`
LastName string `json:"last_name,omitempty"`
Phone string `json:"phone,omitempty"`
RealName string `json:"real_name,omitempty"`
RealNameNormalized string `json:"real_name_normalized,omitempty"`
} `json:"profile,omitempty"`
RealName string `json:"real_name,omitempty"`
Skype string `json:"skype,omitempty"`
Status interface{} `json:"status,omitempty"`
Tz string `json:"tz,omitempty"`
TzLabel string `json:"tz_label,omitempty"`
TzOffset float64 `json:"tz_offset,omitempty"`
Extra map[string]interface{}
}
type WriteFilter ¶
WriteFilter is a yet-to-be-implemented hook run on all outbound events from slack before the broker gets a hold of them
type WriteThread ¶
type WriteThread struct {
Chan chan Event
SyncChan chan bool
// contains filtered or unexported fields
}
The WriteThread serielizes and sends messages to the slack RTM interface