summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-08-28 20:38:37 +0200
committerWim <wim@42.be>2017-08-28 23:07:03 +0200
commit7a86044f7aa8ff70c37be1b806718e39291c0494 (patch)
tree048cf31178f2b5faf087d187a1131a5b52b09953
parent8b98f605bc1d961ce3afa6ff84ed02e9b5112727 (diff)
downloadmatterbridge-msglm-7a86044f7aa8ff70c37be1b806718e39291c0494.tar.gz
matterbridge-msglm-7a86044f7aa8ff70c37be1b806718e39291c0494.tar.bz2
matterbridge-msglm-7a86044f7aa8ff70c37be1b806718e39291c0494.zip
Add support for editing messages (telegram)
-rw-r--r--bridge/telegram/telegram.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go
index d0c471b2..77a5f4e8 100644
--- a/bridge/telegram/telegram.go
+++ b/bridge/telegram/telegram.go
@@ -67,12 +67,31 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
if b.Config.MessageFormat == "HTML" {
msg.Text = makeHTML(msg.Text)
}
+
+ // edit the message if we have a msg ID
+ if msg.ID != "" {
+ msgid, err := strconv.Atoi(msg.ID)
+ if err != nil {
+ return "", err
+ }
+ m := tgbotapi.NewEditMessageText(chatid, msgid, msg.Username+msg.Text)
+ _, err = b.c.Send(m)
+ if err != nil {
+ return "", err
+ }
+ return "", nil
+ }
+
m := tgbotapi.NewMessage(chatid, msg.Username+msg.Text)
if b.Config.MessageFormat == "HTML" {
m.ParseMode = tgbotapi.ModeHTML
}
- _, err = b.c.Send(m)
- return "", err
+ res, err := b.c.Send(m)
+ if err != nil {
+ return "", err
+ }
+ return strconv.Itoa(res.MessageID), nil
+
}
func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
@@ -131,7 +150,7 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
}
if text != "" {
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, UserID: strconv.Itoa(message.From.ID)}
+ b.Remote <- config.Message{Username: username, Text: text, Channel: channel, Account: b.Account, UserID: strconv.Itoa(message.From.ID), ID: strconv.Itoa(message.MessageID)}
}
}
}