diff options
author | Patrick Connolly <patrick.c.connolly@gmail.com> | 2018-11-09 03:45:40 +0800 |
---|---|---|
committer | Wim <wim@42.be> | 2018-11-08 20:45:40 +0100 |
commit | 3d281b3316a68a265efb0f024755e8d1c3863bd5 (patch) | |
tree | 55c6f428b23a3857a7f45263769a84acf633c130 /bridge | |
parent | ea86849a5855e58fd4633117416a21fde753751f (diff) | |
download | matterbridge-msglm-3d281b3316a68a265efb0f024755e8d1c3863bd5.tar.gz matterbridge-msglm-3d281b3316a68a265efb0f024755e8d1c3863bd5.tar.bz2 matterbridge-msglm-3d281b3316a68a265efb0f024755e8d1c3863bd5.zip |
Add ability to show when user is typing across Slack bridges (#559)
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/config/config.go | 2 | ||||
-rw-r--r-- | bridge/slack/handlers.go | 30 | ||||
-rw-r--r-- | bridge/slack/slack.go | 11 |
3 files changed, 41 insertions, 2 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go index bdf77f88..9d335cac 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -23,6 +23,7 @@ const ( EVENT_USER_ACTION = "user_action" EVENT_MSG_DELETE = "msg_delete" EVENT_API_CONNECTED = "api_connected" + EVENT_USER_TYPING = "user_typing" ) type Message struct { @@ -110,6 +111,7 @@ type Protocol struct { Server string // IRC,mattermost,XMPP,discord ShowJoinPart bool // all protocols ShowTopicChange bool // slack + ShowUserTyping bool // slack ShowEmbeds bool // discord SkipTLSVerify bool // IRC, mattermost StripNick bool // all protocols diff --git a/bridge/slack/handlers.go b/bridge/slack/handlers.go index 4307e7b9..0f5e1402 100644 --- a/bridge/slack/handlers.go +++ b/bridge/slack/handlers.go @@ -23,7 +23,9 @@ func (b *Bslack) handleSlack() { time.Sleep(time.Second) b.Log.Debug("Start listening for Slack messages") for message := range messages { - b.Log.Debugf("<= Sending message from %s on %s to gateway", message.Username, b.Account) + if message.Event != config.EVENT_USER_TYPING { + b.Log.Debugf("<= Sending message from %s on %s to gateway", message.Username, b.Account) + } // cleanup the message message.Text = b.replaceMention(message.Text) @@ -46,6 +48,14 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) { b.Log.Debugf("== Receiving event %#v", msg.Data) } switch ev := msg.Data.(type) { + case *slack.UserTypingEvent: + rmsg, err := b.handleTypingEvent(ev) + if err != nil { + b.Log.Errorf("%#v", err) + continue + } + + messages <- rmsg case *slack.MessageEvent: if b.skipMessageEvent(ev) { b.Log.Debugf("Skipped message: %#v", ev) @@ -225,6 +235,24 @@ func (b *Bslack) handleAttachments(ev *slack.MessageEvent, rmsg *config.Message) var commentRE = regexp.MustCompile(`.*?commented: (.*)`) +func (b *Bslack) handleTypingEvent(ev *slack.UserTypingEvent) (*config.Message, error) { + var err error + // use our own func because rtm.GetChannelInfo doesn't work for private channels + channelInfo, err := b.getChannelByID(ev.Channel) + if err != nil { + return nil, err + } + + rmsg := config.Message{ + Channel: channelInfo.Name, + Account: b.Account, + Event: config.EVENT_USER_TYPING, + } + + return &rmsg, nil + +} + // handleDownloadFile handles file download func (b *Bslack) handleDownloadFile(rmsg *config.Message, file *slack.File) error { if b.fileIsAvailable(file) { diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 8c96837e..701f4769 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -187,7 +187,10 @@ func (b *Bslack) Reload(cfg *bridge.Config) (string, error) { } func (b *Bslack) Send(msg config.Message) (string, error) { - b.Log.Debugf("=> Receiving %#v", msg) + // Too noisy to log like other events + if msg.Event != config.EVENT_USER_TYPING { + b.Log.Debugf("=> Receiving %#v", msg) + } // Make a action /me of the message if msg.Event == config.EVENT_USER_ACTION { @@ -266,6 +269,12 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) { if err != nil { return "", fmt.Errorf("could not send message: %v", err) } + if msg.Event == config.EVENT_USER_TYPING { + if b.GetBool("ShowUserTyping") { + b.rtm.SendMessage(b.rtm.NewTypingMessage(channelInfo.ID)) + } + return "", nil + } // Delete message if msg.Event == config.EVENT_MSG_DELETE { |