all repos — telegram-bot-api @ 95a923dc4c570e5aadd7dbed2be03499892b3f6b

Golang bindings for the Telegram Bot API

bot.go (view raw)

  1// Package tgbotapi has functions and types used for interacting with
  2// the Telegram Bot API.
  3package tgbotapi
  4
  5import (
  6	"bytes"
  7	"encoding/json"
  8	"errors"
  9	"fmt"
 10	"io"
 11	"io/ioutil"
 12	"log"
 13	"net/http"
 14	"net/url"
 15	"os"
 16	"strconv"
 17	"strings"
 18	"time"
 19
 20	"github.com/technoweenie/multipartstreamer"
 21)
 22
 23// BotAPI allows you to interact with the Telegram Bot API.
 24type BotAPI struct {
 25	Token  string `json:"token"`
 26	Debug  bool   `json:"debug"`
 27	Buffer int    `json:"buffer"`
 28
 29	Self   User         `json:"-"`
 30	Client *http.Client `json:"-"`
 31}
 32
 33// NewBotAPI creates a new BotAPI instance.
 34//
 35// It requires a token, provided by @BotFather on Telegram.
 36func NewBotAPI(token string) (*BotAPI, error) {
 37	return NewBotAPIWithClient(token, &http.Client{})
 38}
 39
 40// NewBotAPIWithClient creates a new BotAPI instance
 41// and allows you to pass a http.Client.
 42//
 43// It requires a token, provided by @BotFather on Telegram.
 44func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) {
 45	bot := &BotAPI{
 46		Token:  token,
 47		Client: client,
 48		Buffer: 100,
 49	}
 50
 51	self, err := bot.GetMe()
 52	if err != nil {
 53		return nil, err
 54	}
 55
 56	bot.Self = self
 57
 58	return bot, nil
 59}
 60
 61// MakeRequest makes a request to a specific endpoint with our token.
 62func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, error) {
 63	method := fmt.Sprintf(APIEndpoint, bot.Token, endpoint)
 64
 65	resp, err := bot.Client.PostForm(method, params)
 66	if err != nil {
 67		return APIResponse{}, err
 68	}
 69	defer resp.Body.Close()
 70
 71	var apiResp APIResponse
 72	bytes, err := bot.decodeAPIResponse(resp.Body, &apiResp)
 73	if err != nil {
 74		return apiResp, err
 75	}
 76
 77	if bot.Debug {
 78		log.Printf("%s resp: %s", endpoint, bytes)
 79	}
 80
 81	if !apiResp.Ok {
 82		return apiResp, errors.New(apiResp.Description)
 83	}
 84
 85	return apiResp, nil
 86}
 87
 88// decodeAPIResponse decode response and return slice of bytes if debug enabled.
 89// If debug disabled, just decode http.Response.Body stream to APIResponse struct
 90// for efficient memory usage
 91func (bot *BotAPI) decodeAPIResponse(responseBody io.Reader, resp *APIResponse) (_ []byte, err error) {
 92	if !bot.Debug {
 93		dec := json.NewDecoder(responseBody)
 94		err = dec.Decode(resp)
 95		return
 96	}
 97
 98	// if debug, read reponse body
 99	data, err := ioutil.ReadAll(responseBody)
100	if err != nil {
101		return
102	}
103
104	err = json.Unmarshal(data, resp)
105	if err != nil {
106		return
107	}
108
109	return data, nil
110}
111
112// UploadFile makes a request to the API with a file.
113//
114// Requires the parameter to hold the file not be in the params.
115// File should be a string to a file path, a FileBytes struct,
116// a FileReader struct, or a url.URL.
117//
118// Note that if your FileReader has a size set to -1, it will read
119// the file into memory to calculate a size.
120func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldname string, file interface{}) (APIResponse, error) {
121	ms := multipartstreamer.New()
122
123	switch f := file.(type) {
124	case string:
125		ms.WriteFields(params)
126
127		fileHandle, err := os.Open(f)
128		if err != nil {
129			return APIResponse{}, err
130		}
131		defer fileHandle.Close()
132
133		fi, err := os.Stat(f)
134		if err != nil {
135			return APIResponse{}, err
136		}
137
138		ms.WriteReader(fieldname, fileHandle.Name(), fi.Size(), fileHandle)
139	case FileBytes:
140		ms.WriteFields(params)
141
142		buf := bytes.NewBuffer(f.Bytes)
143		ms.WriteReader(fieldname, f.Name, int64(len(f.Bytes)), buf)
144	case FileReader:
145		ms.WriteFields(params)
146
147		if f.Size != -1 {
148			ms.WriteReader(fieldname, f.Name, f.Size, f.Reader)
149
150			break
151		}
152
153		data, err := ioutil.ReadAll(f.Reader)
154		if err != nil {
155			return APIResponse{}, err
156		}
157
158		buf := bytes.NewBuffer(data)
159
160		ms.WriteReader(fieldname, f.Name, int64(len(data)), buf)
161	case url.URL:
162		params[fieldname] = f.String()
163
164		ms.WriteFields(params)
165	default:
166		return APIResponse{}, errors.New(ErrBadFileType)
167	}
168
169	method := fmt.Sprintf(APIEndpoint, bot.Token, endpoint)
170
171	req, err := http.NewRequest("POST", method, nil)
172	if err != nil {
173		return APIResponse{}, err
174	}
175
176	ms.SetupRequest(req)
177
178	res, err := bot.Client.Do(req)
179	if err != nil {
180		return APIResponse{}, err
181	}
182	defer res.Body.Close()
183
184	bytes, err := ioutil.ReadAll(res.Body)
185	if err != nil {
186		return APIResponse{}, err
187	}
188
189	if bot.Debug {
190		log.Println(string(bytes))
191	}
192
193	var apiResp APIResponse
194
195	err = json.Unmarshal(bytes, &apiResp)
196	if err != nil {
197		return APIResponse{}, err
198	}
199
200	if !apiResp.Ok {
201		return APIResponse{}, errors.New(apiResp.Description)
202	}
203
204	return apiResp, nil
205}
206
207// GetFileDirectURL returns direct URL to file
208//
209// It requires the FileID.
210func (bot *BotAPI) GetFileDirectURL(fileID string) (string, error) {
211	file, err := bot.GetFile(FileConfig{fileID})
212
213	if err != nil {
214		return "", err
215	}
216
217	return file.Link(bot.Token), nil
218}
219
220// GetMe fetches the currently authenticated bot.
221//
222// This method is called upon creation to validate the token,
223// and so you may get this data from BotAPI.Self without the need for
224// another request.
225func (bot *BotAPI) GetMe() (User, error) {
226	resp, err := bot.MakeRequest("getMe", nil)
227	if err != nil {
228		return User{}, err
229	}
230
231	var user User
232	json.Unmarshal(resp.Result, &user)
233
234	bot.debugLog("getMe", nil, user)
235
236	return user, nil
237}
238
239// IsMessageToMe returns true if message directed to this bot.
240//
241// It requires the Message.
242func (bot *BotAPI) IsMessageToMe(message Message) bool {
243	return strings.Contains(message.Text, "@"+bot.Self.UserName)
244}
245
246// Send will send a Chattable item to Telegram.
247//
248// It requires the Chattable to send.
249func (bot *BotAPI) Send(c Chattable) (Message, error) {
250	resp, err := bot.Request(c)
251	if err != nil {
252		return Message{}, err
253	}
254
255	var message Message
256	err = json.Unmarshal(resp.Result, &message)
257
258	return message, err
259}
260
261// Request makes a request to Telegram that returns an APIResponse, rather than
262// a Message.
263func (bot *BotAPI) Request(c Chattable) (APIResponse, error) {
264	switch t := c.(type) {
265	case Fileable:
266		if t.useExistingFile() {
267			v, err := t.values()
268			if err != nil {
269				return APIResponse{}, err
270			}
271
272			return bot.MakeRequest(t.method(), v)
273		}
274
275		p, err := t.params()
276		if err != nil {
277			return APIResponse{}, err
278		}
279
280		return bot.UploadFile(t.method(), p, t.name(), t.getFile())
281	default:
282		v, err := c.values()
283		if err != nil {
284			return APIResponse{}, err
285		}
286
287		return bot.MakeRequest(c.method(), v)
288	}
289}
290
291// debugLog checks if the bot is currently running in debug mode, and if
292// so will display information about the request and response in the
293// debug log.
294func (bot *BotAPI) debugLog(context string, v url.Values, message interface{}) {
295	if bot.Debug {
296		log.Printf("%s req : %+v\n", context, v)
297		log.Printf("%s resp: %+v\n", context, message)
298	}
299}
300
301// GetUserProfilePhotos gets a user's profile photos.
302//
303// It requires UserID.
304// Offset and Limit are optional.
305func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserProfilePhotos, error) {
306	v := url.Values{}
307	v.Add("user_id", strconv.Itoa(config.UserID))
308	if config.Offset != 0 {
309		v.Add("offset", strconv.Itoa(config.Offset))
310	}
311	if config.Limit != 0 {
312		v.Add("limit", strconv.Itoa(config.Limit))
313	}
314
315	resp, err := bot.MakeRequest("getUserProfilePhotos", v)
316	if err != nil {
317		return UserProfilePhotos{}, err
318	}
319
320	var profilePhotos UserProfilePhotos
321	json.Unmarshal(resp.Result, &profilePhotos)
322
323	bot.debugLog("GetUserProfilePhoto", v, profilePhotos)
324
325	return profilePhotos, nil
326}
327
328// GetFile returns a File which can download a file from Telegram.
329//
330// Requires FileID.
331func (bot *BotAPI) GetFile(config FileConfig) (File, error) {
332	v := url.Values{}
333	v.Add("file_id", config.FileID)
334
335	resp, err := bot.MakeRequest("getFile", v)
336	if err != nil {
337		return File{}, err
338	}
339
340	var file File
341	json.Unmarshal(resp.Result, &file)
342
343	bot.debugLog("GetFile", v, file)
344
345	return file, nil
346}
347
348// GetUpdates fetches updates.
349// If a WebHook is set, this will not return any data!
350//
351// Offset, Limit, and Timeout are optional.
352// To avoid stale items, set Offset to one higher than the previous item.
353// Set Timeout to a large number to reduce requests so you can get updates
354// instantly instead of having to wait between requests.
355func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error) {
356	v := url.Values{}
357	if config.Offset != 0 {
358		v.Add("offset", strconv.Itoa(config.Offset))
359	}
360	if config.Limit > 0 {
361		v.Add("limit", strconv.Itoa(config.Limit))
362	}
363	if config.Timeout > 0 {
364		v.Add("timeout", strconv.Itoa(config.Timeout))
365	}
366
367	resp, err := bot.MakeRequest("getUpdates", v)
368	if err != nil {
369		return []Update{}, err
370	}
371
372	var updates []Update
373	json.Unmarshal(resp.Result, &updates)
374
375	bot.debugLog("getUpdates", v, updates)
376
377	return updates, nil
378}
379
380// SetWebhook sets a webhook.
381//
382// If this is set, GetUpdates will not get any data!
383//
384// If you do not have a legitimate TLS certificate, you need to include
385// your self signed certificate with the config.
386func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
387	if config.Certificate == nil {
388		v := url.Values{}
389		v.Add("url", config.URL.String())
390		if config.MaxConnections != 0 {
391			v.Add("max_connections", strconv.Itoa(config.MaxConnections))
392		}
393
394		return bot.MakeRequest("setWebhook", v)
395	}
396
397	params := make(map[string]string)
398	params["url"] = config.URL.String()
399	if config.MaxConnections != 0 {
400		params["max_connections"] = strconv.Itoa(config.MaxConnections)
401	}
402
403	resp, err := bot.UploadFile("setWebhook", params, "certificate", config.Certificate)
404	if err != nil {
405		return APIResponse{}, err
406	}
407
408	return resp, nil
409}
410
411// GetWebhookInfo allows you to fetch information about a webhook and if
412// one currently is set, along with pending update count and error messages.
413func (bot *BotAPI) GetWebhookInfo() (WebhookInfo, error) {
414	resp, err := bot.MakeRequest("getWebhookInfo", url.Values{})
415	if err != nil {
416		return WebhookInfo{}, err
417	}
418
419	var info WebhookInfo
420	err = json.Unmarshal(resp.Result, &info)
421
422	return info, err
423}
424
425// GetUpdatesChan starts and returns a channel for getting updates.
426func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) {
427	ch := make(chan Update, bot.Buffer)
428
429	go func() {
430		for {
431			updates, err := bot.GetUpdates(config)
432			if err != nil {
433				log.Println(err)
434				log.Println("Failed to get updates, retrying in 3 seconds...")
435				time.Sleep(time.Second * 3)
436
437				continue
438			}
439
440			for _, update := range updates {
441				if update.UpdateID >= config.Offset {
442					config.Offset = update.UpdateID + 1
443					ch <- update
444				}
445			}
446		}
447	}()
448
449	return ch, nil
450}
451
452// ListenForWebhook registers a http handler for a webhook.
453func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
454	ch := make(chan Update, bot.Buffer)
455
456	http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
457		bytes, _ := ioutil.ReadAll(r.Body)
458
459		var update Update
460		json.Unmarshal(bytes, &update)
461
462		ch <- update
463	})
464
465	return ch
466}
467
468// AnswerInlineQuery sends a response to an inline query.
469//
470// Note that you must respond to an inline query within 30 seconds.
471func (bot *BotAPI) AnswerInlineQuery(config InlineConfig) (APIResponse, error) {
472	v := url.Values{}
473
474	v.Add("inline_query_id", config.InlineQueryID)
475	v.Add("cache_time", strconv.Itoa(config.CacheTime))
476	v.Add("is_personal", strconv.FormatBool(config.IsPersonal))
477	v.Add("next_offset", config.NextOffset)
478	data, err := json.Marshal(config.Results)
479	if err != nil {
480		return APIResponse{}, err
481	}
482	v.Add("results", string(data))
483	v.Add("switch_pm_text", config.SwitchPMText)
484	v.Add("switch_pm_parameter", config.SwitchPMParameter)
485
486	bot.debugLog("answerInlineQuery", v, nil)
487
488	return bot.MakeRequest("answerInlineQuery", v)
489}
490
491// AnswerCallbackQuery sends a response to an inline query callback.
492func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, error) {
493	v := url.Values{}
494
495	v.Add("callback_query_id", config.CallbackQueryID)
496	if config.Text != "" {
497		v.Add("text", config.Text)
498	}
499	v.Add("show_alert", strconv.FormatBool(config.ShowAlert))
500	if config.URL != "" {
501		v.Add("url", config.URL)
502	}
503	v.Add("cache_time", strconv.Itoa(config.CacheTime))
504
505	bot.debugLog("answerCallbackQuery", v, nil)
506
507	return bot.MakeRequest("answerCallbackQuery", v)
508}
509
510// KickChatMember kicks a user from a chat. Note that this only will work
511// in supergroups, and requires the bot to be an admin. Also note they
512// will be unable to rejoin until they are unbanned.
513func (bot *BotAPI) KickChatMember(config KickChatMemberConfig) (APIResponse, error) {
514	v := url.Values{}
515
516	if config.SuperGroupUsername == "" {
517		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
518	} else {
519		v.Add("chat_id", config.SuperGroupUsername)
520	}
521	v.Add("user_id", strconv.Itoa(config.UserID))
522
523	if config.UntilDate != 0 {
524		v.Add("until_date", strconv.FormatInt(config.UntilDate, 10))
525	}
526
527	bot.debugLog("kickChatMember", v, nil)
528
529	return bot.MakeRequest("kickChatMember", v)
530}
531
532// LeaveChat makes the bot leave the chat.
533func (bot *BotAPI) LeaveChat(config ChatConfig) (APIResponse, error) {
534	v := url.Values{}
535
536	if config.SuperGroupUsername == "" {
537		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
538	} else {
539		v.Add("chat_id", config.SuperGroupUsername)
540	}
541
542	bot.debugLog("leaveChat", v, nil)
543
544	return bot.MakeRequest("leaveChat", v)
545}
546
547// GetChat gets information about a chat.
548func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) {
549	v := url.Values{}
550
551	if config.SuperGroupUsername == "" {
552		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
553	} else {
554		v.Add("chat_id", config.SuperGroupUsername)
555	}
556
557	resp, err := bot.MakeRequest("getChat", v)
558	if err != nil {
559		return Chat{}, err
560	}
561
562	var chat Chat
563	err = json.Unmarshal(resp.Result, &chat)
564
565	bot.debugLog("getChat", v, chat)
566
567	return chat, err
568}
569
570// GetChatAdministrators gets a list of administrators in the chat.
571//
572// If none have been appointed, only the creator will be returned.
573// Bots are not shown, even if they are an administrator.
574func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error) {
575	v := url.Values{}
576
577	if config.SuperGroupUsername == "" {
578		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
579	} else {
580		v.Add("chat_id", config.SuperGroupUsername)
581	}
582
583	resp, err := bot.MakeRequest("getChatAdministrators", v)
584	if err != nil {
585		return []ChatMember{}, err
586	}
587
588	var members []ChatMember
589	err = json.Unmarshal(resp.Result, &members)
590
591	bot.debugLog("getChatAdministrators", v, members)
592
593	return members, err
594}
595
596// GetChatMembersCount gets the number of users in a chat.
597func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) {
598	v := url.Values{}
599
600	if config.SuperGroupUsername == "" {
601		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
602	} else {
603		v.Add("chat_id", config.SuperGroupUsername)
604	}
605
606	resp, err := bot.MakeRequest("getChatMembersCount", v)
607	if err != nil {
608		return -1, err
609	}
610
611	var count int
612	err = json.Unmarshal(resp.Result, &count)
613
614	bot.debugLog("getChatMembersCount", v, count)
615
616	return count, err
617}
618
619// GetChatMember gets a specific chat member.
620func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error) {
621	v := url.Values{}
622
623	if config.SuperGroupUsername == "" {
624		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
625	} else {
626		v.Add("chat_id", config.SuperGroupUsername)
627	}
628	v.Add("user_id", strconv.Itoa(config.UserID))
629
630	resp, err := bot.MakeRequest("getChatMember", v)
631	if err != nil {
632		return ChatMember{}, err
633	}
634
635	var member ChatMember
636	err = json.Unmarshal(resp.Result, &member)
637
638	bot.debugLog("getChatMember", v, member)
639
640	return member, err
641}
642
643// UnbanChatMember unbans a user from a chat. Note that this only will work
644// in supergroups and channels, and requires the bot to be an admin.
645func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error) {
646	v := url.Values{}
647
648	if config.SuperGroupUsername != "" {
649		v.Add("chat_id", config.SuperGroupUsername)
650	} else if config.ChannelUsername != "" {
651		v.Add("chat_id", config.ChannelUsername)
652	} else {
653		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
654	}
655	v.Add("user_id", strconv.Itoa(config.UserID))
656
657	bot.debugLog("unbanChatMember", v, nil)
658
659	return bot.MakeRequest("unbanChatMember", v)
660}
661
662// RestrictChatMember to restrict a user in a supergroup. The bot must be an
663//administrator in the supergroup for this to work and must have the
664//appropriate admin rights. Pass True for all boolean parameters to lift
665//restrictions from a user. Returns True on success.
666func (bot *BotAPI) RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error) {
667	v := url.Values{}
668
669	if config.SuperGroupUsername != "" {
670		v.Add("chat_id", config.SuperGroupUsername)
671	} else if config.ChannelUsername != "" {
672		v.Add("chat_id", config.ChannelUsername)
673	} else {
674		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
675	}
676	v.Add("user_id", strconv.Itoa(config.UserID))
677
678	if &config.CanSendMessages != nil {
679		v.Add("can_send_messages", strconv.FormatBool(*config.CanSendMessages))
680	}
681	if &config.CanSendMediaMessages != nil {
682		v.Add("can_send_media_messages", strconv.FormatBool(*config.CanSendMediaMessages))
683	}
684	if &config.CanSendOtherMessages != nil {
685		v.Add("can_send_other_messages", strconv.FormatBool(*config.CanSendOtherMessages))
686	}
687	if &config.CanAddWebPagePreviews != nil {
688		v.Add("can_add_web_page_previews", strconv.FormatBool(*config.CanAddWebPagePreviews))
689	}
690	if config.UntilDate != 0 {
691		v.Add("until_date", strconv.FormatInt(config.UntilDate, 10))
692	}
693
694	bot.debugLog("restrictChatMember", v, nil)
695
696	return bot.MakeRequest("restrictChatMember", v)
697}
698
699// PromoteChatMember add admin rights to user
700func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) {
701	v := url.Values{}
702
703	if config.SuperGroupUsername != "" {
704		v.Add("chat_id", config.SuperGroupUsername)
705	} else if config.ChannelUsername != "" {
706		v.Add("chat_id", config.ChannelUsername)
707	} else {
708		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
709	}
710	v.Add("user_id", strconv.Itoa(config.UserID))
711
712	if &config.CanChangeInfo != nil {
713		v.Add("can_change_info", strconv.FormatBool(*config.CanChangeInfo))
714	}
715	if &config.CanPostMessages != nil {
716		v.Add("can_post_messages", strconv.FormatBool(*config.CanPostMessages))
717	}
718	if &config.CanEditMessages != nil {
719		v.Add("can_edit_messages", strconv.FormatBool(*config.CanEditMessages))
720	}
721	if &config.CanDeleteMessages != nil {
722		v.Add("can_delete_messages", strconv.FormatBool(*config.CanDeleteMessages))
723	}
724	if &config.CanInviteUsers != nil {
725		v.Add("can_invite_users", strconv.FormatBool(*config.CanInviteUsers))
726	}
727	if &config.CanRestrictMembers != nil {
728		v.Add("can_restrict_members", strconv.FormatBool(*config.CanRestrictMembers))
729	}
730	if &config.CanPinMessages != nil {
731		v.Add("can_pin_messages", strconv.FormatBool(*config.CanPinMessages))
732	}
733	if &config.CanPromoteMembers != nil {
734		v.Add("can_promote_members", strconv.FormatBool(*config.CanPromoteMembers))
735	}
736
737	bot.debugLog("promoteChatMember", v, nil)
738
739	return bot.MakeRequest("promoteChatMember", v)
740}
741
742// GetGameHighScores allows you to get the high scores for a game.
743func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) {
744	v, _ := config.values()
745
746	resp, err := bot.MakeRequest(config.method(), v)
747	if err != nil {
748		return []GameHighScore{}, err
749	}
750
751	var highScores []GameHighScore
752	err = json.Unmarshal(resp.Result, &highScores)
753
754	return highScores, err
755}
756
757// GetInviteLink get InviteLink for a chat
758func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
759	v := url.Values{}
760
761	if config.SuperGroupUsername == "" {
762		v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
763	} else {
764		v.Add("chat_id", config.SuperGroupUsername)
765	}
766
767	resp, err := bot.MakeRequest("exportChatInviteLink", v)
768	if err != nil {
769		return "", err
770	}
771
772	var inviteLink string
773	err = json.Unmarshal(resp.Result, &inviteLink)
774
775	return inviteLink, err
776}
777
778// GetStickerSet returns a StickerSet.
779func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error) {
780	v, err := config.values()
781	if err != nil {
782		return StickerSet{}, nil
783	}
784
785	resp, err := bot.MakeRequest(config.method(), v)
786	if err != nil {
787		return StickerSet{}, nil
788	}
789
790	var stickers StickerSet
791	err = json.Unmarshal(resp.Result, &stickers)
792
793	return stickers, err
794}