pull/220/merge
Marc Arndt 6 years ago committed by GitHub
commit c59106a64d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      bot.go
  2. 68
      helpers.go
  3. 87
      types.go

@ -18,6 +18,47 @@ import (
"github.com/technoweenie/multipartstreamer"
)
type Bot interface {
MakeRequest(endpoint string, params url.Values) (APIResponse, error)
UploadFile(endpoint string, params map[string]string, fieldname string, file interface{}) (APIResponse, error)
GetFileDirectURL(fileID string) (string, error)
GetMe() (User, error)
IsMessageToMe(message Message) bool
Send(c Chattable) (Message, error)
GetUserProfilePhotos(config UserProfilePhotosConfig) (UserProfilePhotos, error)
GetFile(config FileConfig) (File, error)
GetUpdates(config UpdateConfig) ([]Update, error)
RemoveWebhook() (APIResponse, error)
SetWebhook(config WebhookConfig) (APIResponse, error)
GetWebhookInfo() (WebhookInfo, error)
GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error)
StopReceivingUpdates()
ListenForWebhook(pattern string) UpdatesChannel
AnswerInlineQuery(config InlineConfig) (APIResponse, error)
AnswerCallbackQuery(config CallbackConfig) (APIResponse, error)
KickChatMember(config KickChatMemberConfig) (APIResponse, error)
LeaveChat(config ChatConfig) (APIResponse, error)
GetChat(config ChatConfig) (Chat, error)
GetChatAdministrators(config ChatConfig) ([]ChatMember, error)
GetChatMembersCount(config ChatConfig) (int, error)
GetChatMember(config ChatConfigWithUser) (ChatMember, error)
UnbanChatMember(config ChatMemberConfig) (APIResponse, error)
RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error)
PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error)
GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error)
AnswerShippingQuery(config ShippingConfig) (APIResponse, error)
AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error)
DeleteMessage(config DeleteMessageConfig) (APIResponse, error)
GetInviteLink(config ChatConfig) (string, error)
PinChatMessage(config PinChatMessageConfig) (APIResponse, error)
UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, error)
SetChatTitle(config SetChatTitleConfig) (APIResponse, error)
SetChatDescription(config SetChatDescriptionConfig) (APIResponse, error)
SetChatPhoto(config SetChatPhotoConfig) (APIResponse, error)
DeleteChatPhoto(config DeleteChatPhotoConfig) (APIResponse, error)
}
// BotAPI allows you to interact with the Telegram Bot API.
type BotAPI struct {
Token string `json:"token"`
@ -439,6 +480,7 @@ func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
bytes, _ := ioutil.ReadAll(r.Body)
r.Body.Close()
var update Update
json.Unmarshal(bytes, &update)

@ -491,6 +491,15 @@ func NewInlineQueryResultGIF(id, url string) InlineQueryResultGIF {
}
}
// NewInlineQueryResultCachedGIF create a new inline query with cached photo.
func NewInlineQueryResultCachedGIF(id, gifID string) InlineQueryResultCachedGIF {
return InlineQueryResultCachedGIF{
Type: "gif",
ID: id,
GifID: gifID,
}
}
// NewInlineQueryResultMPEG4GIF creates a new inline query MPEG4 GIF.
func NewInlineQueryResultMPEG4GIF(id, url string) InlineQueryResultMPEG4GIF {
return InlineQueryResultMPEG4GIF{
@ -500,6 +509,15 @@ func NewInlineQueryResultMPEG4GIF(id, url string) InlineQueryResultMPEG4GIF {
}
}
// NewInlineQueryResultCachedPhoto create a new inline query with cached photo.
func NewInlineQueryResultCachedMPEG4GIF(id, MPEG4GifID string) InlineQueryResultCachedMpeg4Gif {
return InlineQueryResultCachedMpeg4Gif{
Type: "mpeg4_gif",
ID: id,
MGifID: MPEG4GifID,
}
}
// NewInlineQueryResultPhoto creates a new inline query photo.
func NewInlineQueryResultPhoto(id, url string) InlineQueryResultPhoto {
return InlineQueryResultPhoto{
@ -519,6 +537,15 @@ func NewInlineQueryResultPhotoWithThumb(id, url, thumb string) InlineQueryResult
}
}
// NewInlineQueryResultCachedPhoto create a new inline query with cached photo.
func NewInlineQueryResultCachedPhoto(id, photoID string) InlineQueryResultCachedPhoto {
return InlineQueryResultCachedPhoto{
Type: "photo",
ID: id,
PhotoID: photoID,
}
}
// NewInlineQueryResultVideo creates a new inline query video.
func NewInlineQueryResultVideo(id, url string) InlineQueryResultVideo {
return InlineQueryResultVideo{
@ -528,6 +555,16 @@ func NewInlineQueryResultVideo(id, url string) InlineQueryResultVideo {
}
}
// NewInlineQueryResultCachedVideo create a new inline query with cached video.
func NewInlineQueryResultCachedVideo(id, videoID, title string) InlineQueryResultCachedVideo {
return InlineQueryResultCachedVideo{
Type: "video",
ID: id,
VideoID: videoID,
Title: title,
}
}
// NewInlineQueryResultAudio creates a new inline query audio.
func NewInlineQueryResultAudio(id, url, title string) InlineQueryResultAudio {
return InlineQueryResultAudio{
@ -538,6 +575,15 @@ func NewInlineQueryResultAudio(id, url, title string) InlineQueryResultAudio {
}
}
// NewInlineQueryResultCachedAudio create a new inline query with cached photo.
func NewInlineQueryResultCachedAudio(id, audioID string) InlineQueryResultCachedAudio {
return InlineQueryResultCachedAudio{
Type: "audio",
ID: id,
AudioID: audioID,
}
}
// NewInlineQueryResultVoice creates a new inline query voice.
func NewInlineQueryResultVoice(id, url, title string) InlineQueryResultVoice {
return InlineQueryResultVoice{
@ -548,6 +594,16 @@ func NewInlineQueryResultVoice(id, url, title string) InlineQueryResultVoice {
}
}
// NewInlineQueryResultCachedVoice create a new inline query with cached photo.
func NewInlineQueryResultCachedVoice(id, voiceID, title string) InlineQueryResultCachedVoice {
return InlineQueryResultCachedVoice{
Type: "voice",
ID: id,
VoiceID: voiceID,
Title: title,
}
}
// NewInlineQueryResultDocument creates a new inline query document.
func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryResultDocument {
return InlineQueryResultDocument{
@ -559,6 +615,16 @@ func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryRe
}
}
// NewInlineQueryResultCachedDocument create a new inline query with cached photo.
func NewInlineQueryResultCachedDocument(id, documentID, title string) InlineQueryResultCachedDocument {
return InlineQueryResultCachedDocument{
Type: "document",
ID: id,
DocumentID: documentID,
Title: title,
}
}
// NewInlineQueryResultLocation creates a new inline query location.
func NewInlineQueryResultLocation(id, title string, latitude, longitude float64) InlineQueryResultLocation {
return InlineQueryResultLocation{
@ -588,7 +654,7 @@ func NewEditMessageCaption(chatID int64, messageID int, caption string) EditMess
ChatID: chatID,
MessageID: messageID,
},
Caption: caption,
Caption: caption,
}
}

@ -619,6 +619,19 @@ type InlineQueryResultPhoto struct {
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultCachedPhoto is an inline query response with cached photo.
type InlineQueryResultCachedPhoto struct {
Type string `json:"type"` // required
ID string `json:"id"` // required
PhotoID string `json:"photo_file_id"` // required
Title string `json:"title"`
Description string `json:"description"`
Caption string `json:"caption"`
ParseMode string `json:"parse_mode"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultGIF is an inline query response GIF.
type InlineQueryResultGIF struct {
Type string `json:"type"` // required
@ -634,6 +647,18 @@ type InlineQueryResultGIF struct {
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultCachedGIF is an inline query response with cached gif.
type InlineQueryResultCachedGIF struct {
Type string `json:"type"` // required
ID string `json:"id"` // required
GifID string `json:"gif_file_id"` // required
Title string `json:"title"`
Caption string `json:"caption"`
ParseMode string `json:"parse_mode"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
type InlineQueryResultMPEG4GIF struct {
Type string `json:"type"` // required
@ -649,6 +674,19 @@ type InlineQueryResultMPEG4GIF struct {
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultCachedMpeg4Gif is an inline query response with cached
// H.264/MPEG-4 AVC video without sound gif.
type InlineQueryResultCachedMpeg4Gif struct {
Type string `json:"type"` // required
ID string `json:"id"` // required
MGifID string `json:"mpeg4_file_id"` // required
Title string `json:"title"`
Caption string `json:"caption"`
ParseMode string `json:"parse_mode"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultVideo is an inline query response video.
type InlineQueryResultVideo struct {
Type string `json:"type"` // required
@ -666,6 +704,19 @@ type InlineQueryResultVideo struct {
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultCachedVideo is an inline query response with cached video.
type InlineQueryResultCachedVideo struct {
Type string `json:"type"` // required
ID string `json:"id"` // required
VideoID string `json:"video_file_id"` // required
Title string `json:"title"` // required
Description string `json:"description"`
Caption string `json:"caption"`
ParseMode string `json:"parse_mode"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultAudio is an inline query response audio.
type InlineQueryResultAudio struct {
Type string `json:"type"` // required
@ -679,6 +730,17 @@ type InlineQueryResultAudio struct {
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultCachedAudio is an inline query response with cached audio.
type InlineQueryResultCachedAudio struct {
Type string `json:"type"` // required
ID string `json:"id"` // required
AudioID string `json:"audio_file_id"` // required
Caption string `json:"caption"`
ParseMode string `json:"parse_mode"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultVoice is an inline query response voice.
type InlineQueryResultVoice struct {
Type string `json:"type"` // required
@ -691,6 +753,18 @@ type InlineQueryResultVoice struct {
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultCachedVoice is an inline query response with cached voice.
type InlineQueryResultCachedVoice struct {
Type string `json:"type"` // required
ID string `json:"id"` // required
VoiceID string `json:"voice_file_id"` // required
Title string `json:"title"` // required
Caption string `json:"caption"`
ParseMode string `json:"parse_mode"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultDocument is an inline query response document.
type InlineQueryResultDocument struct {
Type string `json:"type"` // required
@ -707,6 +781,19 @@ type InlineQueryResultDocument struct {
ThumbHeight int `json:"thumb_height"`
}
// InlineQueryResultCachedDocument is an inline query response with cached document.
type InlineQueryResultCachedDocument struct {
Type string `json:"type"` // required
ID string `json:"id"` // required
DocumentID string `json:"document_file_id"` // required
Title string `json:"title"` // required
Caption string `json:"caption"`
Description string `json:"description"`
ParseMode string `json:"parse_mode"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
InputMessageContent interface{} `json:"input_message_content,omitempty"`
}
// InlineQueryResultLocation is an inline query response location.
type InlineQueryResultLocation struct {
Type string `json:"type"` // required