Skip to content

Commit 75a4736

Browse files
ernadoclaude
andcommitted
chore(example): log business connection owner and rights
Fetch the connection on each business message and log owner_id, can_reply, enabled and whether the reply peer is the owner — to disambiguate BUSINESS_PEER_INVALID (missing reply right vs replying to the account itself). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 79a30e2 commit 75a4736

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

examples/business/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,23 @@ func handleBusiness(log *zap.Logger) botapi.Handler {
137137
return nil
138138
}
139139

140+
// Diagnostic: fetch the connection (a read, never a business send) to see
141+
// the owner id and granted rights, and whether we are about to reply to
142+
// the owner themselves (an invalid business peer).
143+
if conn, err := bc.Connection(c); err == nil {
144+
canReply := conn.Rights != nil && conn.Rights.CanReply
145+
log.Info("Business connection state",
146+
zap.String("connection", conn.ID),
147+
zap.Int64("owner_id", conn.User.ID),
148+
zap.Bool("enabled", conn.IsEnabled),
149+
zap.Bool("can_reply", canReply),
150+
zap.Int64("reply_peer", bm.Chat.ID),
151+
zap.Bool("reply_peer_is_owner", conn.User.ID == bm.Chat.ID),
152+
)
153+
} else {
154+
log.Warn("Get business connection", zap.Error(err))
155+
}
156+
140157
log.Info("Business message",
141158
zap.String("connection", bc.ConnectionID()),
142159
zap.Int64("chat", bm.Chat.ID),

0 commit comments

Comments
 (0)