Skip to content

Commit 858b175

Browse files
author
George Gabolaev
committed
voice sending example and some cosmetic changes
1 parent 947e14a commit 858b175

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

bot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (b *Bot) NewChat(id string) *Chat {
126126
// SendMessage sends a message, passed as an argument.
127127
// This method fills the argument with ID of sent message and returns an error if any.
128128
func (b *Bot) SendMessage(message *Message) error {
129-
return b.client.SendMessage(message)
129+
return b.client.SendTextMessage(message)
130130
}
131131

132132
// EditMessage edit a message passed as an argument.

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (c *Client) DeleteMessage(message *Message) error {
227227
return nil
228228
}
229229

230-
func (c *Client) SendFile(message *Message) error {
230+
func (c *Client) SendFileMessage(message *Message) error {
231231
params := url.Values{
232232
"chatId": {message.Chat.ID},
233233
"caption": {message.Text},
@@ -246,7 +246,7 @@ func (c *Client) SendFile(message *Message) error {
246246
return nil
247247
}
248248

249-
func (c *Client) SendVoice(message *Message) error {
249+
func (c *Client) SendVoiceMessage(message *Message) error {
250250
params := url.Values{
251251
"chatId": {message.Chat.ID},
252252
"caption": {message.Text},

example/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ func main() {
3434
}
3535

3636
fileMessage.Delete()
37+
file.Close()
38+
39+
file, err = os.Open("./voice.aac")
40+
if err != nil {
41+
log.Fatalf("cannot open file: %s", err)
42+
}
43+
defer file.Close()
44+
45+
voiceMessage := bot.NewVoiceMessage("[email protected]", file)
46+
if err := voiceMessage.Send(); err != nil {
47+
log.Println(err)
48+
}
3749

3850
// Simple 30-seconds echo bot
3951
ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)

example/voice.aac

239 KB
Binary file not shown.

message.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,22 @@ func (m *Message) Send() error {
8585
switch m.ContentType {
8686
case Voice:
8787
if m.FileID != "" {
88-
return m.client.SendVoice(m)
88+
return m.client.SendVoiceMessage(m)
8989
}
9090

9191
if m.File != nil {
9292
return m.client.UploadVoice(m)
9393
}
9494
case OtherFile:
9595
if m.FileID != "" {
96-
return m.client.SendFile(m)
96+
return m.client.SendFileMessage(m)
9797
}
9898

9999
if m.File != nil {
100100
return m.client.UploadFile(m)
101101
}
102102
case Text:
103-
return m.client.SendMessage(m)
103+
return m.client.SendTextMessage(m)
104104
}
105105

106106
return fmt.Errorf("cannot send message or file without data")
@@ -135,7 +135,7 @@ func (m *Message) Reply(text string) error {
135135
m.ReplyMsgID = m.ID
136136
m.Text = text
137137

138-
return m.client.SendMessage(m)
138+
return m.client.SendTextMessage(m)
139139
}
140140

141141
// Forward method forwards your message to chat.
@@ -149,5 +149,5 @@ func (m *Message) Forward(chatID string) error {
149149
m.ForwardMsgID = m.ID
150150
m.Chat.ID = chatID
151151

152-
return m.client.SendMessage(m)
152+
return m.client.SendTextMessage(m)
153153
}

0 commit comments

Comments
 (0)