commit
dd5b918046
5
bot.go
5
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.
|
||||
|
|
28
bot_test.go
28
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)
|
||||
|
||||
|
|
27
configs.go
27
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"
|
||||
}
|
||||
|
|
26
helpers.go
26
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",
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue