-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathconfigs_edit.go
More file actions
125 lines (107 loc) · 3.04 KB
/
configs_edit.go
File metadata and controls
125 lines (107 loc) · 3.04 KB
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
package telegram
import (
"encoding/json"
"net/url"
"strconv"
)
// BaseEdit is base type of all chat edits.
type BaseEdit struct {
// Required if inline_message_id is not specified.
// Unique identifier for the target chat or
// username of the target channel (in the format @channelusername)
ChatID int64
ChannelUsername string
// Required if inline_message_id is not specified.
// Unique identifier of the sent message
MessageID int64
// Required if chat_id and message_id are not specified.
// Identifier of the inline message
InlineMessageID string
// Only InlineKeyboardMarkup supported right now.
ReplyMarkup ReplyMarkup
}
// Values returns a url.Values representation of BaseEdit.
func (m BaseEdit) Values() (url.Values, error) {
v := url.Values{}
if m.ChannelUsername != "" {
v.Add("chat_id", m.ChannelUsername)
} else {
v.Add("chat_id", strconv.FormatInt(m.ChatID, 10))
}
if m.MessageID != 0 {
v.Add("message_id", strconv.FormatInt(m.MessageID, 10))
}
if m.InlineMessageID != "" {
v.Add("inline_message_id", m.InlineMessageID)
}
if m.ReplyMarkup != nil {
data, err := json.Marshal(m.ReplyMarkup)
if err != nil {
return nil, err
}
v.Add("reply_markup", string(data))
}
return v, nil
}
// EditMessageTextCfg allows you to modify the text in a message.
type EditMessageTextCfg struct {
BaseEdit
// New text of the message
Text string
// Send Markdown or HTML, if you want Telegram apps
// to show bold, italic, fixed-width text
// or inline URLs in your bot's message. Optional.
ParseMode string
// Disables link previews for links in this message. Optional.
DisableWebPagePreview bool
}
// Values returns a url.Values representation of EditMessageTextCfg.
func (cfg EditMessageTextCfg) Values() (url.Values, error) {
v, err := cfg.BaseEdit.Values()
if err != nil {
return nil, err
}
v.Add("text", cfg.Text)
if cfg.ParseMode != "" {
v.Add("parse_mode", cfg.ParseMode)
}
if cfg.DisableWebPagePreview {
v.Add("disable_web_page_preview", "true")
}
return v, nil
}
// Name returns method name
func (EditMessageTextCfg) Name() string {
return editMessageTextMethod
}
// EditMessageCaptionCfg allows you to modify the caption of a message.
type EditMessageCaptionCfg struct {
BaseEdit
// New caption of the message
Caption string
}
// Values returns a url.Values representation of EditMessageCaptionCfg.
func (cfg EditMessageCaptionCfg) Values() (url.Values, error) {
v, err := cfg.BaseEdit.Values()
if err != nil {
return nil, err
}
v.Add("text", cfg.Caption)
return v, nil
}
// Name returns method name
func (EditMessageCaptionCfg) Name() string {
return editMessageCaptionMethod
}
// EditMessageReplyMarkupCfg allows you to modify the reply markup of a message.
type EditMessageReplyMarkupCfg struct {
BaseEdit
}
// Values returns a url.Values representation of EditMessageReplyMarkupCfg.
func (cfg EditMessageReplyMarkupCfg) Values() (url.Values, error) {
return cfg.BaseEdit.Values()
}
// Name returns method name
func (EditMessageReplyMarkupCfg) Name() string {
return editMessageReplyMarkupMethod
}