Skip to content

Commit d80727d

Browse files
committed
feat: SetChatMemberTag
messages.editChatParticipantRank sets a custom tag/rank on any supergroup or channel member (the dedicated rank RPC, no admin-rights round-trip). Mapping confirmed against telegram-bot-api 10.1. Hermetic test; lint clean.
1 parent cadb46a commit d80727d

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

chat_admin_methods_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,24 @@ func TestSetChatAdministratorCustomTitle(t *testing.T) {
183183
t.Fatalf("rank = %q", req.Rank)
184184
}
185185
}
186+
187+
func TestSetChatMemberTag(t *testing.T) {
188+
inv := newMockInvoker()
189+
inv.reply(tg.MessagesEditChatParticipantRankRequestTypeID, okUpdates())
190+
191+
if err := newMockBot(inv).SetChatMemberTag(context.Background(), tdlibChannel(50), 60, "VIP"); err != nil {
192+
t.Fatalf("SetChatMemberTag: %v", err)
193+
}
194+
195+
var req tg.MessagesEditChatParticipantRankRequest
196+
197+
inv.decode(t, tg.MessagesEditChatParticipantRankRequestTypeID, &req)
198+
199+
if req.Rank != "VIP" {
200+
t.Fatalf("rank = %q", req.Rank)
201+
}
202+
203+
if _, ok := req.Participant.(*tg.InputPeerUser); !ok {
204+
t.Fatalf("participant = %#v, want user", req.Participant)
205+
}
206+
}

chat_member_methods.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,28 @@ func (b *Bot) SetChatAdministratorCustomTitle(ctx context.Context, chat ChatID,
297297

298298
return nil
299299
}
300+
301+
// SetChatMemberTag sets a custom tag (rank) for a member of a supergroup or
302+
// channel. An empty tag removes it. The bot must be an administrator with the
303+
// appropriate rights.
304+
func (b *Bot) SetChatMemberTag(ctx context.Context, chat ChatID, userID int64, tag string) error {
305+
peer, err := b.resolveInputPeer(ctx, chat)
306+
if err != nil {
307+
return err
308+
}
309+
310+
user, err := b.resolveInputUser(ctx, userID)
311+
if err != nil {
312+
return err
313+
}
314+
315+
if _, err := b.raw.MessagesEditChatParticipantRank(ctx, &tg.MessagesEditChatParticipantRankRequest{
316+
Peer: peer,
317+
Participant: userToInputPeer(user),
318+
Rank: tag,
319+
}); err != nil {
320+
return asAPIError(err)
321+
}
322+
323+
return nil
324+
}

0 commit comments

Comments
 (0)