Skip to content

Commit

Permalink
Add Telegram sticker handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedy committed Mar 29, 2020
1 parent 68c8cc6 commit b243708
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
11 changes: 11 additions & 0 deletions internal/handlers/telegram/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ func messageHandler(tg *Client, u tgbotapi.Update) {
tg.sendToIrc(formatted)
}

/*
stickerHandler handles the Message.Sticker Telegram Object, which formats the
Telegram message into its base Emoji unicode character.
*/
func stickerHandler(tg *Client, u tgbotapi.Update) {
formatted := tg.Settings.Prefix + u.Message.From.UserName +
tg.Settings.Suffix + u.Message.Sticker.Emoji

tg.sendToIrc(formatted)
}

/*
documentHandler receives a document object from Telegram, and sends
a notification to IRC.
Expand Down
20 changes: 11 additions & 9 deletions internal/handlers/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ func (tg *Client) StartBot(errChan chan<- error, sendMessage func(string)) {

// TODO: Move these lines into the updateHandler when available
for update := range updates {
if update.Message == nil {
continue
switch {
case update.Message == nil:
continue
case update.Message.Text != "":
messageHandler(tg, update)
case update.Message.Sticker != nil:
stickerHandler(tg, update)
case update.Message.Document != nil:
documentHandler(tg, update.Message)
default:
continue
}

if update.Message.Document != nil {
documentHandler(tg, update.Message)
} else {
messageHandler(tg, update)
}

}
errChan <- nil
}

0 comments on commit b243708

Please sign in to comment.