Raw() method introduced. KeyboardButton -> ReplyButton.

pull/108/head
Ian Byrd 7 years ago
parent 38298d3e9d
commit 4f400f035e
No known key found for this signature in database
GPG Key ID: 598F598CA3B8055F

@ -62,7 +62,7 @@ func (b *Bot) Ban(chat *Chat, member *ChatMember) error {
"until_date": strconv.FormatInt(member.RestrictedUntil, 10),
}
respJSON, err := b.sendCommand("kickChatMember", params)
respJSON, err := b.Raw("kickChatMember", params)
if err != nil {
return err
}
@ -77,7 +77,7 @@ func (b *Bot) Unban(chat *Chat, user *User) error {
"user_id": user.Recipient(),
}
respJSON, err := b.sendCommand("unbanChatMember", params)
respJSON, err := b.Raw("unbanChatMember", params)
if err != nil {
return err
}
@ -104,7 +104,7 @@ func (b *Bot) Restrict(chat *Chat, member *ChatMember) error {
embedRights(params, prv)
respJSON, err := b.sendCommand("restrictChatMember", params)
respJSON, err := b.Raw("restrictChatMember", params)
if err != nil {
return err
}
@ -133,7 +133,7 @@ func (b *Bot) Promote(chat *Chat, member *ChatMember) error {
embedRights(params, prv)
respJSON, err := b.sendCommand("promoteChatMember", params)
respJSON, err := b.Raw("promoteChatMember", params)
if err != nil {
return err
}
@ -152,7 +152,7 @@ func (b *Bot) AdminsOf(chat *Chat) ([]ChatMember, error) {
"chat_id": chat.Recipient(),
}
respJSON, err := b.sendCommand("getChatAdministrators", params)
respJSON, err := b.Raw("getChatAdministrators", params)
if err != nil {
return nil, err
}
@ -181,7 +181,7 @@ func (b *Bot) Len(chat *Chat) (int, error) {
"chat_id": chat.Recipient(),
}
respJSON, err := b.sendCommand("getChatMembersCount", params)
respJSON, err := b.Raw("getChatMembersCount", params)
if err != nil {
return 0, err
}

@ -17,7 +17,8 @@ import (
"github.com/pkg/errors"
)
func (b *Bot) sendCommand(method string, payload interface{}) ([]byte, error) {
// Raw lets you call any method of Bot API manually.
func (b *Bot) Raw(method string, payload interface{}) ([]byte, error) {
url := fmt.Sprintf("https://api.telegram.org/bot%s/%s", b.Token, method)
var buf bytes.Buffer
@ -109,10 +110,10 @@ func (b *Bot) sendObject(f *File, what string, params map[string]string) (*Messa
if f.InCloud() {
params[what] = f.FileID
respJSON, err = b.sendCommand(sendWhat, params)
respJSON, err = b.Raw(sendWhat, params)
} else if f.FileURL != "" {
params[what] = f.FileURL
respJSON, err = b.sendCommand(sendWhat, params)
respJSON, err = b.Raw(sendWhat, params)
} else {
respJSON, err = b.sendFiles(sendWhat,
map[string]string{what: f.FileLocal}, params)
@ -126,7 +127,7 @@ func (b *Bot) sendObject(f *File, what string, params map[string]string) (*Messa
}
func (b *Bot) getMe() (*User, error) {
meJSON, err := b.sendCommand("getMe", nil)
meJSON, err := b.Raw("getMe", nil)
if err != nil {
return nil, err
}
@ -155,7 +156,7 @@ func (b *Bot) getUpdates(offset int, timeout time.Duration) (upd []Update, err e
"offset": strconv.Itoa(offset),
"timeout": strconv.Itoa(int(timeout / time.Second)),
}
updatesJSON, errCommand := b.sendCommand("getUpdates", params)
updatesJSON, errCommand := b.Raw("getUpdates", params)
if errCommand != nil {
err = errCommand
return

@ -551,7 +551,7 @@ func (b *Bot) Forward(to Recipient, what *Message, options ...interface{}) (*Mes
sendOpts := extractOptions(options)
embedSendOptions(params, sendOpts)
respJSON, err := b.sendCommand("forwardMessage", params)
respJSON, err := b.Raw("forwardMessage", params)
if err != nil {
return nil, err
}
@ -596,7 +596,7 @@ func (b *Bot) Edit(message Editable, what interface{}, options ...interface{}) (
sendOpts := extractOptions(options)
embedSendOptions(params, sendOpts)
respJSON, err := b.sendCommand("editMessageText", params)
respJSON, err := b.Raw("editMessageText", params)
if err != nil {
return nil, err
}
@ -620,7 +620,7 @@ func (b *Bot) EditCaption(originalMsg Editable, caption string) (*Message, error
params["message_id"] = strconv.Itoa(messageID)
}
respJSON, err := b.sendCommand("editMessageCaption", params)
respJSON, err := b.Raw("editMessageCaption", params)
if err != nil {
return nil, err
}
@ -647,7 +647,7 @@ func (b *Bot) Delete(message Editable) error {
"message_id": strconv.Itoa(messageID),
}
respJSON, err := b.sendCommand("deleteMessage", params)
respJSON, err := b.Raw("deleteMessage", params)
if err != nil {
return err
}
@ -670,7 +670,7 @@ func (b *Bot) Notify(recipient Recipient, action ChatAction) error {
"action": string(action),
}
respJSON, err := b.sendCommand("sendChatAction", params)
respJSON, err := b.Raw("sendChatAction", params)
if err != nil {
return err
}
@ -682,7 +682,7 @@ func (b *Bot) Notify(recipient Recipient, action ChatAction) error {
// be responded to once, subsequent attempts to respond to the same query
// will result in an error.
func (b *Bot) Answer(query *Query, response *QueryResponse) error {
respJSON, err := b.sendCommand("answerInlineQuery", response)
respJSON, err := b.Raw("answerInlineQuery", response)
if err != nil {
return err
}
@ -696,7 +696,7 @@ func (b *Bot) Answer(query *Query, response *QueryResponse) error {
func (b *Bot) Respond(callback *Callback, response *CallbackResponse) error {
response.CallbackID = callback.ID
respJSON, err := b.sendCommand("answerCallbackQuery", response)
respJSON, err := b.Raw("answerCallbackQuery", response)
if err != nil {
return err
}
@ -714,7 +714,7 @@ func (b *Bot) FileByID(fileID string) (File, error) {
"file_id": fileID,
}
respJSON, err := b.sendCommand("getFile", params)
respJSON, err := b.Raw("getFile", params)
if err != nil {
return File{}, err
}
@ -788,7 +788,7 @@ func (b *Bot) StopLiveLocation(message Editable, options ...interface{}) (*Messa
sendOpts := extractOptions(options)
embedSendOptions(params, sendOpts)
respJSON, err := b.sendCommand("stopMessageLiveLocation", params)
respJSON, err := b.Raw("stopMessageLiveLocation", params)
if err != nil {
return nil, err
}
@ -802,7 +802,7 @@ func (b *Bot) GetInviteLink(chat *Chat) (string, error) {
"chat_id": chat.Recipient(),
}
respJSON, err := b.sendCommand("exportChatInviteLink", params)
respJSON, err := b.Raw("exportChatInviteLink", params)
if err != nil {
return "", err
}
@ -832,7 +832,7 @@ func (b *Bot) SetGroupTitle(chat *Chat, newTitle string) error {
"title": newTitle,
}
respJSON, err := b.sendCommand("setChatTitle", params)
respJSON, err := b.Raw("setChatTitle", params)
if err != nil {
return err
}
@ -847,7 +847,7 @@ func (b *Bot) SetGroupDescription(chat *Chat, description string) error {
"description": description,
}
respJSON, err := b.sendCommand("setChatDescription", params)
respJSON, err := b.Raw("setChatDescription", params)
if err != nil {
return err
}
@ -877,7 +877,7 @@ func (b *Bot) SetGroupStickerSet(chat *Chat, setName string) error {
"sticker_set_name": setName,
}
respJSON, err := b.sendCommand("setChatStickerSet", params)
respJSON, err := b.Raw("setChatStickerSet", params)
if err != nil {
return err
}
@ -891,7 +891,7 @@ func (b *Bot) DeleteGroupPhoto(chat *Chat) error {
"chat_id": chat.Recipient(),
}
respJSON, err := b.sendCommand("deleteGroupPhoto", params)
respJSON, err := b.Raw("deleteGroupPhoto", params)
if err != nil {
return err
}
@ -905,7 +905,7 @@ func (b *Bot) DeleteGroupStickerSet(chat *Chat) error {
"chat_id": chat.Recipient(),
}
respJSON, err := b.sendCommand("deleteChatStickerSet", params)
respJSON, err := b.Raw("deleteChatStickerSet", params)
if err != nil {
return err
}
@ -919,7 +919,7 @@ func (b *Bot) Leave(chat *Chat) error {
"chat_id": chat.Recipient(),
}
respJSON, err := b.sendCommand("leaveChat", params)
respJSON, err := b.Raw("leaveChat", params)
if err != nil {
return err
}
@ -941,7 +941,7 @@ func (b *Bot) Pin(message Editable, options ...interface{}) error {
sendOpts := extractOptions(options)
embedSendOptions(params, sendOpts)
respJSON, err := b.sendCommand("pinChatMessage", params)
respJSON, err := b.Raw("pinChatMessage", params)
if err != nil {
return err
}
@ -957,7 +957,7 @@ func (b *Bot) Unpin(chat *Chat) error {
"chat_id": chat.Recipient(),
}
respJSON, err := b.sendCommand("upinChatMessage", params)
respJSON, err := b.Raw("upinChatMessage", params)
if err != nil {
return err
}
@ -976,7 +976,7 @@ func (b *Bot) ChatByID(id string) (*Chat, error) {
"chat_id": id,
}
respJSON, err := b.sendCommand("getChat", params)
respJSON, err := b.Raw("getChat", params)
if err != nil {
return nil, err
}
@ -1005,7 +1005,7 @@ func (b *Bot) ProfilePhotosOf(user *User) ([]Photo, error) {
"user_id": user.Recipient(),
}
respJSON, err := b.sendCommand("getUserProfilePhotos", params)
respJSON, err := b.Raw("getUserProfilePhotos", params)
if err != nil {
return nil, err
}
@ -1041,7 +1041,7 @@ func (b *Bot) ChatMemberOf(chat *Chat, user *User) (*ChatMember, error) {
"user_id": user.Recipient(),
}
respJSON, err := b.sendCommand("getChatMember", params)
respJSON, err := b.Raw("getChatMember", params)
if err != nil {
return nil, err
}

@ -74,6 +74,6 @@ func (t *InlineButton) CallbackUnique() string {
}
// CallbackUnique returns KeyboardButton.Text.
func (t *KeyboardButton) CallbackUnique() string {
func (t *ReplyButton) CallbackUnique() string {
return t.Text
}

@ -58,7 +58,7 @@ type ReplyMarkup struct {
// ReplyKeyboard is a grid, consisting of keyboard buttons.
//
// Note: you don't need to set HideCustomKeyboard field to show custom keyboard.
ReplyKeyboard [][]KeyboardButton `json:"keyboard,omitempty"`
ReplyKeyboard [][]ReplyButton `json:"keyboard,omitempty"`
// ForceReply forces Telegram clients to display
// a reply interface to the user (act as if the user
@ -87,12 +87,12 @@ type ReplyMarkup struct {
Selective bool `json:"selective,omitempty"`
}
// KeyboardButton represents a button displayed in reply-keyboard.
// ReplyButton represents a button displayed in reply-keyboard.
//
// Set either Contact or Location to true in order to request
// sensitive info, such as user's phone number or current location.
// (Available in private chats only.)
type KeyboardButton struct {
type ReplyButton struct {
Text string `json:"text"`
Contact bool `json:"request_contact,omitempty"`

@ -159,7 +159,7 @@ func (x *Location) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error
}
embedSendOptions(params, opt)
respJSON, err := b.sendCommand("sendLocation", params)
respJSON, err := b.Raw("sendLocation", params)
if err != nil {
return nil, err
}
@ -179,7 +179,7 @@ func (v *Venue) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
}
embedSendOptions(params, opt)
respJSON, err := b.sendCommand("sendVenue", params)
respJSON, err := b.Raw("sendVenue", params)
if err != nil {
return nil, err
}

@ -31,7 +31,7 @@ func (b *Bot) sendText(to Recipient, text string, opt *SendOptions) (*Message, e
}
embedSendOptions(params, opt)
respJSON, err := b.sendCommand("sendMessage", params)
respJSON, err := b.Raw("sendMessage", params)
if err != nil {
return nil, err
}

Loading…
Cancel
Save