diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-03-12 20:25:53 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-03-12 20:25:53 +0300 |
commit | 022a12ce3174ebc53ad7be712fd37077145aaffc (patch) | |
tree | 8d99a186b4f621c2abcb63b6b61ed24be7ac86e8 /telegram/commands.go | |
parent | c6556eb6b86d4267bb35b7a27c34a0046668e3b9 (diff) |
Add /forward command
Diffstat (limited to 'telegram/commands.go')
-rw-r--r-- | telegram/commands.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/telegram/commands.go b/telegram/commands.go index 58f4db3..17d212f 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -59,6 +59,7 @@ var chatCommands = map[string]command{ "s": command{"edited message", "edit your last message"}, "silent": command{"message", "send a message without sound"}, "schedule": command{"{online | 2006-01-02T15:04:05 | 15:04:05} message", "schedules a message either to timestamp or to whenever the user goes online"}, + "forward": command{"message_id target_chat", "forwards a message"}, "add": command{"@username", "add @username to your chat list"}, "join": command{"https://t.me/invite_link", "join to chat via invite link"}, "group": command{"title", "create groupchat «title» with current user"}, @@ -575,6 +576,36 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) } else { return "Message processing error", true } + // forward a message to chat + case "forward": + if len(args) < 2 { + return notEnoughArguments, true + } + + messageId, err := strconv.ParseInt(args[0], 10, 64) + if err != nil { + return "Cannot parse message ID", true + } + + targetChatParts := strings.Split(args[1], "@") // full JIDs are supported too + targetChatId, err := strconv.ParseInt(targetChatParts[0], 10, 64) + if err != nil { + return "Cannot parse target chat ID", true + } + + messages, err := c.client.ForwardMessages(&client.ForwardMessagesRequest{ + ChatId: targetChatId, + FromChatId: chatID, + MessageIds: []int64{messageId}, + }) + if err != nil { + return err.Error(), true + } + if messages != nil && messages.Messages != nil { + for _, message := range messages.Messages { + c.ProcessIncomingMessage(targetChatId, message) + } + } // add @contact case "add": if len(args) < 1 { |