-
-
Notifications
You must be signed in to change notification settings - Fork 127
/
typing.go
131 lines (106 loc) · 4.05 KB
/
typing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package message
import (
"context"
"golang.org/x/xerrors"
"github.com/gotd/td/tg"
)
// TypingActionBuilder is a helper to create and send typing actions.
//
// See https://core.telegram.org/method/messages.setTyping.
//
// See https://core.telegram.org/type/SendMessageAction.
type TypingActionBuilder struct {
sender *Sender
peer peerPromise
topMsgID int
}
// ThreadID sets thread ID to send.
func (b *TypingActionBuilder) ThreadID(id int) *TypingActionBuilder {
b.topMsgID = id
return b
}
// ThreadMsg sets message's ID as thread ID to send.
func (b *TypingActionBuilder) ThreadMsg(msg tg.MessageClass) *TypingActionBuilder {
return b.ThreadID(msg.GetID())
}
func (b *TypingActionBuilder) send(ctx context.Context, action tg.SendMessageActionClass) error {
p, err := b.peer(ctx)
if err != nil {
return xerrors.Errorf("peer: %w", err)
}
if err := b.sender.setTyping(ctx, &tg.MessagesSetTypingRequest{
Peer: p,
TopMsgID: b.topMsgID,
Action: action,
}); err != nil {
return xerrors.Errorf("set typing: %w", err)
}
return nil
}
// Typing sends SendMessageTypingAction.
func (b *TypingActionBuilder) Typing(ctx context.Context) error {
return b.send(ctx, &tg.SendMessageTypingAction{})
}
// Cancel sends SendMessageCancelAction.
func (b *TypingActionBuilder) Cancel(ctx context.Context) error {
return b.send(ctx, &tg.SendMessageCancelAction{})
}
// RecordVideo sends SendMessageRecordVideoAction.
func (b *TypingActionBuilder) RecordVideo(ctx context.Context) error {
return b.send(ctx, &tg.SendMessageRecordVideoAction{})
}
// UploadVideo sends SendMessageUploadVideoAction.
func (b *TypingActionBuilder) UploadVideo(ctx context.Context, progress int) error {
return b.send(ctx, &tg.SendMessageUploadVideoAction{Progress: progress})
}
// RecordAudio sends SendMessageRecordAudioAction.
func (b *TypingActionBuilder) RecordAudio(ctx context.Context) error {
return b.send(ctx, &tg.SendMessageRecordAudioAction{})
}
// UploadAudio sends SendMessageUploadAudioAction.
func (b *TypingActionBuilder) UploadAudio(ctx context.Context, progress int) error {
return b.send(ctx, &tg.SendMessageUploadAudioAction{Progress: progress})
}
// UploadPhoto sends SendMessageUploadPhotoAction.
func (b *TypingActionBuilder) UploadPhoto(ctx context.Context, progress int) error {
return b.send(ctx, &tg.SendMessageUploadPhotoAction{Progress: progress})
}
// UploadDocument sends SendMessageUploadDocumentAction.
func (b *TypingActionBuilder) UploadDocument(ctx context.Context, progress int) error {
return b.send(ctx, &tg.SendMessageUploadDocumentAction{Progress: progress})
}
// GeoLocation sends SendMessageGeoLocationAction.
func (b *TypingActionBuilder) GeoLocation(ctx context.Context) error {
return b.send(ctx, &tg.SendMessageGeoLocationAction{})
}
// ChooseContact sends SendMessageChooseContactAction.
func (b *TypingActionBuilder) ChooseContact(ctx context.Context) error {
return b.send(ctx, &tg.SendMessageChooseContactAction{})
}
// GamePlay sends SendMessageGamePlayAction.
func (b *TypingActionBuilder) GamePlay(ctx context.Context) error {
return b.send(ctx, &tg.SendMessageGamePlayAction{})
}
// RecordRound sends SendMessageRecordRoundAction.
func (b *TypingActionBuilder) RecordRound(ctx context.Context) error {
return b.send(ctx, &tg.SendMessageRecordRoundAction{})
}
// UploadRound sends SendMessageUploadRoundAction.
func (b *TypingActionBuilder) UploadRound(ctx context.Context, progress int) error {
return b.send(ctx, &tg.SendMessageUploadRoundAction{Progress: progress})
}
// SpeakingInGroupCall sends SpeakingInGroupCallAction.
func (b *TypingActionBuilder) SpeakingInGroupCall(ctx context.Context) error {
return b.send(ctx, &tg.SpeakingInGroupCallAction{})
}
// HistoryImport sends SendMessageHistoryImportAction.
func (b *TypingActionBuilder) HistoryImport(ctx context.Context, progress int) error {
return b.send(ctx, &tg.SendMessageHistoryImportAction{Progress: progress})
}
// TypingAction creates TypingActionBuilder.
func (b *RequestBuilder) TypingAction() *TypingActionBuilder {
return &TypingActionBuilder{
sender: b.sender,
peer: b.peer,
}
}