cjongseok / mtproto

Telegram MTProto and its proxy (over gRPC) in Go (golang). API Layer: 71
Apache License 2.0
151 stars 20 forks source link

Can't get ReplyToMsgId to work #15

Closed handlerug closed 6 years ago

handlerug commented 6 years ago

I am using your library and want to reply to message with some text. So I took your simpleshell example and slightly customised it.

Now in OnUpdate I have this code:

func (s *subscriber) OnUpdate(u mtproto.Update) {
    if _, ok := u.(*mtproto.PredUpdates); ok {
        predUpdates := u.(*mtproto.PredUpdates)
        updates := predUpdates.GetUpdates()
        for _, update := range updates {
            if _, ok := update.Value.(*mtproto.TypeUpdate_UpdateNewChannelMessage); ok {
                update := update.Value.(*mtproto.TypeUpdate_UpdateNewChannelMessage).UpdateNewChannelMessage
                message := update.Message.GetMessage()
                if message.GetToId().GetPeerChat() != nil {
                    continue
                }
                if message.Message == "/help" {
                    msgID := message.Id
                    chanID := message.ToId.GetPeerChannel().ChannelId
                    var chanHash int64
                    chats := predUpdates.GetChats()
                    for _, chat := range chats {
                        if chat.GetChannel().Id == chanID {
                            chanHash = chat.GetChannel().GetAccessHash()
                            break
                        }
                    }
                    peer := &mtproto.TypeInputPeer{Value: &mtproto.TypeInputPeer_InputPeerChannel{
                        InputPeerChannel: &mtproto.PredInputPeerChannel{
                            ChannelId: chanID, AccessHash: chanHash,
                        }}}
                    _, err := s.caller.MessagesSendMessage(context.Background(), &mtproto.ReqMessagesSendMessage{
                        Peer:         peer,
                        Message:      "Test of hndbot.",
                        ReplyToMsgId: msgID,
                        RandomId:     rand.Int63(),
                    })
                    handleError(err)
                }
            }
        }
    }
}

But message is sending without ReplyToMsgId (I also looked on MessagesSendMessage response and there isn't ReplyToMsgId too). Screenshot from Telegram Desktop:

Telegram Desktop screenshot

So how I can get replies to work? Do I need to use flags (as schema shows) or I did something wrong?

cjongseok commented 6 years ago

Thanks for your interest in this repository. Actually I didn't try all the features in mtproto, since the scope of this repository is just encoding and decoding mtproto packets for its RPC. So I have no idea for the exact usage of mtproto for 'reply to a message', and need to try it to figure it out. Unfortunately, I can do that after a couple of days. After trying that, I will let you know the result.

handlerug commented 6 years ago

Thanks for quick reply! 👍 I was confused by ReplyToMsgId field because in SendMessage schema I should pass message ID into flags. But Flags field has type int32, and I can't pass parameters in it (message ID also has type int32). So I will wait for your response. Thanks in advance!

cjongseok commented 6 years ago

@handlerug I think MsgID is in the right place.Flags is for marking whether optional fields are filled with, and it seems ReplyToMsgId also needs to set it. Can you set Flags = 1 and try your example again?

Due to my business emergency I cannot try it now. Sorry for that. If Flags does not work, maybe I think I can try in on Friday.

handlerug commented 6 years ago

Yes, that's working! 😃 Thanks for help!