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

How to send one message to many chanels #22

Closed amir3code closed 5 years ago

amir3code commented 5 years ago
// New RPC caller with a connection to Telegram server. 
caller := mtproto.RPCaller{mconn}

// New input peer
// Create a Predicate, InputPeerChannel, wraped by its parent Type, InputPeer.
channelPeer := &mtproto.TypeInputPeer{&mtproto.TypeInputPeer_InputPeerChannel{
    &mtproto.PredInputPeerChannel{
        yourChannelId, yourChannelHash,
    }}}

// Send a request to Telegram
caller.MessagesSendMessage(context.Background(), &mtproto.ReqMessagesSendMessage{
    Peer:      channelPeer,
    Message:   "Hello MTProto",
    RandomId:  rand.Int63(),
})

You have put this code in the README.md file of the project.
But the problem is that I have to specify each channel on each request.
How can I supply a list of channels or peers to send message to all of them at once?
Is it even possible? (I have seen people do it in telegram but I didn't find how, at the same time I have checked schema.tl file but there is no method that can accept a list type)

Thanks in advance for the great work of the project.

cjongseok commented 5 years ago

@amir3code I think the channel list should be handled in the application level. As you already checked schema.tl, the function is not supported in Telegram RPC (at least in this MTProto version 71). So I recommend to use MessagesSendMessage() for each channel.

In this case you should be care of RPC rate limit, and you can set RPC packet send delay on the configuration setup. In config, _ := mtproto.NewConfiguration(appVersion, deviceModel, systemVersion, language, 0, 0, "credentials.json"), the second '0' is the send delay. So if you set it as time.Second, mtproto's message sending routine would sleep for a second after each RPC call.

amir3code commented 5 years ago

Oh I got it. Thanks for the reply! Happy new year.