diff options
author | Wim <wim@42.be> | 2017-01-27 23:26:06 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-01-27 23:26:06 +0100 |
commit | 678a7ceb4e4e40ab2f2c8c8529c4997376a39555 (patch) | |
tree | 67ab38063da201599bec1c9661230831f1081c0d /bridge/telegram/telegram.go | |
parent | 077d494c7bd6fc0b8c2fa1c537cccd7959d0f201 (diff) | |
download | matterbridge-msglm-678a7ceb4e4e40ab2f2c8c8529c4997376a39555.tar.gz matterbridge-msglm-678a7ceb4e4e40ab2f2c8c8529c4997376a39555.tar.bz2 matterbridge-msglm-678a7ceb4e4e40ab2f2c8c8529c4997376a39555.zip |
Fix channel and group messages (telegram)
Diffstat (limited to 'bridge/telegram/telegram.go')
-rw-r--r-- | bridge/telegram/telegram.go | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index b179dd6d..cbf8eedf 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -124,11 +124,33 @@ func (b *Btelegram) Send(msg config.Message) error { } func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { + username := "" + text := "" + channel := "" for update := range updates { - if update.Message == nil { - continue + // handle channels + if update.ChannelPost != nil { + if update.ChannelPost.From != nil { + username = update.ChannelPost.From.FirstName + if username == "" { + username = update.ChannelPost.From.UserName + } + text = update.ChannelPost.Text + channel = strconv.FormatInt(update.ChannelPost.Chat.ID, 10) + } } - flog.Debugf("Sending message from %s on %s to gateway", update.Message.From.UserName, b.Account) - b.Remote <- config.Message{Username: update.Message.From.UserName, Text: update.Message.Text, Channel: strconv.FormatInt(update.Message.Chat.ID, 10), Account: b.Account} + // handle groups + if update.Message != nil { + if update.Message.From != nil { + username = update.Message.From.FirstName + if username == "" { + username = update.Message.From.UserName + } + text = update.Message.Text + channel = strconv.FormatInt(update.Message.Chat.ID, 10) + } + } + flog.Debugf("Sending message from %s on %s to gateway", username, b.Account) + b.Remote <- config.Message{Username: username, Text: text, Channel: channel, Account: b.Account} } } |