diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-08-09 02:16:08 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-08-09 02:16:08 +0300 |
commit | 188740f248bf26934aa8db832f5c9c9b9418b2fc (patch) | |
tree | 89f2c9f5ab9ba267862d16b9d0dc048b00f06fea | |
parent | 94c96cef29cd83bc60b2eabb8bb89c9fd8c7059b (diff) |
0.1.8 Release -- small fixes
-rw-r--r-- | api.go | 7 | ||||
-rw-r--r-- | bots.go | 6 | ||||
-rw-r--r-- | chats.go | 13 | ||||
-rw-r--r-- | client.go | 4 | ||||
-rw-r--r-- | keyboard.go | 13 | ||||
-rw-r--r-- | messages.go | 10 | ||||
-rw-r--r-- | models.go | 4 | ||||
-rw-r--r-- | subscriptions.go | 8 | ||||
-rw-r--r-- | uploads.go | 6 |
9 files changed, 53 insertions, 18 deletions
@@ -1,5 +1,5 @@ -// Package tamtam implements TamTam Bot API -// Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> +//Package tamtam implements TamTam Bot API +//Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> package tamtam import ( @@ -13,6 +13,7 @@ import ( "time" ) +//Api implements main part of TamTam API type Api struct { Bots *bots Chats *chats @@ -194,10 +195,12 @@ func (a *Api) UpdatesLoop(ctx context.Context) error { } } +//GetUpdates returns updates channel func (a *Api) GetUpdates() chan UpdateInterface { return a.updates } +//GetHandler returns http handler for webhooks func (a *Api) GetHandler(updates chan interface{}) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { defer func() { @@ -1,5 +1,5 @@ -// Package tamtam implements TamTam Bot API -// Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> +//Package tamtam implements TamTam Bot API +//Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> package tamtam import ( @@ -17,6 +17,7 @@ func newBots(client *client) *bots { return &bots{client: client} } +//GetBot returns info about current bot. Current bot can be identified by access token. Method returns bot identifier, name and avatar (if any) func (a *bots) GetBot() (*BotInfo, error) { result := new(BotInfo) values := url.Values{} @@ -32,6 +33,7 @@ func (a *bots) GetBot() (*BotInfo, error) { return result, json.NewDecoder(body).Decode(result) } +//PatchBot edits current bot info. Fill only the fields you want to update. All remaining fields will stay untouched func (a *bots) PatchBot(patch *BotPatch) (*BotInfo, error) { result := new(BotInfo) values := url.Values{} @@ -1,5 +1,5 @@ -// Package tamtam implements TamTam Bot API -// Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> +//Package tamtam implements TamTam Bot API +//Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> package tamtam import ( @@ -19,6 +19,7 @@ func newChats(client *client) *chats { return &chats{client: client} } +//GetChats returns information about chats that bot participated in: a result list and marker points to the next page func (a *chats) GetChats(count, marker int) (*ChatList, error) { result := new(ChatList) values := url.Values{} @@ -40,6 +41,7 @@ func (a *chats) GetChats(count, marker int) (*ChatList, error) { return result, json.NewDecoder(body).Decode(result) } +//GetChat returns info about chat func (a *chats) GetChat(chatID int) (*Chat, error) { result := new(Chat) values := url.Values{} @@ -55,6 +57,7 @@ func (a *chats) GetChat(chatID int) (*Chat, error) { return result, json.NewDecoder(body).Decode(result) } +//GetChatMembership returns chat membership info for current bot func (a *chats) GetChatMembership(chatID int) (*ChatMember, error) { result := new(ChatMember) values := url.Values{} @@ -70,6 +73,7 @@ func (a *chats) GetChatMembership(chatID int) (*ChatMember, error) { return result, json.NewDecoder(body).Decode(result) } +//GetChatMembers returns users participated in chat func (a *chats) GetChatMembers(chatID, count, marker int) (*ChatMembersList, error) { result := new(ChatMembersList) values := url.Values{} @@ -91,6 +95,7 @@ func (a *chats) GetChatMembers(chatID, count, marker int) (*ChatMembersList, err return result, json.NewDecoder(body).Decode(result) } +//LeaveChat removes bot from chat members func (a *chats) LeaveChat(chatID int) (*SimpleQueryResult, error) { result := new(SimpleQueryResult) values := url.Values{} @@ -106,6 +111,7 @@ func (a *chats) LeaveChat(chatID int) (*SimpleQueryResult, error) { return result, json.NewDecoder(body).Decode(result) } +//EditChat edits chat info: title, icon, etc… func (a *chats) EditChat(chatID int, update *ChatPatch) (*Chat, error) { result := new(Chat) values := url.Values{} @@ -121,6 +127,7 @@ func (a *chats) EditChat(chatID int, update *ChatPatch) (*Chat, error) { return result, json.NewDecoder(body).Decode(result) } +//AddMember adds members to chat. Additional permissions may require. func (a *chats) AddMember(chatID int, users UserIdsList) (*SimpleQueryResult, error) { result := new(SimpleQueryResult) values := url.Values{} @@ -136,6 +143,7 @@ func (a *chats) AddMember(chatID int, users UserIdsList) (*SimpleQueryResult, er return result, json.NewDecoder(body).Decode(result) } +//RemoveMember removes member from chat. Additional permissions may require. func (a *chats) RemoveMember(chatID int, userID int) (*SimpleQueryResult, error) { result := new(SimpleQueryResult) values := url.Values{} @@ -152,6 +160,7 @@ func (a *chats) RemoveMember(chatID int, userID int) (*SimpleQueryResult, error) return result, json.NewDecoder(body).Decode(result) } +//SendAction send bot action to chat func (a *chats) SendAction(chatID int, action SenderAction) (*SimpleQueryResult, error) { result := new(SimpleQueryResult) values := url.Values{} @@ -1,5 +1,5 @@ -// Package tamtam implements TamTam Bot API -// Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> +//Package tamtam implements TamTam Bot API +//Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> package tamtam import ( diff --git a/keyboard.go b/keyboard.go index 7d79042..094f8f1 100644 --- a/keyboard.go +++ b/keyboard.go @@ -1,17 +1,20 @@ -// Package tamtam implements TamTam Bot API -// Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> +//Package tamtam implements TamTam Bot API +//Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> package tamtam +//KeyboardBuilder implements builder for inline keyboard type KeyboardBuilder struct { rows []*KeyboardRow } +//AddRow adds row to inline keyboard func (k *KeyboardBuilder) AddRow() *KeyboardRow { kr := &KeyboardRow{} k.rows = append(k.rows, kr) return kr } +//Build returns result keyboard func (k *KeyboardBuilder) Build() Keyboard { buttons := make([][]ButtonInterface, 0, len(k.rows)) for _, r := range k.rows { @@ -20,14 +23,17 @@ func (k *KeyboardBuilder) Build() Keyboard { return Keyboard{Buttons: buttons} } +//KeyboardRow represents buttons row type KeyboardRow struct { cols []ButtonInterface } +//Build returns result keyboard row func (k *KeyboardRow) Build() []ButtonInterface { return k.cols } +//AddLink button func (k *KeyboardRow) AddLink(text string, intent Intent, url string) *KeyboardRow { b := LinkButton{ Url: url, @@ -40,6 +46,7 @@ func (k *KeyboardRow) AddLink(text string, intent Intent, url string) *KeyboardR return k } +//AddCallback button func (k *KeyboardRow) AddCallback(text string, intent Intent, payload string) *KeyboardRow { b := CallbackButton{ Payload: payload, @@ -53,6 +60,7 @@ func (k *KeyboardRow) AddCallback(text string, intent Intent, payload string) *K return k } +//AddContact button func (k *KeyboardRow) AddContact(text string) *KeyboardRow { b := RequestContactButton{ Button: Button{ @@ -64,6 +72,7 @@ func (k *KeyboardRow) AddContact(text string) *KeyboardRow { return k } +//AddGeolocation button func (k *KeyboardRow) AddGeolocation(text string, quick bool) *KeyboardRow { b := RequestGeoLocationButton{ Quick: quick, diff --git a/messages.go b/messages.go index c7cad45..66db7da 100644 --- a/messages.go +++ b/messages.go @@ -1,5 +1,5 @@ -// Package tamtam implements TamTam Bot API -// Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> +//Package tamtam implements TamTam Bot API +//Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> package tamtam import ( @@ -18,6 +18,7 @@ func newMessages(client *client) *messages { return &messages{client: client} } +//GetMessages returns messages in chat: result page and marker referencing to the next page. Messages traversed in reverse direction so the latest message in chat will be first in result array. Therefore if you use from and to parameters, to must be less than from func (a *messages) GetMessages(chatID int, messageIDs []string, from int, to int, count int) (*MessageList, error) { result := new(MessageList) values := url.Values{} @@ -50,6 +51,7 @@ func (a *messages) GetMessages(chatID int, messageIDs []string, from int, to int return result, json.NewDecoder(body).Decode(result) } +//SendMessage sends a message to a chat. As a result for this method new message identifier returns. func (a *messages) SendMessage(chatID int, userID int, message *NewMessageBody) (*Message, error) { result := new(Message) values := url.Values{} @@ -71,6 +73,7 @@ func (a *messages) SendMessage(chatID int, userID int, message *NewMessageBody) return result, json.NewDecoder(body).Decode(result) } +//EditMessage updates message by id func (a *messages) EditMessage(messageID int, message *NewMessageBody) (*SimpleQueryResult, error) { result := new(SimpleQueryResult) values := url.Values{} @@ -87,6 +90,7 @@ func (a *messages) EditMessage(messageID int, message *NewMessageBody) (*SimpleQ return result, json.NewDecoder(body).Decode(result) } +//DeleteMessage deletes message by id func (a *messages) DeleteMessage(messageID int) (*SimpleQueryResult, error) { result := new(SimpleQueryResult) values := url.Values{} @@ -103,6 +107,7 @@ func (a *messages) DeleteMessage(messageID int) (*SimpleQueryResult, error) { return result, json.NewDecoder(body).Decode(result) } +//AnswerOnCallback should be called to send an answer after a user has clicked the button. The answer may be an updated message or/and a one-time user notification. func (a *messages) AnswerOnCallback(callbackID int, callback *CallbackAnswer) (*SimpleQueryResult, error) { result := new(SimpleQueryResult) values := url.Values{} @@ -119,6 +124,7 @@ func (a *messages) AnswerOnCallback(callbackID int, callback *CallbackAnswer) (* return result, json.NewDecoder(body).Decode(result) } +//NewKeyboardBuilder returns new keyboard builder helper func (a *messages) NewKeyboardBuilder() *KeyboardBuilder { return &KeyboardBuilder{ rows: make([]*KeyboardRow, 0), @@ -1,5 +1,5 @@ -// Package tamtam implements TamTam Bot API -// Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> +//Package tamtam implements TamTam Bot API +//Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> package tamtam import ( diff --git a/subscriptions.go b/subscriptions.go index d32d985..ec2df80 100644 --- a/subscriptions.go +++ b/subscriptions.go @@ -1,5 +1,5 @@ -// Package tamtam implements TamTam Bot API -// Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> +//Package tamtam implements TamTam Bot API +//Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> package tamtam import ( @@ -16,6 +16,8 @@ type subscriptions struct { func newSubscriptions(client *client) *subscriptions { return &subscriptions{client: client} } + +//GetSubscriptions returns list of all subscriptions func (a *subscriptions) GetSubscriptions() (*GetSubscriptionsResult, error) { result := new(GetSubscriptionsResult) values := url.Values{} @@ -31,6 +33,7 @@ func (a *subscriptions) GetSubscriptions() (*GetSubscriptionsResult, error) { return result, json.NewDecoder(body).Decode(result) } +//Subscribe subscribes bot to receive updates via WebHook func (a *subscriptions) Subscribe(subscribeURL string, updateTypes []string) (*SimpleQueryResult, error) { subscription := &SubscriptionRequestBody{ Url: subscribeURL, @@ -51,6 +54,7 @@ func (a *subscriptions) Subscribe(subscribeURL string, updateTypes []string) (*S return result, json.NewDecoder(body).Decode(result) } +//Unsubscribe unsubscribes bot from receiving updates via WebHook func (a *subscriptions) Unsubscribe(subscriptionURL string) (*SimpleQueryResult, error) { result := new(SimpleQueryResult) values := url.Values{} @@ -1,5 +1,5 @@ -// Package tamtam implements TamTam Bot API -// Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> +//Package tamtam implements TamTam Bot API +//Copyright (c) 2019 Alexander Kiryukhin <a.kiryukhin@mail.ru> package tamtam import ( @@ -21,6 +21,7 @@ func newUploads(client *client) *uploads { return &uploads{client: client} } +//GetUploadURL returns url to upload files func (a *uploads) GetUploadURL(uploadType UploadType) (*UploadEndpoint, error) { result := new(UploadEndpoint) values := url.Values{} @@ -37,6 +38,7 @@ func (a *uploads) GetUploadURL(uploadType UploadType) (*UploadEndpoint, error) { return result, json.NewDecoder(body).Decode(result) } +//UploadMedia uploads file to TamTam server func (a *uploads) UploadMedia(uploadType UploadType, filename string) (*UploadedInfo, error) { bodyBuf := &bytes.Buffer{} bodyWriter := multipart.NewWriter(bodyBuf) |