Sending audio

pull/3/head
Ilya Kowalewski 9 years ago
parent 6a4863ece8
commit 51d01479b6

@ -230,3 +230,42 @@ func api_sendPhoto(token string, recipient User, photo *Photo) error {
return nil
}
func api_sendAudio(token string, recipient User, audio *Audio) error {
params := url.Values{}
params.Set("chat_id", strconv.Itoa(recipient.Id))
var response_json []byte
var err error
if audio.Exists() {
params.Set("audio", audio.FileId)
response_json, err = api_GET("sendAudio", token, params)
} else {
response_json, err = api_POST("sendAudio", token, "audio",
audio.filename, params)
}
if err != nil {
return err
}
var response_recieved struct {
Ok bool
Result Message
Description string
}
err = json.Unmarshal(response_json, &response_recieved)
if err != nil {
return err
}
if !response_recieved.Ok {
return SendError{response_recieved.Description}
}
*audio = response_recieved.Result.Audio
return nil
}

@ -49,6 +49,21 @@ func (b *Bot) ForwardMessage(recipient User, message Message) error {
}
// SendPhoto sends a photo object to recipient.
//
// On success, photo object would be aliased to its copy on
// the Telegram servers, so sending the same photo object
// again, won't issue a new upload, but would make a use
// of existing file on Telegram servers.
func (b *Bot) SendPhoto(recipient User, photo *Photo) error {
return api_sendPhoto(b.Token, recipient, photo)
}
// SendPhoto sends an audio object to recipient.
//
// On success, audio object would be aliased to its copy on
// the Telegram servers, so sending the same audio object
// again, won't issue a new upload, but would make a use
// of existing file on Telegram servers.
func (b *Bot) SendAudio(recipient User, audio *Audio) error {
return api_sendAudio(b.Token, recipient, audio)
}

Loading…
Cancel
Save