helper_structs.go (view raw)
1package tgbotapi
2
3// ChatConfig is a base type for all chat identifiers
4type ChatConfig struct {
5 ChatID int64
6 ChannelUsername string
7 SuperGroupUsername string
8}
9
10func (base ChatConfig) params() (Params, error) {
11 return base.paramsWithKey("chat_id")
12}
13
14func (base ChatConfig) paramsWithKey(key string) (Params, error) {
15 params := make(Params)
16 return params, params.AddFirstValid(key, base.ChatID, base.ChannelUsername, base.SuperGroupUsername)
17}
18
19// BaseChat is base type for all chat config types.
20type BaseChat struct {
21 ChatConfig
22 BusinessConnectionID BusinessConnectionID
23 MessageThreadID int
24 ProtectContent bool
25 ReplyMarkup interface{}
26 DisableNotification bool
27 ReplyParameters ReplyParameters
28}
29
30func (chat *BaseChat) params() (Params, error) {
31 params, err := chat.ChatConfig.params()
32 if err != nil {
33 return params, err
34 }
35 p1, err := chat.BusinessConnectionID.params()
36 if err != nil {
37 return params, err
38 }
39 params.Merge(p1)
40
41 params.AddNonZero("message_thread_id", chat.MessageThreadID)
42 params.AddBool("disable_notification", chat.DisableNotification)
43 params.AddBool("protect_content", chat.ProtectContent)
44
45 err = params.AddInterface("reply_markup", chat.ReplyMarkup)
46 if err != nil {
47 return params, err
48 }
49 err = params.AddInterface("reply_parameters", chat.ReplyParameters)
50 return params, err
51}
52
53// BaseFile is a base type for all file config types.
54type BaseFile struct {
55 BaseChat
56 File RequestFileData
57}
58
59func (file BaseFile) params() (Params, error) {
60 return file.BaseChat.params()
61}
62
63// BaseEdit is base type of all chat edits.
64type BaseEdit struct {
65 BaseChatMessage
66 InlineMessageID string
67 ReplyMarkup *InlineKeyboardMarkup
68}
69
70func (edit BaseEdit) params() (Params, error) {
71 params := make(Params)
72
73 if edit.InlineMessageID != "" {
74 params["inline_message_id"] = edit.InlineMessageID
75 } else {
76 p1, err := edit.BaseChatMessage.params()
77 if err != nil {
78 return params, err
79 }
80 params.Merge(p1)
81 }
82
83 err := params.AddInterface("reply_markup", edit.ReplyMarkup)
84
85 return params, err
86}
87
88// BaseSpoiler is base type of structures with spoilers.
89type BaseSpoiler struct {
90 HasSpoiler bool
91}
92
93func (spoiler BaseSpoiler) params() (Params, error) {
94 params := make(Params)
95
96 if spoiler.HasSpoiler {
97 params.AddBool("has_spoiler", true)
98 }
99
100 return params, nil
101}
102
103// BaseChatMessage is a base type for all messages in chats.
104type BaseChatMessage struct {
105 ChatConfig
106 MessageID int
107}
108
109func (base BaseChatMessage) params() (Params, error) {
110 params, err := base.ChatConfig.params()
111 if err != nil {
112 return params, err
113 }
114 params.AddNonZero("message_id", base.MessageID)
115
116 return params, nil
117}
118
119// BaseChatMessages is a base type for all messages in chats.
120type BaseChatMessages struct {
121 ChatConfig
122 MessageIDs []int
123}
124
125func (base BaseChatMessages) params() (Params, error) {
126 params, err := base.ChatConfig.params()
127 if err != nil {
128 return params, err
129 }
130 err = params.AddInterface("message_ids", base.MessageIDs)
131
132 return params, err
133}