Skip to content

Commit 2ffecf8

Browse files
ernadoclaude
andcommitted
feat(send): implement SendChatAction
Map the ChatAction enum onto the gotd typing-action builder (typing, upload/ record photo/video/voice/document, choose sticker, find location, video note). The switch is exhaustive; unknown actions return a 400. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7740497 commit 2ffecf8

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

send_action.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package botapi
2+
3+
import "context"
4+
5+
// SendChatAction tells the chat that the bot is performing an action (e.g.
6+
// "typing"). The status is cleared automatically after a short period or when
7+
// the next message is sent.
8+
//
9+
// The switch over ChatAction is exhaustive (exhaustive lint).
10+
func (b *Bot) SendChatAction(ctx context.Context, chat ChatID, action ChatAction) error {
11+
peer, err := b.resolveInputPeer(ctx, chat)
12+
if err != nil {
13+
return err
14+
}
15+
16+
a := b.sender.To(peer).TypingAction()
17+
switch action {
18+
case ChatActionTyping:
19+
err = a.Typing(ctx)
20+
case ChatActionUploadPhoto:
21+
err = a.UploadPhoto(ctx, 0)
22+
case ChatActionRecordVideo:
23+
err = a.RecordVideo(ctx)
24+
case ChatActionUploadVideo:
25+
err = a.UploadVideo(ctx, 0)
26+
case ChatActionRecordVoice:
27+
err = a.RecordAudio(ctx)
28+
case ChatActionUploadVoice:
29+
err = a.UploadAudio(ctx, 0)
30+
case ChatActionUploadDocument:
31+
err = a.UploadDocument(ctx, 0)
32+
case ChatActionChooseSticker:
33+
err = a.ChooseSticker(ctx)
34+
case ChatActionFindLocation:
35+
err = a.GeoLocation(ctx)
36+
case ChatActionRecordVideoNote:
37+
err = a.RecordRound(ctx)
38+
case ChatActionUploadVideoNote:
39+
err = a.UploadRound(ctx, 0)
40+
default:
41+
return &Error{Code: 400, Description: "Bad Request: wrong parameter action in request"}
42+
}
43+
return asAPIError(err)
44+
}

0 commit comments

Comments
 (0)