1
0
telegram/get_updates.go

54 lines
2.0 KiB
Go
Raw Normal View History

2017-09-04 18:34:04 +00:00
package telegram
2017-09-05 09:20:10 +00:00
import json "github.com/pquerna/ffjson/ffjson"
2017-09-04 18:34:04 +00:00
type GetUpdatesParameters struct {
2017-10-06 07:55:54 +00:00
// Identifier of the first update to be returned. Must be greater by one than
// the highest among the identifiers of previously received updates. By
// default, updates starting with the earliest unconfirmed update are
// returned. An update is considered confirmed as soon as getUpdates is
// called with an offset higher than its update_id. The negative offset can
// be specified to retrieve updates starting from -offset update from the
// end of the updates queue. All previous updates will forgotten.
Offset int `json:"offset,omitempty"`
// Limits the number of updates to be retrieved. Values between 1—100 are
// accepted. Defaults to 100.
Limit int `json:"limit,omitempty"`
// Timeout in seconds for long polling. Defaults to 0, i.e. usual short
// polling. Should be positive, short polling should be used for testing
// purposes only.
Timeout int `json:"timeout,omitempty"`
// List the types of updates you want your bot to receive. For example,
// specify [“message”, “edited_channel_post”, “callback_query”] to only
// receive updates of these types. See Update for a complete list of
// available update types. Specify an empty list to receive all updates
// regardless of type (default). If not specified, the previous setting will
// be used.
2017-09-04 18:34:04 +00:00
//
2017-10-06 07:55:54 +00:00
// Please note that this parameter doesn't affect updates created before the
// call to the getUpdates, so unwanted updates may be received for a short
// period of time.
AllowedUpdates []string `json:"allowed_updates,omitempty"`
2017-09-04 18:34:04 +00:00
}
2017-10-06 07:55:54 +00:00
// GetUpdates receive incoming updates using long polling (wiki). An Array of
// Update objects is returned.
2017-10-06 08:47:05 +00:00
func (bot *Bot) GetUpdates(params *GetUpdatesParameters) ([]Update, error) {
2017-09-05 09:20:10 +00:00
dst, err := json.Marshal(params)
if err != nil {
return nil, err
2017-09-04 18:34:04 +00:00
}
2018-04-12 11:58:05 +00:00
resp, err := bot.request(dst, MethodGetUpdates)
2017-09-04 18:34:04 +00:00
if err != nil {
return nil, err
}
2017-10-06 08:47:05 +00:00
data := make([]Update, 100)
2017-09-05 09:20:10 +00:00
err = json.Unmarshal(*resp.Result, &data)
return data, err
2017-09-04 18:34:04 +00:00
}