Skip to content

Commit

Permalink
Convert "..." to a typing indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
venkytv committed Apr 25, 2023
1 parent 74630eb commit 0e80958
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/slack_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ type SlackApier interface {
ChannelInfo(channel string) *slack.Channel
GetEvents() chan slack.RTMEvent
PostMessage(channel string, msgOptions ...slack.MsgOption) (string, error)
PostTypingIndicator(channel string)
}

// SlackApi implements the SlackApier interface
type SlackApi struct {
client *slack.Client
rtm *slack.RTM
Expand All @@ -44,6 +46,10 @@ func (s SlackApi) PostMessage(channel string, msgOptions ...slack.MsgOption) (st
return timestamp, err
}

func (s SlackApi) PostTypingIndicator(channel string) {
s.rtm.SendMessage(s.rtm.NewTypingMessage(channel))
}

func NewSlackApi(token string, debug bool) SlackApi {
client := slack.New(
token,
Expand Down Expand Up @@ -199,6 +205,12 @@ func (s SlackBackend) Post() {
}
logrus.Debugf("Got response: %#v", msg)

if msg.Text == "..." {
// Send a typing indicator
s.api.PostTypingIndicator(msg.ChannelId)
continue
}

msgOptions := []slack.MsgOption{
slack.MsgOptionText(msg.Text, false),
slack.MsgOptionAsUser(true),
Expand Down

0 comments on commit 0e80958

Please sign in to comment.