Chat actions implemented

pull/3/head
Ilya Kowalewski 9 years ago
parent 5da873e39b
commit 8dab2461ef

@ -403,3 +403,40 @@ func (b Bot) SendLocation(recipient User, geo *Location, options *SendOptions) e
return nil
}
// SendChatAction updates a chat action for recipient.
//
// Chat action is a status message that recipient would see where
// you typically see "Harry is typing" status message. The only
// difference is that bots' chat actions live only for 5 seconds
// and die just once the client recieves a message from the bot.
//
// Currently, Telegram supports only a narrow range of possible
// actions, these are aligned as constants of this package.
func (b Bot) SendChatAction(recipient User, action string) error {
params := url.Values{}
params.Set("chat_id", strconv.Itoa(recipient.Id))
params.Set("action", action)
responseJSON, err := sendCommand("sendChatAction", b.Token, params)
if err != nil {
return err
}
var responseRecieved struct {
Ok bool
Description string
}
err = json.Unmarshal(responseJSON, &responseRecieved)
if err != nil {
return err
}
if !responseRecieved.Ok {
return SendError{responseRecieved.Description}
}
return nil
}

@ -26,3 +26,15 @@
// }
//
package telebot
// A bunch of available chat actions.
const (
Typing = "typing"
UploadingPhoto = "upload_photo"
UploadingVideo = "upload_video"
UploadingAudio = "upload_audio"
UploadingDocument = "upload_document"
RecordingVideo = "record_video"
RecordingAudio = "record_audio"
FindingLocation = "find_location"
)

Loading…
Cancel
Save