[bug]: Bot echo message don't have Users in entities
My test Code
func main() {
// Environment variables:
examples.Run(func(ctx context.Context, log *zap.Logger) error {
// Dispatcher handles incoming updates.
dispatcher := tg.NewUpdateDispatcher()
opts := telegram.Options{
Logger: log,
UpdateHandler: dispatcher,
}
return telegram.BotFromEnvironment(ctx, opts, func(ctx context.Context, client *telegram.Client) error {
// Raw MTProto API client, allows making raw RPC calls.
api := tg.NewClient(client)
// Helper for sending messages.
sender := message.NewSender(api)
// Setting up handler for incoming message.
dispatcher.OnNewMessage(func(ctx context.Context, entities tg.Entities, u *tg.UpdateNewMessage) error {
m, ok := u.Message.(*tg.Message)
if !ok || m.Out {
// Outgoing message, not interesting.
return nil
}
// entities.Users[2127968597] = &tg.User{ID: 2127968597}
log.Sugar().Infof("entities=%#v", entities)
log.Sugar().Infof("m,=%#v", m)
// Sending reply.
_, err := sender.Reply(entities, u).Text(ctx, "message from td")
return err
})
return nil
}, telegram.RunUntilCanceled)
})
}
what I got
{"level":"INFO","ts":"2021-12-18 10:38:40","caller":"auth/main.go:163","msg":"Message,got message ppp"}
2021-12-18T10:38:40.369+0800 DEBUG conn.mtproto mtproto/handle_message.go:19 Handle message {"v": "v0.54.0-alpha.0", "conn_id": 0, "dc_id": 5, "type_id": "0x74ae4240", "type_name": "updates#74ae4240", "size_bytes": 844, "msg_id": 7042866422552158209}
{"level":"INFO","ts":"2021-12-18 10:38:40","caller":"auth/main.go:165","msg":"entities={true map[] map[] map[]}"}
{"level":"INFO","ts":"2021-12-18 10:38:40","caller":"auth/main.go:166","msg":"m=Message{Flags:100000000 Out:false Mentioned:false MediaUnread:false Silent:false Post:false FromScheduled:false Legacy:false EditHide:false Pinned:false ID:2564 FromID:PeerUser{UserID:1560939195} PeerID:PeerUser{UserID:1560939195} FwdFrom:{Flags:0 Imported:false FromID:<nil> FromName: Date:0 ChannelPost:0 PostAuthor: SavedFromPeer:<nil> SavedFromMsgID:0 PsaType:} ViaBotID:0 ReplyTo:{Flags:0 ReplyToMsgID:0 ReplyToPeerID:<nil> ReplyToTopID:0} Date:1639795122 Message:ppp Media:<nil> ReplyMarkup:<nil> Entities:[] Views:0 Forwards:0 Replies:{Flags:0 Comments:false Replies:0 RepliesPts:0 RecentRepliers:[] ChannelID:0 MaxID:0 ReadMaxID:0} EditDate:0 PostAuthor: GroupedID:0 RestrictionReason:[] TTLPeriod:0}"}
2021-12-18T10:38:40.370+0800 DEBUG conn.mtproto mtproto/handle_message.go:19 Handle message {"v": "v0.54.0-alpha.0", "conn_id": 0, "dc_id": 5, "type_id": "0x74ae4240", "type_name": "updates#74ae4240", "size_bytes": 260, "msg_id": 7042866422552205313}
2021-12-18T10:38:40.370+0800 DEBUG conn.mtproto mtproto/handle_message.go:19 Handle message {"v": "v0.54.0-alpha.0", "conn_id": 0, "dc_id": 5, "type_id": "0x78d4dec1", "type_name": "updateShort#78d4dec1", "size_bytes": 40, "msg_id": 7042866422552205313}
2021-12-18T10:38:40.370+0800 DEBUG conn.mtproto mtproto/handle_message.go:19 Handle message {"v": "v0.54.0-alpha.0", "conn_id": 0, "dc_id": 5, "type_id": "0x74ae4240", "type_name": "updates#74ae4240", "size_bytes": 520, "msg_id": 7042866422552205313}
2021-12-18T10:38:44.233+0800 DEBUG conn.mtproto mtproto/new_encrypted_msg.go:62 Request {"v": "v0.54.0-alpha.0", "conn_id": 0, "dc_id": 5, "type_id": "0x62d6b459", "type_name": "msgs_ack#62d6b459", "msg_id": 7042866429953721704}
2021-12-18T10:38:44.233+0800 DEBUG conn.mtproto.ack mtproto/ack.go:24 Ack {"v": "v0.54.0-alpha.0", "conn_id": 0, "dc_id": 5, "msg_ids": [7042866375007386625, 7042866375007346689, 7042866375007364097, 7042866375007385601, 7042866375007348737, 7042866375007444993, 7042866422552157185, 7042866422552155137, 7042866422552156161, 7042866422552158209]}
seems the entities from callback function OnNewMessage is not correctly set. and the Users map is empty
The weirdo part is, if I send a text message, the entities are empty, if I send Image messages, it will be good.

Hey, thank you for your report, I'll investigate.
Even our bot just stopped working.
Has the problem been fixed? I also found no Users and Chats in the entities in the user messages
same problem.
Experienced the same issue. Had a very quick look through and I got to tl_handlers_gen.go:80. Whenever the message is received, it ends up as UpdateShort type and therefore doesn't have any entities set.
As far as I understand, when someone send you a little text message, you got just an UpdateShort without sender User or even their AccessHash to retrieve them later. How do you guys deal with it?
@ernado, do you have any progress on this issue or some alternative solution?
Initial issue were resolved long time ago.
Entities should be cached by client. You can use gotd/contrib/storage#PeerStorage for that. For example, there are pebble and redis storage implementations, but you can make your own.