diff --git a/bot.go b/bot.go index a7647d6..c112ab4 100644 --- a/bot.go +++ b/bot.go @@ -75,8 +75,9 @@ func NewBotAPIWithClient(token, apiEndpoint string, client HttpClient) (*BotAPI, return bot, nil } -func (b *BotAPI) SetAPIEndpoint(apiEndpoint string) { - b.apiEndpoint = apiEndpoint +// SetAPIEndpoint add telegram apiEndpont to Bot +func (bot *BotAPI) SetAPIEndpoint(apiEndpoint string) { + bot.apiEndpoint = apiEndpoint } // MakeRequest makes a request to a specific endpoint with our token. diff --git a/bot_test.go b/bot_test.go index 2e9d07a..0c98ee9 100644 --- a/bot_test.go +++ b/bot_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/go-telegram-bot-api/telegram-bot-api" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" ) const ( @@ -402,6 +402,32 @@ func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) { } } +func TestSendWithDice(t *testing.T) { + bot, _ := getBot(t) + + msg := tgbotapi.NewDice(ChatID) + _, err := bot.Send(msg) + + if err != nil { + t.Error(err) + t.Fail() + } + +} + +func TestSendWithDiceWithEmoji(t *testing.T) { + bot, _ := getBot(t) + + msg := tgbotapi.NewDiceWithEmoji(ChatID, "🏀") + _, err := bot.Send(msg) + + if err != nil { + t.Error(err) + t.Fail() + } + +} + func TestGetFile(t *testing.T) { bot, _ := getBot(t) diff --git a/configs.go b/configs.go index 0265ada..3989774 100644 --- a/configs.go +++ b/configs.go @@ -1284,3 +1284,30 @@ func (config GetStickerSetConfig) values() (url.Values, error) { v.Add("name", config.Name) return v, nil } + +// DiceConfig contains information about a sendDice request. +type DiceConfig struct { + BaseChat + // Emoji on which the dice throw animation is based. + // Currently, must be one of “🎲”, “🎯”, or “🏀”. + // Dice can have values 1-6 for “🎲” and “🎯”, and values 1-5 for “🏀”. + // Defaults to “🎲” + Emoji string +} + +// values returns a url.Values representation of DiceConfig. +func (config DiceConfig) values() (url.Values, error) { + v, err := config.BaseChat.values() + if err != nil { + return v, err + } + if config.Emoji != "" { + v.Add("emoji", config.Emoji) + } + return v, nil +} + +// method returns Telegram API method name for sending Dice. +func (config DiceConfig) method() string { + return "sendDice" +} diff --git a/helpers.go b/helpers.go index fe54443..512b453 100644 --- a/helpers.go +++ b/helpers.go @@ -18,6 +18,30 @@ func NewMessage(chatID int64, text string) MessageConfig { } } +// NewDice creates a new DiceConfig. +// +// chatID is where to send it +func NewDice(chatID int64) DiceConfig { + return DiceConfig{ + BaseChat: BaseChat{ + ChatID: chatID, + }, + } +} + +// NewDiceWithEmoji creates a new DiceConfig. +// +// chatID is where to send it +// emoji is type of the Dice +func NewDiceWithEmoji(chatID int64, emoji string) DiceConfig { + return DiceConfig{ + BaseChat: BaseChat{ + ChatID: chatID, + }, + Emoji: emoji, + } +} + // NewDeleteMessage creates a request to delete a message. func NewDeleteMessage(chatID int64, messageID int) DeleteMessageConfig { return DeleteMessageConfig{ @@ -491,7 +515,7 @@ func NewInlineQueryResultMPEG4GIF(id, url string) InlineQueryResultMPEG4GIF { } } -// NewInlineQueryResultCachedPhoto create a new inline query with cached photo. +// NewInlineQueryResultCachedMPEG4GIF create a new inline query with cached MPEG4 GIF. func NewInlineQueryResultCachedMPEG4GIF(id, MPEG4GifID string) InlineQueryResultCachedMpeg4Gif { return InlineQueryResultCachedMpeg4Gif{ Type: "mpeg4_gif", diff --git a/helpers_test.go b/helpers_test.go index 9542f02..ec15a4e 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -1,8 +1,9 @@ package tgbotapi_test import ( - "github.com/go-telegram-bot-api/telegram-bot-api" "testing" + + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" ) func TestNewInlineQueryResultArticle(t *testing.T) { @@ -175,3 +176,21 @@ func TestNewEditMessageReplyMarkup(t *testing.T) { } } + +func TestNewDice(t *testing.T) { + dice := tgbotapi.NewDice(42) + + if dice.ChatID != 42 || + dice.Emoji != "" { + t.Fail() + } +} + +func TestNewDiceWithEmoji(t *testing.T) { + dice := tgbotapi.NewDiceWithEmoji(42, "🏀") + + if dice.ChatID != 42 || + dice.Emoji != "🏀" { + t.Fail() + } +} diff --git a/types.go b/types.go index 6e295ca..f2ad140 100644 --- a/types.go +++ b/types.go @@ -352,6 +352,7 @@ type Sticker struct { IsAnimated bool `json:"is_animated"` // optional } +// StickerSet contains information about an sticker set. type StickerSet struct { Name string `json:"name"` Title string `json:"title"`