🔀 Merge branch 'develop'
This commit is contained in:
commit
d956093bb4
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// AnswerCallbackQueryParameters represents data for AnswerCallbackQuery method.
|
||||||
type AnswerCallbackQueryParameters struct {
|
type AnswerCallbackQueryParameters struct {
|
||||||
// Unique identifier for the query to be answered
|
// Unique identifier for the query to be answered
|
||||||
CallbackQueryID string `json:"callback_query_id"`
|
CallbackQueryID string `json:"callback_query_id"`
|
||||||
|
@ -29,6 +30,8 @@ type AnswerCallbackQueryParameters struct {
|
||||||
CacheTime int `json:"cache_time,omitempty"`
|
CacheTime int `json:"cache_time,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAnswerCallbackQuery creates AnswerCallbackQueryParameters only with
|
||||||
|
// required parameters.
|
||||||
func NewAnswerCallbackQuery(callbackQueryID string) *AnswerCallbackQueryParameters {
|
func NewAnswerCallbackQuery(callbackQueryID string) *AnswerCallbackQueryParameters {
|
||||||
return &AnswerCallbackQueryParameters{CallbackQueryID: callbackQueryID}
|
return &AnswerCallbackQueryParameters{CallbackQueryID: callbackQueryID}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// AnswerInlineQueryParameters represents data for AnswerInlineQuery method.
|
||||||
type AnswerInlineQueryParameters struct {
|
type AnswerInlineQueryParameters struct {
|
||||||
// Unique identifier for the answered query
|
// Unique identifier for the answered query
|
||||||
InlineQueryID string `json:"inline_query_id"`
|
InlineQueryID string `json:"inline_query_id"`
|
||||||
|
@ -35,6 +36,8 @@ type AnswerInlineQueryParameters struct {
|
||||||
IsPersonal bool `json:"is_personal,omitempty"`
|
IsPersonal bool `json:"is_personal,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAnswerInlineQuery creates AnswerInlineQueryParameters only with required
|
||||||
|
// parameters.
|
||||||
func NewAnswerInlineQuery(inlineQueryID string, results ...interface{}) *AnswerInlineQueryParameters {
|
func NewAnswerInlineQuery(inlineQueryID string, results ...interface{}) *AnswerInlineQueryParameters {
|
||||||
return &AnswerInlineQueryParameters{
|
return &AnswerInlineQueryParameters{
|
||||||
InlineQueryID: inlineQueryID,
|
InlineQueryID: inlineQueryID,
|
||||||
|
|
|
@ -2,6 +2,8 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// AnswerPreCheckoutQueryParameters represents data for AnswerPreCheckoutQuery
|
||||||
|
// method.
|
||||||
type AnswerPreCheckoutQueryParameters struct {
|
type AnswerPreCheckoutQueryParameters struct {
|
||||||
// Unique identifier for the query to be answered
|
// Unique identifier for the query to be answered
|
||||||
PreCheckoutQueryID string `json:"pre_checkout_query_id"`
|
PreCheckoutQueryID string `json:"pre_checkout_query_id"`
|
||||||
|
@ -19,6 +21,8 @@ type AnswerPreCheckoutQueryParameters struct {
|
||||||
Ok bool `json:"ok"`
|
Ok bool `json:"ok"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAnswerPreCheckoutQuery creates AnswerPreCheckoutQueryParameters only with
|
||||||
|
// required parameters.
|
||||||
func NewAnswerPreCheckoutQuery(preCheckoutQueryID string, ok bool) *AnswerPreCheckoutQueryParameters {
|
func NewAnswerPreCheckoutQuery(preCheckoutQueryID string, ok bool) *AnswerPreCheckoutQueryParameters {
|
||||||
return &AnswerPreCheckoutQueryParameters{
|
return &AnswerPreCheckoutQueryParameters{
|
||||||
PreCheckoutQueryID: preCheckoutQueryID,
|
PreCheckoutQueryID: preCheckoutQueryID,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// AnswerShippingQueryParameters represents data for AnswerShippingQuery method.
|
||||||
type AnswerShippingQueryParameters struct {
|
type AnswerShippingQueryParameters struct {
|
||||||
// Unique identifier for the query to be answered
|
// Unique identifier for the query to be answered
|
||||||
ShippingQueryID string `json:"shipping_query_id"`
|
ShippingQueryID string `json:"shipping_query_id"`
|
||||||
|
@ -22,6 +23,8 @@ type AnswerShippingQueryParameters struct {
|
||||||
ShippingOptions []ShippingOption `json:"shipping_options,omitempty"`
|
ShippingOptions []ShippingOption `json:"shipping_options,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAnswerShippingQuery creates AnswerShippingQueryParameters only with
|
||||||
|
// required parameters.
|
||||||
func NewAnswerShippingQuery(shippingQueryID string, ok bool) *AnswerShippingQueryParameters {
|
func NewAnswerShippingQuery(shippingQueryID string, ok bool) *AnswerShippingQueryParameters {
|
||||||
return &AnswerShippingQueryParameters{
|
return &AnswerShippingQueryParameters{
|
||||||
ShippingQueryID: shippingQueryID,
|
ShippingQueryID: shippingQueryID,
|
||||||
|
|
13
constants.go
13
constants.go
|
@ -1,5 +1,9 @@
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
|
// Version represents current version of Telegram API supported by this package
|
||||||
|
const Version = 3.6
|
||||||
|
|
||||||
|
// Action... represents available and supported status actions of bot
|
||||||
const (
|
const (
|
||||||
ActionFindLocation = "find_location"
|
ActionFindLocation = "find_location"
|
||||||
ActionRecordAudio = "record_audio"
|
ActionRecordAudio = "record_audio"
|
||||||
|
@ -13,6 +17,7 @@ const (
|
||||||
ActionUploadVideoNote = "upload_video_note"
|
ActionUploadVideoNote = "upload_video_note"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Chat... represents available and supported chat types
|
||||||
const (
|
const (
|
||||||
ChatChannel = "channel"
|
ChatChannel = "channel"
|
||||||
ChatGroup = "group"
|
ChatGroup = "group"
|
||||||
|
@ -20,6 +25,7 @@ const (
|
||||||
ChatSuperGroup = "supergroup"
|
ChatSuperGroup = "supergroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Entity... represents available and supported entity types
|
||||||
const (
|
const (
|
||||||
EntityBold = "bold"
|
EntityBold = "bold"
|
||||||
EntityBotCommand = "bot_command"
|
EntityBotCommand = "bot_command"
|
||||||
|
@ -34,6 +40,7 @@ const (
|
||||||
EntityURL = "url"
|
EntityURL = "url"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Method... represents available and supported Telegram API methods
|
||||||
const (
|
const (
|
||||||
MethodAddStickerToSet = "addStickerToSet"
|
MethodAddStickerToSet = "addStickerToSet"
|
||||||
MethodAnswerCallbackQuery = "answerCallbackQuery"
|
MethodAnswerCallbackQuery = "answerCallbackQuery"
|
||||||
|
@ -96,11 +103,13 @@ const (
|
||||||
MethodUploadStickerFile = "uploadStickerFile"
|
MethodUploadStickerFile = "uploadStickerFile"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Mode... represents available and supported parsing modes of messages
|
||||||
const (
|
const (
|
||||||
ModeHTML = "html"
|
ModeHTML = "html"
|
||||||
ModeMarkdown = "markdown"
|
ModeMarkdown = "markdown"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Mime... represents available and supported MIME types of data
|
||||||
const (
|
const (
|
||||||
MimeHTML = "text/html"
|
MimeHTML = "text/html"
|
||||||
MimeMP4 = "video/mp4"
|
MimeMP4 = "video/mp4"
|
||||||
|
@ -108,11 +117,13 @@ const (
|
||||||
MimeZIP = "application/zip"
|
MimeZIP = "application/zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Scheme... represents optional schemes for URLs
|
||||||
const (
|
const (
|
||||||
SchemeAttach = "attach"
|
SchemeAttach = "attach"
|
||||||
SchemeTelegram = "tg"
|
SchemeTelegram = "tg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Status... represents available and supported statuses of ID
|
||||||
const (
|
const (
|
||||||
StatusAdministrator = "administrator"
|
StatusAdministrator = "administrator"
|
||||||
StatusCreator = "creator"
|
StatusCreator = "creator"
|
||||||
|
@ -122,6 +133,7 @@ const (
|
||||||
StatusRestricted = "restricted"
|
StatusRestricted = "restricted"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Type... represents available and supported types of data
|
||||||
const (
|
const (
|
||||||
TypeArticle = "article"
|
TypeArticle = "article"
|
||||||
TypeAudio = "audio"
|
TypeAudio = "audio"
|
||||||
|
@ -138,6 +150,7 @@ const (
|
||||||
TypeVoice = "voice"
|
TypeVoice = "voice"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Update... represents available and supported types of updates
|
||||||
const (
|
const (
|
||||||
UpdateCallbackQuery = "callback_query"
|
UpdateCallbackQuery = "callback_query"
|
||||||
UpdateChannelPost = "channel_post"
|
UpdateChannelPost = "channel_post"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// DeleteChatPhotoParameters represents data for DeleteChatPhoto method.
|
||||||
type DeleteChatPhotoParameters struct {
|
type DeleteChatPhotoParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// DeleteChatStickerSetParameters represents data for DeleteChatStickerSet method.
|
||||||
type DeleteChatStickerSetParameters struct {
|
type DeleteChatStickerSetParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// DeleteMessageParameters represents data for DeleteMessage method.
|
||||||
type DeleteMessageParameters struct {
|
type DeleteMessageParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// DeleteStickerFromSetParameters represents data for DeleteStickerFromSet method.
|
||||||
type DeleteStickerFromSetParameters struct {
|
type DeleteStickerFromSetParameters struct {
|
||||||
Sticker string `json:"sticker"`
|
Sticker string `json:"sticker"`
|
||||||
}
|
}
|
||||||
|
|
2
doc.go
2
doc.go
|
@ -1,2 +1,2 @@
|
||||||
// Version of the bot API: 3.6 (February 13, 2018)
|
// Package telegram contains bindings for the Telegram API
|
||||||
package telegram
|
package telegram
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// EditMessageCaptionParameters represents data for EditMessageCaption method.
|
||||||
type EditMessageCaptionParameters struct {
|
type EditMessageCaptionParameters struct {
|
||||||
// Required if inline_message_id is not specified. Unique identifier for the
|
// Required if inline_message_id is not specified. Unique identifier for the
|
||||||
// target chat or username of the target channel (in the format
|
// target chat or username of the target channel (in the format
|
||||||
|
|
|
@ -2,6 +2,8 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// EditMessageLiveLocationParameters represents data for EditMessageLiveLocation
|
||||||
|
// method.
|
||||||
type EditMessageLiveLocationParameters struct {
|
type EditMessageLiveLocationParameters struct {
|
||||||
// Required if inline_message_id is not specified. Unique identifier for the
|
// Required if inline_message_id is not specified. Unique identifier for the
|
||||||
// target chat or username of the target channel (in the format
|
// target chat or username of the target channel (in the format
|
||||||
|
@ -26,6 +28,8 @@ type EditMessageLiveLocationParameters struct {
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewLiveLocation creates EditMessageLiveLocationParameters only with required
|
||||||
|
// parameters.
|
||||||
func NewLiveLocation(latitude, longitude float32) *EditMessageLiveLocationParameters {
|
func NewLiveLocation(latitude, longitude float32) *EditMessageLiveLocationParameters {
|
||||||
return &EditMessageLiveLocationParameters{
|
return &EditMessageLiveLocationParameters{
|
||||||
Latitude: latitude,
|
Latitude: latitude,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// EditMessageReplyMarkupParameters represents data for EditMessageReplyMarkup method.
|
||||||
type EditMessageReplyMarkupParameters struct {
|
type EditMessageReplyMarkupParameters struct {
|
||||||
// Required if inline_message_id is not specified. Unique identifier for the
|
// Required if inline_message_id is not specified. Unique identifier for the
|
||||||
// target chat or username of the target channel (in the format
|
// target chat or username of the target channel (in the format
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// EditMessageTextParameters represents data for EditMessageText method.
|
||||||
type EditMessageTextParameters struct {
|
type EditMessageTextParameters struct {
|
||||||
// Required if inline_message_id is not specified. Unique identifier for the
|
// Required if inline_message_id is not specified. Unique identifier for the
|
||||||
// target chat or username of the target channel (in the format
|
// target chat or username of the target channel (in the format
|
||||||
|
@ -30,6 +31,7 @@ type EditMessageTextParameters struct {
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMessageText creates EditMessageTextParameters only with required parameters.
|
||||||
func NewMessageText(text string) *EditMessageTextParameters {
|
func NewMessageText(text string) *EditMessageTextParameters {
|
||||||
return &EditMessageTextParameters{
|
return &EditMessageTextParameters{
|
||||||
Text: text,
|
Text: text,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// ExportChatInviteLinkParameters represents data for ExportChatInviteLink method.
|
||||||
type ExportChatInviteLinkParameters struct {
|
type ExportChatInviteLinkParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// ForwardMessageParameters represents data for ForwardMessage method.
|
||||||
type ForwardMessageParameters struct {
|
type ForwardMessageParameters struct {
|
||||||
// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -16,6 +17,7 @@ type ForwardMessageParameters struct {
|
||||||
MessageID int `json:"message_id"`
|
MessageID int `json:"message_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewForwardMessage creates ForwardMessageParameters only with reqired parameters.
|
||||||
func NewForwardMessage(from, to int64, messageID int) *ForwardMessageParameters {
|
func NewForwardMessage(from, to int64, messageID int) *ForwardMessageParameters {
|
||||||
return &ForwardMessageParameters{
|
return &ForwardMessageParameters{
|
||||||
FromChatID: from,
|
FromChatID: from,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// GetChatParameters represents data for GetChat method.
|
||||||
type GetChatParameters struct {
|
type GetChatParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,8 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// GetChatAdministratorsParameters represents data for GetChatAdministrators
|
||||||
|
// method.
|
||||||
type GetChatAdministratorsParameters struct {
|
type GetChatAdministratorsParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// GetChatMemberParameters represents data for GetChatMember method.
|
||||||
type GetChatMemberParameters struct {
|
type GetChatMemberParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// GetChatMembersCountParameters represents data for GetChatMembersCount method.
|
||||||
type GetChatMembersCountParameters struct {
|
type GetChatMembersCountParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// GetFileParameters represents data for GetFile method.
|
||||||
type GetFileParameters struct {
|
type GetFileParameters struct {
|
||||||
FileID string `json:"file_id"`
|
FileID string `json:"file_id"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// GetGameHighScoresParameters represents data for GetGameHighScores method.
|
||||||
type GetGameHighScoresParameters struct {
|
type GetGameHighScoresParameters struct {
|
||||||
// Target user id
|
// Target user id
|
||||||
UserID int `json:"user_id"`
|
UserID int `json:"user_id"`
|
||||||
|
@ -19,6 +20,7 @@ type GetGameHighScoresParameters struct {
|
||||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewGameHighScores creates GetGameHighScoresParameters only with required parameters.
|
||||||
func NewGameHighScores(userID int) *GetGameHighScoresParameters {
|
func NewGameHighScores(userID int) *GetGameHighScoresParameters {
|
||||||
return &GetGameHighScoresParameters{
|
return &GetGameHighScoresParameters{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// GetStickerSetParameters represents data for GetStickerSet method.
|
||||||
type GetStickerSetParameters struct {
|
type GetStickerSetParameters struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// GetUpdatesParameters represents data for GetUpdates method.
|
||||||
type GetUpdatesParameters struct {
|
type GetUpdatesParameters struct {
|
||||||
// Identifier of the first update to be returned. Must be greater by one than
|
// Identifier of the first update to be returned. Must be greater by one than
|
||||||
// the highest among the identifiers of previously received updates. By
|
// the highest among the identifiers of previously received updates. By
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// GetUserProfilePhotosParameters represents data for GetUserProfilePhotos method.
|
||||||
type GetUserProfilePhotosParameters struct {
|
type GetUserProfilePhotosParameters struct {
|
||||||
UserID int `json:"user_id"`
|
UserID int `json:"user_id"`
|
||||||
Offset int `json:"offset"`
|
Offset int `json:"offset"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// KickChatMemberParameters represents data for KickChatMember method.
|
||||||
type KickChatMemberParameters struct {
|
type KickChatMemberParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// LeaveChatParameters represents data for LeaveChat method.
|
||||||
type LeaveChatParameters struct {
|
type LeaveChatParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrUserNotDefined describes error of an unassigned structure of user
|
||||||
var ErrUserNotDefined = errors.New("user is not defined")
|
var ErrUserNotDefined = errors.New("user is not defined")
|
||||||
|
|
||||||
// CheckAuthorization verify the authentication and the integrity of the data
|
// CheckAuthorization verify the authentication and the integrity of the data
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package login
|
package login
|
||||||
|
|
||||||
|
// Key... represents available and supported data keys
|
||||||
const (
|
const (
|
||||||
KeyAuthDate = "auth_date"
|
KeyAuthDate = "auth_date"
|
||||||
KeyFirstName = "first_name"
|
KeyFirstName = "first_name"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// PinChatMessageParameters represents data for PinChatMessage method.
|
||||||
type PinChatMessageParameters struct {
|
type PinChatMessageParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
13
request.go
13
request.go
|
@ -3,7 +3,6 @@ package telegram
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
log "github.com/kirillDanshin/dlog"
|
log "github.com/kirillDanshin/dlog"
|
||||||
json "github.com/pquerna/ffjson/ffjson"
|
json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
@ -11,18 +10,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (bot *Bot) request(dst []byte, method string) (*Response, error) {
|
func (bot *Bot) request(dst []byte, method string) (*Response, error) {
|
||||||
requestURI := &url.URL{
|
requestURI := defaultURI
|
||||||
Scheme: "https",
|
requestURI.Path = fmt.Sprint("/bot", bot.AccessToken, "/", method)
|
||||||
Host: "api.telegram.org",
|
|
||||||
Path: fmt.Sprint("/bot", bot.AccessToken, "/", method),
|
|
||||||
}
|
|
||||||
|
|
||||||
req := http.AcquireRequest()
|
req := http.AcquireRequest()
|
||||||
defer http.ReleaseRequest(req)
|
defer http.ReleaseRequest(req)
|
||||||
req.Header.SetContentType("application/json; charset=utf-8")
|
req.Header.SetContentType("application/json; charset=utf-8")
|
||||||
req.Header.SetMethod("POST")
|
req.Header.SetMethod("POST")
|
||||||
|
if dst == nil {
|
||||||
|
req.Header.SetMethod("GET")
|
||||||
|
}
|
||||||
req.Header.SetRequestURI(requestURI.String())
|
req.Header.SetRequestURI(requestURI.String())
|
||||||
req.Header.SetUserAgent("go-telegram/3.5")
|
req.Header.SetUserAgent(fmt.Sprint("telegram/", Version))
|
||||||
req.Header.SetHost(requestURI.Hostname())
|
req.Header.SetHost(requestURI.Hostname())
|
||||||
req.SetBody(dst)
|
req.SetBody(dst)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SendChatActionParameters represents data for SendChatAction method.
|
||||||
type SendChatActionParameters struct {
|
type SendChatActionParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SendContactParameters represents data for SendContact method.
|
||||||
type SendContactParameters struct {
|
type SendContactParameters struct {
|
||||||
// Unique identifier for the target private chat
|
// Unique identifier for the target private chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -28,6 +29,7 @@ type SendContactParameters struct {
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewContact creates SendContactParameters only with required parameters.
|
||||||
func NewContact(chatID int64, phoneNumber, firstName string) *SendContactParameters {
|
func NewContact(chatID int64, phoneNumber, firstName string) *SendContactParameters {
|
||||||
return &SendContactParameters{
|
return &SendContactParameters{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SendDocumentParameters represents data for SendDocument method.
|
||||||
type SendDocumentParameters struct {
|
type SendDocumentParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -34,6 +35,7 @@ type SendDocumentParameters struct {
|
||||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDocument creates SendDocumentParameters only with required parameters.
|
||||||
func NewDocument(chatID int64, document interface{}) *SendDocumentParameters {
|
func NewDocument(chatID int64, document interface{}) *SendDocumentParameters {
|
||||||
return &SendDocumentParameters{
|
return &SendDocumentParameters{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SendGameParameters represents data for SendGame method.
|
||||||
type SendGameParameters struct {
|
type SendGameParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -23,6 +24,7 @@ type SendGameParameters struct {
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewGame creates SendGameParameters only with required parameters.
|
||||||
func NewGame(chatID int64, gameShortName string) *SendGameParameters {
|
func NewGame(chatID int64, gameShortName string) *SendGameParameters {
|
||||||
return &SendGameParameters{
|
return &SendGameParameters{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SendInvoiceParameters represents data for SendInvoice method.
|
||||||
type SendInvoiceParameters struct {
|
type SendInvoiceParameters struct {
|
||||||
// Unique identifier for the target private chat
|
// Unique identifier for the target private chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -78,6 +79,7 @@ type SendInvoiceParameters struct {
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInvoice creates SendInvoiceParameters only with required parameters.
|
||||||
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices ...LabeledPrice) *SendInvoiceParameters {
|
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices ...LabeledPrice) *SendInvoiceParameters {
|
||||||
return &SendInvoiceParameters{
|
return &SendInvoiceParameters{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SendLocationParameters represents data for SendLocation method.
|
||||||
type SendLocationParameters struct {
|
type SendLocationParameters struct {
|
||||||
// Unique identifier for the target private chat
|
// Unique identifier for the target private chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -29,6 +30,7 @@ type SendLocationParameters struct {
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewLocation creates SendLocationParameters only with required parameters.
|
||||||
func NewLocation(chatID int64, latitude, longitude float32) *SendLocationParameters {
|
func NewLocation(chatID int64, latitude, longitude float32) *SendLocationParameters {
|
||||||
return &SendLocationParameters{
|
return &SendLocationParameters{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SendMediaGroupParameters represents data for SendMediaGroup method.
|
||||||
type SendMediaGroupParameters struct {
|
type SendMediaGroupParameters struct {
|
||||||
// Unique identifier for the target chat.
|
// Unique identifier for the target chat.
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -18,6 +19,7 @@ type SendMediaGroupParameters struct {
|
||||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMediaGroup creates SendMediaGroupParameters only with required parameters.
|
||||||
func NewMediaGroup(chatID int64, media ...interface{}) *SendMediaGroupParameters {
|
func NewMediaGroup(chatID int64, media ...interface{}) *SendMediaGroupParameters {
|
||||||
return &SendMediaGroupParameters{
|
return &SendMediaGroupParameters{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SendMessageParameters represents data for SendMessage method.
|
||||||
type SendMessageParameters struct {
|
type SendMessageParameters struct {
|
||||||
// Unique identifier for the target chat or username of the target channel
|
// Unique identifier for the target chat or username of the target channel
|
||||||
// (in the format @channelusername)
|
// (in the format @channelusername)
|
||||||
|
@ -30,6 +31,7 @@ type SendMessageParameters struct {
|
||||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMessage creates SendMessageParameters only with required parameters.
|
||||||
func NewMessage(chatID int64, text string) *SendMessageParameters {
|
func NewMessage(chatID int64, text string) *SendMessageParameters {
|
||||||
return &SendMessageParameters{
|
return &SendMessageParameters{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SendPhotoParameters represents data for SendPhoto method.
|
||||||
type SendPhotoParameters struct {
|
type SendPhotoParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -41,6 +42,7 @@ type SendPhotoParameters struct {
|
||||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPhoto creates SendPhotoParameters only with required parameters.
|
||||||
func NewPhoto(chatID int64, photo interface{}) *SendPhotoParameters {
|
func NewPhoto(chatID int64, photo interface{}) *SendPhotoParameters {
|
||||||
return &SendPhotoParameters{
|
return &SendPhotoParameters{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SendVenueParameters represents data for SendVenue method.
|
||||||
type SendVenueParameters struct {
|
type SendVenueParameters struct {
|
||||||
// Unique identifier for the target private chat
|
// Unique identifier for the target private chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -34,6 +35,7 @@ type SendVenueParameters struct {
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewVenue creates SendVenueParameters only with required parameters.
|
||||||
func NewVenue(chatID int64, latitude, longitude float32, title, address string) *SendVenueParameters {
|
func NewVenue(chatID int64, latitude, longitude float32, title, address string) *SendVenueParameters {
|
||||||
return &SendVenueParameters{
|
return &SendVenueParameters{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SetChatDescriptionParameters represents data for SetChatDescription method.
|
||||||
type SetChatDescriptionParameters struct {
|
type SetChatDescriptionParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SetChatPhotoParameters represents data for SetChatPhoto method.
|
||||||
type SetChatPhotoParameters struct {
|
type SetChatPhotoParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SetChatStickerSetParameters represents data for SetChatStickerSet method.
|
||||||
type SetChatStickerSetParameters struct {
|
type SetChatStickerSetParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SetChatTitleParameters represents data for SetChatTitle method.
|
||||||
type SetChatTitleParameters struct {
|
type SetChatTitleParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SetGameScoreParameters represents data for SetGameScore method.
|
||||||
type SetGameScoreParameters struct {
|
type SetGameScoreParameters struct {
|
||||||
// User identifier
|
// User identifier
|
||||||
UserID int `json:"user_id"`
|
UserID int `json:"user_id"`
|
||||||
|
@ -30,6 +31,7 @@ type SetGameScoreParameters struct {
|
||||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewGameScore creates SetGameScoreParameters only with required parameters.
|
||||||
func NewGameScore(userID, score int) *SetGameScoreParameters {
|
func NewGameScore(userID, score int) *SetGameScoreParameters {
|
||||||
return &SetGameScoreParameters{
|
return &SetGameScoreParameters{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
|
|
|
@ -2,6 +2,8 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// SetStickerPositionInSetParameters represents data for SetStickerPositionInSet
|
||||||
|
// method.
|
||||||
type SetStickerPositionInSetParameters struct {
|
type SetStickerPositionInSetParameters struct {
|
||||||
Sticker string `json:"sticker"`
|
Sticker string `json:"sticker"`
|
||||||
Position int `json:"position"`
|
Position int `json:"position"`
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SetWebhookParameters represents data for SetWebhook method.
|
||||||
type SetWebhookParameters struct {
|
type SetWebhookParameters struct {
|
||||||
// HTTPS url to send updates to. Use an empty string to remove webhook
|
// HTTPS url to send updates to. Use an empty string to remove webhook
|
||||||
// integration
|
// integration
|
||||||
|
@ -36,6 +37,7 @@ type SetWebhookParameters struct {
|
||||||
AllowedUpdates []string `json:"allowed_updates,omitempty"`
|
AllowedUpdates []string `json:"allowed_updates,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewWebhook creates new SetWebhookParameters only with required parameters.
|
||||||
func NewWebhook(url string, file interface{}) *SetWebhookParameters {
|
func NewWebhook(url string, file interface{}) *SetWebhookParameters {
|
||||||
return &SetWebhookParameters{
|
return &SetWebhookParameters{
|
||||||
URL: url,
|
URL: url,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// UnbanChatMemberParameters represents data for UnbanChatMember method.
|
||||||
type UnbanChatMemberParameters struct {
|
type UnbanChatMemberParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package telegram
|
||||||
|
|
||||||
import json "github.com/pquerna/ffjson/ffjson"
|
import json "github.com/pquerna/ffjson/ffjson"
|
||||||
|
|
||||||
|
// UnpinChatMessageParameters represents data for UnpinChatMessage method.
|
||||||
type UnpinChatMessageParameters struct {
|
type UnpinChatMessageParameters struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
77
upload.go
77
upload.go
|
@ -14,6 +14,7 @@ import (
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrBadFileType describes error of the unsupported file data type for uploading
|
||||||
var ErrBadFileType = errors.New("bad file type")
|
var ErrBadFileType = errors.New("bad file type")
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -23,8 +24,10 @@ media, etc.):
|
||||||
1. If the file is already stored somewhere on the Telegram servers, you don't need to reupload it:
|
1. If the file is already stored somewhere on the Telegram servers, you don't need to reupload it:
|
||||||
each file object has a file_id field, simply pass this file_id as a parameter instead of uploading.
|
each file object has a file_id field, simply pass this file_id as a parameter instead of uploading.
|
||||||
There are no limits for files sent this way.
|
There are no limits for files sent this way.
|
||||||
|
|
||||||
2. Provide Telegram with an *url.URL for the file to be sent. Telegram will download and send the
|
2. Provide Telegram with an *url.URL for the file to be sent. Telegram will download and send the
|
||||||
file. 5 MB max size for photos and 20 MB max for other types of content.
|
file. 5 MB max size for photos and 20 MB max for other types of content.
|
||||||
|
|
||||||
3. Post the file using multipart/form-data in the usual way that files are uploaded via the
|
3. Post the file using multipart/form-data in the usual way that files are uploaded via the
|
||||||
browser. Use []byte or io.Reader for this. 10 MB max size for photos, 50 MB for other files.
|
browser. Use []byte or io.Reader for this. 10 MB max size for photos, 50 MB for other files.
|
||||||
|
|
||||||
|
@ -49,11 +52,8 @@ func (bot *Bot) Upload(method, key, name string, file InputFile, args fmt.String
|
||||||
buffer := bytes.NewBuffer(nil)
|
buffer := bytes.NewBuffer(nil)
|
||||||
multi := multipart.NewWriter(buffer)
|
multi := multipart.NewWriter(buffer)
|
||||||
|
|
||||||
requestURI := &url.URL{
|
requestURI := defaultURI
|
||||||
Scheme: "https",
|
requestURI.Path = fmt.Sprint("/bot", bot.AccessToken, "/", method)
|
||||||
Host: "api.telegram.org",
|
|
||||||
Path: fmt.Sprint("/bot", bot.AccessToken, "/", method),
|
|
||||||
}
|
|
||||||
|
|
||||||
query, err := url.ParseQuery(args.String())
|
query, err := url.ParseQuery(args.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -66,19 +66,7 @@ func (bot *Bot) Upload(method, key, name string, file InputFile, args fmt.String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch src := file.(type) {
|
if err = createFileField(multi, file, key, name); err != nil {
|
||||||
case string:
|
|
||||||
err = uploadByString(multi, key, src)
|
|
||||||
case *url.URL: // Send by URL
|
|
||||||
err = uploadFromURL(multi, key, src)
|
|
||||||
case []byte: // Upload new
|
|
||||||
err = uploadFromMemory(multi, key, name, bytes.NewReader(src))
|
|
||||||
case io.Reader: // Upload new
|
|
||||||
err = uploadFromMemory(multi, key, name, src)
|
|
||||||
default:
|
|
||||||
return nil, ErrBadFileType
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,23 +80,21 @@ func (bot *Bot) Upload(method, key, name string, file InputFile, args fmt.String
|
||||||
req.Header.SetContentType(multi.FormDataContentType())
|
req.Header.SetContentType(multi.FormDataContentType())
|
||||||
req.Header.SetMethod("POST")
|
req.Header.SetMethod("POST")
|
||||||
req.Header.SetRequestURI(requestURI.String())
|
req.Header.SetRequestURI(requestURI.String())
|
||||||
req.Header.SetUserAgent("go-telegram/3.5")
|
req.Header.SetUserAgent(fmt.Sprint("telegram/", Version))
|
||||||
req.Header.SetHost("api.telegram.org")
|
req.Header.SetHost(requestURI.Hostname())
|
||||||
|
|
||||||
log.Ln("Request:")
|
log.Ln("Request:")
|
||||||
log.D(req)
|
log.D(req)
|
||||||
|
|
||||||
resp := http.AcquireResponse()
|
resp := http.AcquireResponse()
|
||||||
defer http.ReleaseResponse(resp)
|
defer http.ReleaseResponse(resp)
|
||||||
if err = http.Do(req, resp); err != nil {
|
|
||||||
log.Ln("Resp:")
|
|
||||||
log.D(resp)
|
|
||||||
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
err = http.Do(req, resp)
|
||||||
log.Ln("Resp:")
|
log.Ln("Resp:")
|
||||||
log.D(resp)
|
log.D(resp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var data Response
|
var data Response
|
||||||
if err = json.Unmarshal(resp.Body(), &data); err != nil {
|
if err = json.Unmarshal(resp.Body(), &data); err != nil {
|
||||||
|
@ -122,19 +108,34 @@ func (bot *Bot) Upload(method, key, name string, file InputFile, args fmt.String
|
||||||
return &data, nil
|
return &data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadByString(w *multipart.Writer, key, src string) error {
|
func createFileField(w *multipart.Writer, file interface{}, key, val string) error {
|
||||||
_, err := os.Stat(src)
|
var err error
|
||||||
switch {
|
switch src := file.(type) {
|
||||||
case os.IsNotExist(err):
|
case string: // Send FileID of file on disk path
|
||||||
err = uploadFromFileID(w, key, src)
|
err = createFileFieldString(w, key, src)
|
||||||
case os.IsExist(err):
|
case *url.URL: // Send by URL
|
||||||
err = uploadFromDisk(w, key, src)
|
err = w.WriteField(key, src.String())
|
||||||
|
case []byte: // Upload new
|
||||||
|
err = createFileFieldRaw(w, key, val, bytes.NewReader(src))
|
||||||
|
case io.Reader: // Upload new
|
||||||
|
err = createFileFieldRaw(w, key, val, src)
|
||||||
|
default:
|
||||||
|
return ErrBadFileType
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadFromFileID(w *multipart.Writer, key, src string) error {
|
func createFileFieldString(w *multipart.Writer, key, src string) error {
|
||||||
return w.WriteField(key, src)
|
_, err := os.Stat(src)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case os.IsNotExist(err):
|
||||||
|
err = w.WriteField(key, src)
|
||||||
|
case os.IsExist(err):
|
||||||
|
err = uploadFromDisk(w, key, src)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadFromDisk(w *multipart.Writer, key, src string) error {
|
func uploadFromDisk(w *multipart.Writer, key, src string) error {
|
||||||
|
@ -156,11 +157,7 @@ func uploadFromDisk(w *multipart.Writer, key, src string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadFromURL(w *multipart.Writer, key string, src *url.URL) error {
|
func createFileFieldRaw(w *multipart.Writer, key, value string, src io.Reader) error {
|
||||||
return w.WriteField(key, src.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func uploadFromMemory(w *multipart.Writer, key, value string, src io.Reader) error {
|
|
||||||
field, err := w.CreateFormFile(key, value)
|
field, err := w.CreateFormFile(key, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
2
utils.go
2
utils.go
|
@ -5,10 +5,12 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewForceReply calls the response interface to the message.
|
||||||
func NewForceReply() *ForceReply {
|
func NewForceReply() *ForceReply {
|
||||||
return &ForceReply{ForceReply: true}
|
return &ForceReply{ForceReply: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineMentionURL creates a url.URL for the mention user without username.
|
||||||
func NewInlineMentionURL(userID int) *url.URL {
|
func NewInlineMentionURL(userID int) *url.URL {
|
||||||
link := &url.URL{
|
link := &url.URL{
|
||||||
Scheme: SchemeTelegram,
|
Scheme: SchemeTelegram,
|
||||||
|
|
102
utils_bot.go
102
utils_bot.go
|
@ -6,61 +6,42 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Bot represents a bot user with access token getted from @BotFather.
|
||||||
type Bot struct {
|
type Bot struct {
|
||||||
AccessToken string
|
AccessToken string
|
||||||
*User
|
*User
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates a new Bot structure based on the input access token.
|
||||||
func New(accessToken string) (*Bot, error) {
|
func New(accessToken string) (*Bot, error) {
|
||||||
var err error
|
var err error
|
||||||
bot := &Bot{AccessToken: accessToken}
|
bot := new(Bot)
|
||||||
|
bot.AccessToken = accessToken
|
||||||
|
|
||||||
bot.User, err = bot.GetMe()
|
bot.User, err = bot.GetMe()
|
||||||
return bot, err
|
return bot, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMessageFromMe checks that the input message is a message from the current
|
||||||
|
// bot.
|
||||||
func (bot *Bot) IsMessageFromMe(msg *Message) bool {
|
func (bot *Bot) IsMessageFromMe(msg *Message) bool {
|
||||||
if msg == nil || bot == nil {
|
return msg != nil && bot != nil && msg.From != nil && bot.User != nil && msg.From.ID == bot.ID
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.From == nil || bot.User == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg.From.ID == bot.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsForwardFromMe checks that the input message is a forwarded message from the
|
||||||
|
// current bot.
|
||||||
func (bot *Bot) IsForwardFromMe(msg *Message) bool {
|
func (bot *Bot) IsForwardFromMe(msg *Message) bool {
|
||||||
if !msg.IsForward() {
|
return msg.IsForward() && bot != nil && bot.User != nil && msg.ForwardFrom.ID == bot.ID
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if bot == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if bot.User == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg.ForwardFrom.ID == bot.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsReplyToMe checks that the input message is a reply to the current bot.
|
||||||
func (bot *Bot) IsReplyToMe(msg *Message) bool {
|
func (bot *Bot) IsReplyToMe(msg *Message) bool {
|
||||||
if msg.Chat.IsPrivate() {
|
return msg.Chat.IsPrivate() || (msg.IsReply() && bot.IsMessageFromMe(msg.ReplyToMessage))
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if !msg.IsReply() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return bot.IsMessageFromMe(msg.ReplyToMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsCommandToMe checks that the input message is a command for the current bot.
|
||||||
func (bot *Bot) IsCommandToMe(msg *Message) bool {
|
func (bot *Bot) IsCommandToMe(msg *Message) bool {
|
||||||
if !msg.IsCommand("") {
|
if !msg.IsCommand() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,12 +57,9 @@ func (bot *Bot) IsCommandToMe(msg *Message) bool {
|
||||||
return strings.ToLower(parts[1]) == strings.ToLower(bot.User.Username)
|
return strings.ToLower(parts[1]) == strings.ToLower(bot.User.Username)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMessageMentionsMe checks that the input message mentions the current bot.
|
||||||
func (bot *Bot) IsMessageMentionsMe(msg *Message) bool {
|
func (bot *Bot) IsMessageMentionsMe(msg *Message) bool {
|
||||||
if msg == nil || bot == nil {
|
if msg == nil || bot == nil || bot.User == nil {
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if bot.User == nil {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,59 +86,45 @@ func (bot *Bot) IsMessageMentionsMe(msg *Message) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsForwardMentionsMe checks that the input forwarded message mentions the
|
||||||
|
// current bot.
|
||||||
func (bot *Bot) IsForwardMentionsMe(msg *Message) bool {
|
func (bot *Bot) IsForwardMentionsMe(msg *Message) bool {
|
||||||
return msg.IsForward() && bot.IsMessageMentionsMe(msg)
|
return msg.IsForward() && bot.IsMessageMentionsMe(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsReplyMentionsMe checks that the input message mentions the current bot.
|
||||||
func (bot *Bot) IsReplyMentionsMe(msg *Message) bool {
|
func (bot *Bot) IsReplyMentionsMe(msg *Message) bool {
|
||||||
return msg.IsReply() && bot.IsMessageMentionsMe(msg.ReplyToMessage)
|
return msg.IsReply() && bot.IsMessageMentionsMe(msg.ReplyToMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMessageToMe checks that the input message is addressed to the current bot.
|
||||||
func (bot *Bot) IsMessageToMe(msg *Message) bool {
|
func (bot *Bot) IsMessageToMe(msg *Message) bool {
|
||||||
if msg == nil {
|
if msg == nil || msg.Chat == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Chat == nil {
|
if msg.Chat.IsPrivate() || bot.IsCommandToMe(msg) || bot.IsReplyToMe(msg) || bot.IsMessageMentionsMe(msg) {
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.Chat.IsPrivate() ||
|
|
||||||
bot.IsCommandToMe(msg) ||
|
|
||||||
bot.IsReplyToMe(msg) ||
|
|
||||||
bot.IsMessageMentionsMe(msg) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewFileURL creates a url.URL to file with path getted from GetFile method.
|
||||||
func (bot *Bot) NewFileURL(filePath string) *url.URL {
|
func (bot *Bot) NewFileURL(filePath string) *url.URL {
|
||||||
if bot == nil {
|
if bot == nil || bot.AccessToken == "" || filePath == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if bot.AccessToken == "" || filePath == "" {
|
result := defaultURI
|
||||||
return nil
|
result.Path = fmt.Sprint("/file/bot", bot.AccessToken, "/", filePath)
|
||||||
}
|
|
||||||
|
|
||||||
return &url.URL{
|
return result
|
||||||
Scheme: "https",
|
|
||||||
Host: "api.telegram.org",
|
|
||||||
Path: fmt.Sprint("/file/bot", bot.AccessToken, "/", filePath),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *Bot) NewRedirectURL(group bool, param string) *url.URL {
|
// NewRedirectURL creates new url.URL for redirecting from one chat to another.
|
||||||
if bot == nil {
|
func (bot *Bot) NewRedirectURL(param string, group bool) *url.URL {
|
||||||
return nil
|
if bot == nil || bot.User == nil || bot.User.Username == "" {
|
||||||
}
|
|
||||||
|
|
||||||
if bot.User == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if bot.User.Username == "" {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,11 +135,11 @@ func (bot *Bot) NewRedirectURL(group bool, param string) *url.URL {
|
||||||
}
|
}
|
||||||
|
|
||||||
q := link.Query()
|
q := link.Query()
|
||||||
|
key := "start"
|
||||||
if group {
|
if group {
|
||||||
q.Add("startgroup", param)
|
key += "group"
|
||||||
} else {
|
|
||||||
q.Add("start", param)
|
|
||||||
}
|
}
|
||||||
|
q.Add(key, param)
|
||||||
|
|
||||||
link.RawQuery = q.Encode()
|
link.RawQuery = q.Encode()
|
||||||
|
|
||||||
|
|
|
@ -2,60 +2,39 @@ package telegram
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
// IsPrivate checks that the current chat is a private chat with single user.
|
||||||
func (chat *Chat) IsPrivate() bool {
|
func (chat *Chat) IsPrivate() bool {
|
||||||
if chat == nil {
|
return chat != nil && chat.Type == ChatPrivate
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return chat.Type == ChatPrivate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsGroup checks that the current chat is a group.
|
||||||
func (chat *Chat) IsGroup() bool {
|
func (chat *Chat) IsGroup() bool {
|
||||||
if chat == nil {
|
return chat != nil && chat.Type == ChatGroup
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return chat.Type == ChatGroup
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsSuperGroup checks that the current chat is a supergroup.
|
||||||
func (chat *Chat) IsSuperGroup() bool {
|
func (chat *Chat) IsSuperGroup() bool {
|
||||||
if chat == nil {
|
return chat != nil && chat.Type == ChatSuperGroup
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return chat.Type == ChatSuperGroup
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsChannel checks that the current chat is a channel.
|
||||||
func (chat *Chat) IsChannel() bool {
|
func (chat *Chat) IsChannel() bool {
|
||||||
if chat == nil {
|
return chat != nil && chat.Type == ChatChannel
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return chat.Type == ChatChannel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasPinnedMessage checks that the current chat has a pinned message.
|
||||||
func (chat *Chat) HasPinnedMessage() bool {
|
func (chat *Chat) HasPinnedMessage() bool {
|
||||||
if chat == nil {
|
return chat != nil && chat.PinnedMessage != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return chat.PinnedMessage != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasStickerSet checks that the current chat has a sticker set.
|
||||||
func (chat *Chat) HasStickerSet() bool {
|
func (chat *Chat) HasStickerSet() bool {
|
||||||
if chat == nil {
|
return chat != nil && chat.StickerSetName != ""
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return chat.StickerSetName != ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StickerSet return StickerSet structure if StickerSetName is available.
|
||||||
func (chat *Chat) StickerSet(bot *Bot) *StickerSet {
|
func (chat *Chat) StickerSet(bot *Bot) *StickerSet {
|
||||||
if !chat.HasStickerSet() {
|
if !chat.HasStickerSet() || bot == nil {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if bot == nil {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +46,7 @@ func (chat *Chat) StickerSet(bot *Bot) *StickerSet {
|
||||||
return set
|
return set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FullName returns the full name of chat or FirstName if LastName is not available.
|
||||||
func (chat *Chat) FullName() string {
|
func (chat *Chat) FullName() string {
|
||||||
if chat == nil {
|
if chat == nil {
|
||||||
return ""
|
return ""
|
||||||
|
|
|
@ -5,16 +5,9 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ParseURL selects URL from entered text of message and parse it as url.URL.
|
||||||
func (entity *MessageEntity) ParseURL(messageText string) *url.URL {
|
func (entity *MessageEntity) ParseURL(messageText string) *url.URL {
|
||||||
if entity == nil {
|
if entity == nil || !entity.IsURL() || messageText == "" {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !entity.IsURL() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if messageText == "" {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,94 +29,62 @@ func (entity *MessageEntity) ParseURL(messageText string) *url.URL {
|
||||||
return link
|
return link
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsBold checks that the current entity is a bold tag.
|
||||||
func (entity *MessageEntity) IsBold() bool {
|
func (entity *MessageEntity) IsBold() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityBold
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityBold
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsBotCommand checks that the current entity is a bot command.
|
||||||
func (entity *MessageEntity) IsBotCommand() bool {
|
func (entity *MessageEntity) IsBotCommand() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityBotCommand
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityBotCommand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsCode checks that the current entity is a code tag.
|
||||||
func (entity *MessageEntity) IsCode() bool {
|
func (entity *MessageEntity) IsCode() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityCode
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityCode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsEmail checks that the current entity is a email.
|
||||||
func (entity *MessageEntity) IsEmail() bool {
|
func (entity *MessageEntity) IsEmail() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityEmail
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityEmail
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsHashtag checks that the current entity is a hashtag.
|
||||||
func (entity *MessageEntity) IsHashtag() bool {
|
func (entity *MessageEntity) IsHashtag() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityHashtag
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityHashtag
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsItalic checks that the current entity is a italic tag.
|
||||||
func (entity *MessageEntity) IsItalic() bool {
|
func (entity *MessageEntity) IsItalic() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityItalic
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityItalic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMention checks that the current entity is a username mention.
|
||||||
func (entity *MessageEntity) IsMention() bool {
|
func (entity *MessageEntity) IsMention() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityMention
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityMention
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPre checks that the current entity is a pre tag.
|
||||||
func (entity *MessageEntity) IsPre() bool {
|
func (entity *MessageEntity) IsPre() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityPre
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityPre
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsTextLink checks that the current entity is a text link.
|
||||||
func (entity *MessageEntity) IsTextLink() bool {
|
func (entity *MessageEntity) IsTextLink() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityTextLink
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityTextLink
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsTextMention checks that the current entity is a mention without username.
|
||||||
func (entity *MessageEntity) IsTextMention() bool {
|
func (entity *MessageEntity) IsTextMention() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityTextMention
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityTextMention
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsURL checks that the current entity is a URL
|
||||||
func (entity *MessageEntity) IsURL() bool {
|
func (entity *MessageEntity) IsURL() bool {
|
||||||
if entity == nil {
|
return entity != nil && entity.Type == EntityURL
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity.Type == EntityURL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TextLink parse current text link entity as url.URL.
|
||||||
func (entity *MessageEntity) TextLink() *url.URL {
|
func (entity *MessageEntity) TextLink() *url.URL {
|
||||||
if entity == nil {
|
if entity == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
|
// NewInlineKeyboardMarkup creates a new inline keyboard markup for message.
|
||||||
func NewInlineKeyboardMarkup(rows ...[]InlineKeyboardButton) *InlineKeyboardMarkup {
|
func NewInlineKeyboardMarkup(rows ...[]InlineKeyboardButton) *InlineKeyboardMarkup {
|
||||||
var keyboard [][]InlineKeyboardButton
|
var keyboard [][]InlineKeyboardButton
|
||||||
keyboard = append(keyboard, rows...)
|
keyboard = append(keyboard, rows...)
|
||||||
|
@ -8,12 +9,14 @@ func NewInlineKeyboardMarkup(rows ...[]InlineKeyboardButton) *InlineKeyboardMark
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineKeyboardRow creates a new inline keyboard row for buttons.
|
||||||
func NewInlineKeyboardRow(buttons ...InlineKeyboardButton) []InlineKeyboardButton {
|
func NewInlineKeyboardRow(buttons ...InlineKeyboardButton) []InlineKeyboardButton {
|
||||||
var row []InlineKeyboardButton
|
var row []InlineKeyboardButton
|
||||||
row = append(row, buttons...)
|
row = append(row, buttons...)
|
||||||
return row
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineKeyboardButton creates a new inline keyboard callback button.
|
||||||
func NewInlineKeyboardButton(text, data string) InlineKeyboardButton {
|
func NewInlineKeyboardButton(text, data string) InlineKeyboardButton {
|
||||||
return InlineKeyboardButton{
|
return InlineKeyboardButton{
|
||||||
Text: text,
|
Text: text,
|
||||||
|
@ -21,6 +24,7 @@ func NewInlineKeyboardButton(text, data string) InlineKeyboardButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineKeyboardButtonURL creates a new inline keyboard button with URL.
|
||||||
func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton {
|
func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton {
|
||||||
return InlineKeyboardButton{
|
return InlineKeyboardButton{
|
||||||
Text: text,
|
Text: text,
|
||||||
|
@ -28,6 +32,8 @@ func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineKeyboardButtonSwitch creates a new inline keyboard button to make
|
||||||
|
// specific inline query in other chat.
|
||||||
func NewInlineKeyboardButtonSwitch(text, query string) InlineKeyboardButton {
|
func NewInlineKeyboardButtonSwitch(text, query string) InlineKeyboardButton {
|
||||||
return InlineKeyboardButton{
|
return InlineKeyboardButton{
|
||||||
Text: text,
|
Text: text,
|
||||||
|
@ -35,6 +41,8 @@ func NewInlineKeyboardButtonSwitch(text, query string) InlineKeyboardButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineKeyboardButtonSwitchSelf creates a new inline keyboard button to make
|
||||||
|
// specific inline query in same chat.
|
||||||
func NewInlineKeyboardButtonSwitchSelf(text, query string) InlineKeyboardButton {
|
func NewInlineKeyboardButtonSwitchSelf(text, query string) InlineKeyboardButton {
|
||||||
return InlineKeyboardButton{
|
return InlineKeyboardButton{
|
||||||
Text: text,
|
Text: text,
|
||||||
|
@ -42,6 +50,8 @@ func NewInlineKeyboardButtonSwitchSelf(text, query string) InlineKeyboardButton
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineKeyboardButtonGame creates a new inline keyboard button with game
|
||||||
|
// callback.
|
||||||
func NewInlineKeyboardButtonGame(text string) InlineKeyboardButton {
|
func NewInlineKeyboardButtonGame(text string) InlineKeyboardButton {
|
||||||
var game CallbackGame
|
var game CallbackGame
|
||||||
return InlineKeyboardButton{
|
return InlineKeyboardButton{
|
||||||
|
@ -50,6 +60,8 @@ func NewInlineKeyboardButtonGame(text string) InlineKeyboardButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineKeyboardButtonPay creates a new inline keyboard button with pay
|
||||||
|
// callback.
|
||||||
func NewInlineKeyboardButtonPay(text string) InlineKeyboardButton {
|
func NewInlineKeyboardButtonPay(text string) InlineKeyboardButton {
|
||||||
return InlineKeyboardButton{
|
return InlineKeyboardButton{
|
||||||
Text: text,
|
Text: text,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
|
// NewInlineQueryResultCachedAudio creates a new inline query result with cached
|
||||||
|
// audio.
|
||||||
func NewInlineQueryResultCachedAudio(resultID, fileID string) *InlineQueryResultCachedAudio {
|
func NewInlineQueryResultCachedAudio(resultID, fileID string) *InlineQueryResultCachedAudio {
|
||||||
return &InlineQueryResultCachedAudio{
|
return &InlineQueryResultCachedAudio{
|
||||||
Type: TypeAudio,
|
Type: TypeAudio,
|
||||||
|
@ -8,6 +10,8 @@ func NewInlineQueryResultCachedAudio(resultID, fileID string) *InlineQueryResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultCachedDocument creates a new inline query result with
|
||||||
|
// cached document.
|
||||||
func NewInlineQueryResultCachedDocument(resultID, fileID, title string) *InlineQueryResultCachedDocument {
|
func NewInlineQueryResultCachedDocument(resultID, fileID, title string) *InlineQueryResultCachedDocument {
|
||||||
return &InlineQueryResultCachedDocument{
|
return &InlineQueryResultCachedDocument{
|
||||||
Type: TypeDocument,
|
Type: TypeDocument,
|
||||||
|
@ -17,6 +21,8 @@ func NewInlineQueryResultCachedDocument(resultID, fileID, title string) *InlineQ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultCachedGif creates a new inline query result with cached
|
||||||
|
// GIF.
|
||||||
func NewInlineQueryResultCachedGif(resultID, fileID string) *InlineQueryResultCachedGif {
|
func NewInlineQueryResultCachedGif(resultID, fileID string) *InlineQueryResultCachedGif {
|
||||||
return &InlineQueryResultCachedGif{
|
return &InlineQueryResultCachedGif{
|
||||||
Type: TypeGIF,
|
Type: TypeGIF,
|
||||||
|
@ -25,6 +31,8 @@ func NewInlineQueryResultCachedGif(resultID, fileID string) *InlineQueryResultCa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultCachedMpeg4Gif creates a new inline query result with
|
||||||
|
// cached MPEG GIF.
|
||||||
func NewInlineQueryResultCachedMpeg4Gif(resultID, fileID string) *InlineQueryResultCachedMpeg4Gif {
|
func NewInlineQueryResultCachedMpeg4Gif(resultID, fileID string) *InlineQueryResultCachedMpeg4Gif {
|
||||||
return &InlineQueryResultCachedMpeg4Gif{
|
return &InlineQueryResultCachedMpeg4Gif{
|
||||||
Type: TypeMpeg4Gif,
|
Type: TypeMpeg4Gif,
|
||||||
|
@ -33,6 +41,8 @@ func NewInlineQueryResultCachedMpeg4Gif(resultID, fileID string) *InlineQueryRes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultCachedPhoto creates a new inline query result with cached
|
||||||
|
// photo.
|
||||||
func NewInlineQueryResultCachedPhoto(resultID, fileID string) *InlineQueryResultCachedPhoto {
|
func NewInlineQueryResultCachedPhoto(resultID, fileID string) *InlineQueryResultCachedPhoto {
|
||||||
return &InlineQueryResultCachedPhoto{
|
return &InlineQueryResultCachedPhoto{
|
||||||
Type: TypePhoto,
|
Type: TypePhoto,
|
||||||
|
@ -41,6 +51,8 @@ func NewInlineQueryResultCachedPhoto(resultID, fileID string) *InlineQueryResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultCachedSticker creates a new inline query result with
|
||||||
|
// cached sticker.
|
||||||
func NewInlineQueryResultCachedSticker(resultID, fileID string) *InlineQueryResultCachedSticker {
|
func NewInlineQueryResultCachedSticker(resultID, fileID string) *InlineQueryResultCachedSticker {
|
||||||
return &InlineQueryResultCachedSticker{
|
return &InlineQueryResultCachedSticker{
|
||||||
Type: TypeSticker,
|
Type: TypeSticker,
|
||||||
|
@ -49,6 +61,8 @@ func NewInlineQueryResultCachedSticker(resultID, fileID string) *InlineQueryResu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultCachedVideo creates a new inline query result with cached
|
||||||
|
// video.
|
||||||
func NewInlineQueryResultCachedVideo(resultID, fileID, title string) *InlineQueryResultCachedVideo {
|
func NewInlineQueryResultCachedVideo(resultID, fileID, title string) *InlineQueryResultCachedVideo {
|
||||||
return &InlineQueryResultCachedVideo{
|
return &InlineQueryResultCachedVideo{
|
||||||
Type: TypeVideo,
|
Type: TypeVideo,
|
||||||
|
@ -58,6 +72,8 @@ func NewInlineQueryResultCachedVideo(resultID, fileID, title string) *InlineQuer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultCachedVoice creates a new inline query result with cached
|
||||||
|
// voice.
|
||||||
func NewInlineQueryResultCachedVoice(resultID, fileID, title string) *InlineQueryResultCachedVoice {
|
func NewInlineQueryResultCachedVoice(resultID, fileID, title string) *InlineQueryResultCachedVoice {
|
||||||
return &InlineQueryResultCachedVoice{
|
return &InlineQueryResultCachedVoice{
|
||||||
Type: TypeVoice,
|
Type: TypeVoice,
|
||||||
|
@ -67,6 +83,7 @@ func NewInlineQueryResultCachedVoice(resultID, fileID, title string) *InlineQuer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultArticle creates a new inline query result with article.
|
||||||
func NewInlineQueryResultArticle(resultID, title string, content *InputMessageContent) *InlineQueryResultArticle {
|
func NewInlineQueryResultArticle(resultID, title string, content *InputMessageContent) *InlineQueryResultArticle {
|
||||||
return &InlineQueryResultArticle{
|
return &InlineQueryResultArticle{
|
||||||
Type: TypeArticle,
|
Type: TypeArticle,
|
||||||
|
@ -76,6 +93,7 @@ func NewInlineQueryResultArticle(resultID, title string, content *InputMessageCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultAudio creates a new inline query result with audio.
|
||||||
func NewInlineQueryResultAudio(resultID, audioURL, title string) *InlineQueryResultAudio {
|
func NewInlineQueryResultAudio(resultID, audioURL, title string) *InlineQueryResultAudio {
|
||||||
return &InlineQueryResultAudio{
|
return &InlineQueryResultAudio{
|
||||||
Type: TypeAudio,
|
Type: TypeAudio,
|
||||||
|
@ -85,6 +103,7 @@ func NewInlineQueryResultAudio(resultID, audioURL, title string) *InlineQueryRes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultContact creates a new inline query result with contact.
|
||||||
func NewInlineQueryResultContact(resultID, phoneNumber, firstName string) *InlineQueryResultContact {
|
func NewInlineQueryResultContact(resultID, phoneNumber, firstName string) *InlineQueryResultContact {
|
||||||
return &InlineQueryResultContact{
|
return &InlineQueryResultContact{
|
||||||
Type: TypeContact,
|
Type: TypeContact,
|
||||||
|
@ -94,6 +113,7 @@ func NewInlineQueryResultContact(resultID, phoneNumber, firstName string) *Inlin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultGame creates a new inline query result with game.
|
||||||
func NewInlineQueryResultGame(resultID, gameShortName string) *InlineQueryResultGame {
|
func NewInlineQueryResultGame(resultID, gameShortName string) *InlineQueryResultGame {
|
||||||
return &InlineQueryResultGame{
|
return &InlineQueryResultGame{
|
||||||
Type: TypeGame,
|
Type: TypeGame,
|
||||||
|
@ -102,6 +122,7 @@ func NewInlineQueryResultGame(resultID, gameShortName string) *InlineQueryResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultDocument creates a new inline query result with document.
|
||||||
func NewInlineQueryResultDocument(resultID, title, documentURL, mimeType string) *InlineQueryResultDocument {
|
func NewInlineQueryResultDocument(resultID, title, documentURL, mimeType string) *InlineQueryResultDocument {
|
||||||
return &InlineQueryResultDocument{
|
return &InlineQueryResultDocument{
|
||||||
Type: TypeDocument,
|
Type: TypeDocument,
|
||||||
|
@ -112,6 +133,7 @@ func NewInlineQueryResultDocument(resultID, title, documentURL, mimeType string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultGif creates a new inline query result with GIF.
|
||||||
func NewInlineQueryResultGif(resultID, gifURL, thumbURL string) *InlineQueryResultGif {
|
func NewInlineQueryResultGif(resultID, gifURL, thumbURL string) *InlineQueryResultGif {
|
||||||
return &InlineQueryResultGif{
|
return &InlineQueryResultGif{
|
||||||
Type: TypeGIF,
|
Type: TypeGIF,
|
||||||
|
@ -121,6 +143,7 @@ func NewInlineQueryResultGif(resultID, gifURL, thumbURL string) *InlineQueryResu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultLocation creates a new inline query result with location.
|
||||||
func NewInlineQueryResultLocation(resultID, title string, latitude, longitude float32) *InlineQueryResultLocation {
|
func NewInlineQueryResultLocation(resultID, title string, latitude, longitude float32) *InlineQueryResultLocation {
|
||||||
return &InlineQueryResultLocation{
|
return &InlineQueryResultLocation{
|
||||||
Type: TypeLocation,
|
Type: TypeLocation,
|
||||||
|
@ -131,6 +154,7 @@ func NewInlineQueryResultLocation(resultID, title string, latitude, longitude fl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultMpeg4Gif creates a new inline query result with MPEG GIF.
|
||||||
func NewInlineQueryResultMpeg4Gif(resultID, mpeg4URL, thumbURL string) *InlineQueryResultMpeg4Gif {
|
func NewInlineQueryResultMpeg4Gif(resultID, mpeg4URL, thumbURL string) *InlineQueryResultMpeg4Gif {
|
||||||
return &InlineQueryResultMpeg4Gif{
|
return &InlineQueryResultMpeg4Gif{
|
||||||
Type: TypeMpeg4Gif,
|
Type: TypeMpeg4Gif,
|
||||||
|
@ -140,6 +164,7 @@ func NewInlineQueryResultMpeg4Gif(resultID, mpeg4URL, thumbURL string) *InlineQu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultPhoto creates a new inline query result with photo.
|
||||||
func NewInlineQueryResultPhoto(resultID, photoURL, thumbURL string) *InlineQueryResultPhoto {
|
func NewInlineQueryResultPhoto(resultID, photoURL, thumbURL string) *InlineQueryResultPhoto {
|
||||||
return &InlineQueryResultPhoto{
|
return &InlineQueryResultPhoto{
|
||||||
Type: TypePhoto,
|
Type: TypePhoto,
|
||||||
|
@ -149,6 +174,7 @@ func NewInlineQueryResultPhoto(resultID, photoURL, thumbURL string) *InlineQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultVenue creates a new inline query result with venue.
|
||||||
func NewInlineQueryResultVenue(resultID, title, address string, latitude, longitude float32) *InlineQueryResultVenue {
|
func NewInlineQueryResultVenue(resultID, title, address string, latitude, longitude float32) *InlineQueryResultVenue {
|
||||||
return &InlineQueryResultVenue{
|
return &InlineQueryResultVenue{
|
||||||
Type: TypeVenue,
|
Type: TypeVenue,
|
||||||
|
@ -160,6 +186,7 @@ func NewInlineQueryResultVenue(resultID, title, address string, latitude, longit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultVideo creates a new inline query result with video.
|
||||||
func NewInlineQueryResultVideo(resultID, videoURL, mimeType, thumbURL, title string) *InlineQueryResultVideo {
|
func NewInlineQueryResultVideo(resultID, videoURL, mimeType, thumbURL, title string) *InlineQueryResultVideo {
|
||||||
return &InlineQueryResultVideo{
|
return &InlineQueryResultVideo{
|
||||||
Type: TypeVideo,
|
Type: TypeVideo,
|
||||||
|
@ -171,6 +198,7 @@ func NewInlineQueryResultVideo(resultID, videoURL, mimeType, thumbURL, title str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInlineQueryResultVoice creates a new inline query result with voice.
|
||||||
func NewInlineQueryResultVoice(resultID, voiceURL, title string) *InlineQueryResultVoice {
|
func NewInlineQueryResultVoice(resultID, voiceURL, title string) *InlineQueryResultVoice {
|
||||||
return &InlineQueryResultVoice{
|
return &InlineQueryResultVoice{
|
||||||
Type: TypeVoice,
|
Type: TypeVoice,
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
|
// NewInputTextMessageContent creates a new text of message.
|
||||||
func NewInputTextMessageContent(messageText string) *InputTextMessageContent {
|
func NewInputTextMessageContent(messageText string) *InputTextMessageContent {
|
||||||
return &InputTextMessageContent{
|
return &InputTextMessageContent{
|
||||||
MessageText: messageText,
|
MessageText: messageText,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInputLocationMessageContent creates a new location.
|
||||||
func NewInputLocationMessageContent(latitude, longitude float32) *InputLocationMessageContent {
|
func NewInputLocationMessageContent(latitude, longitude float32) *InputLocationMessageContent {
|
||||||
return &InputLocationMessageContent{
|
return &InputLocationMessageContent{
|
||||||
Latitude: latitude,
|
Latitude: latitude,
|
||||||
|
@ -13,6 +15,7 @@ func NewInputLocationMessageContent(latitude, longitude float32) *InputLocationM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInputVenueMessageContent creates a new venue.
|
||||||
func NewInputVenueMessageContent(latitude, longitude float32, title, address string) *InputVenueMessageContent {
|
func NewInputVenueMessageContent(latitude, longitude float32, title, address string) *InputVenueMessageContent {
|
||||||
return &InputVenueMessageContent{
|
return &InputVenueMessageContent{
|
||||||
Latitude: latitude,
|
Latitude: latitude,
|
||||||
|
@ -22,6 +25,7 @@ func NewInputVenueMessageContent(latitude, longitude float32, title, address str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInputContactMessageContent creates a new contact.
|
||||||
func NewInputContactMessageContent(phoneNumber, firstName string) *InputContactMessageContent {
|
func NewInputContactMessageContent(phoneNumber, firstName string) *InputContactMessageContent {
|
||||||
return &InputContactMessageContent{
|
return &InputContactMessageContent{
|
||||||
PhoneNumber: phoneNumber,
|
PhoneNumber: phoneNumber,
|
||||||
|
@ -29,6 +33,7 @@ func NewInputContactMessageContent(phoneNumber, firstName string) *InputContactM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInputMediaPhoto creates a new photo in media album.
|
||||||
func NewInputMediaPhoto(media string) *InputMediaPhoto {
|
func NewInputMediaPhoto(media string) *InputMediaPhoto {
|
||||||
return &InputMediaPhoto{
|
return &InputMediaPhoto{
|
||||||
Type: TypePhoto,
|
Type: TypePhoto,
|
||||||
|
@ -36,6 +41,7 @@ func NewInputMediaPhoto(media string) *InputMediaPhoto {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInputMediaVideo creates a new video in media album.
|
||||||
func NewInputMediaVideo(media string) *InputMediaVideo {
|
func NewInputMediaVideo(media string) *InputMediaVideo {
|
||||||
return &InputMediaVideo{
|
return &InputMediaVideo{
|
||||||
Type: TypeVideo,
|
Type: TypeVideo,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
|
// NewReplyKeyboardRemove just hides keyboard.
|
||||||
func NewReplyKeyboardRemove(selective bool) *ReplyKeyboardRemove {
|
func NewReplyKeyboardRemove(selective bool) *ReplyKeyboardRemove {
|
||||||
return &ReplyKeyboardRemove{
|
return &ReplyKeyboardRemove{
|
||||||
RemoveKeyboard: true,
|
RemoveKeyboard: true,
|
||||||
|
@ -7,27 +8,29 @@ func NewReplyKeyboardRemove(selective bool) *ReplyKeyboardRemove {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewReplyKeyboardMarkup creates new keyboard markup of simple buttons.
|
||||||
func NewReplyKeyboardMarkup(rows ...[]KeyboardButton) *ReplyKeyboardMarkup {
|
func NewReplyKeyboardMarkup(rows ...[]KeyboardButton) *ReplyKeyboardMarkup {
|
||||||
var keyboard [][]KeyboardButton
|
var keyboard [][]KeyboardButton
|
||||||
keyboard = append(keyboard, rows...)
|
keyboard = append(keyboard, rows...)
|
||||||
return &ReplyKeyboardMarkup{
|
return &ReplyKeyboardMarkup{Keyboard: keyboard}
|
||||||
Keyboard: keyboard,
|
|
||||||
ResizeKeyboard: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewReplyKeyboardRow creates new keyboard row for buttons.
|
||||||
func NewReplyKeyboardRow(buttons ...KeyboardButton) []KeyboardButton {
|
func NewReplyKeyboardRow(buttons ...KeyboardButton) []KeyboardButton {
|
||||||
var row []KeyboardButton
|
var row []KeyboardButton
|
||||||
row = append(row, buttons...)
|
row = append(row, buttons...)
|
||||||
return row
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewReplyKeyboardButton creates new button with custom text for sending it.
|
||||||
func NewReplyKeyboardButton(text string) KeyboardButton {
|
func NewReplyKeyboardButton(text string) KeyboardButton {
|
||||||
return KeyboardButton{
|
return KeyboardButton{
|
||||||
Text: text,
|
Text: text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewReplyKeyboardButtonContact creates new button with custom text for sending
|
||||||
|
// user contact.
|
||||||
func NewReplyKeyboardButtonContact(text string) KeyboardButton {
|
func NewReplyKeyboardButtonContact(text string) KeyboardButton {
|
||||||
return KeyboardButton{
|
return KeyboardButton{
|
||||||
Text: text,
|
Text: text,
|
||||||
|
@ -35,6 +38,8 @@ func NewReplyKeyboardButtonContact(text string) KeyboardButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewReplyKeyboardButtonLocation creates new button with custom text for sending
|
||||||
|
// user location.
|
||||||
func NewReplyKeyboardButtonLocation(text string) KeyboardButton {
|
func NewReplyKeyboardButtonLocation(text string) KeyboardButton {
|
||||||
return KeyboardButton{
|
return KeyboardButton{
|
||||||
Text: text,
|
Text: text,
|
||||||
|
|
|
@ -2,54 +2,37 @@ package telegram
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
// IsCreator checks that current member is creator.
|
||||||
func (member *ChatMember) IsCreator() bool {
|
func (member *ChatMember) IsCreator() bool {
|
||||||
if member == nil {
|
return member != nil && member.Status == StatusCreator
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return member.Status == StatusCreator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsAdministrator checks that current member is administrator.
|
||||||
func (member *ChatMember) IsAdministrator() bool {
|
func (member *ChatMember) IsAdministrator() bool {
|
||||||
if member == nil {
|
return member != nil && member.Status == StatusAdministrator
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return member.Status == StatusAdministrator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMember checks that current member is a member.
|
||||||
func (member *ChatMember) IsMember() bool {
|
func (member *ChatMember) IsMember() bool {
|
||||||
if member == nil {
|
return member != nil && member.Status == StatusMember
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return member.Status == StatusMember
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsRestricted checks that current member has been restricted.
|
||||||
func (member *ChatMember) IsRestricted() bool {
|
func (member *ChatMember) IsRestricted() bool {
|
||||||
if member == nil {
|
return member != nil && member.Status == StatusRestricted
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return member.Status == StatusRestricted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsLeft checks that current member has left the chat.
|
||||||
func (member *ChatMember) IsLeft() bool {
|
func (member *ChatMember) IsLeft() bool {
|
||||||
if member == nil {
|
return member != nil && member.Status == StatusLeft
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return member.Status == StatusLeft
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsKicked checks that current member has been kicked.
|
||||||
func (member *ChatMember) IsKicked() bool {
|
func (member *ChatMember) IsKicked() bool {
|
||||||
if member == nil {
|
return member != nil && member.Status == StatusKicked
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return member.Status == StatusKicked
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UntilTime parse UntilDate of restrictions and returns time.Time.
|
||||||
func (member *ChatMember) UntilTime() time.Time {
|
func (member *ChatMember) UntilTime() time.Time {
|
||||||
if member == nil {
|
if member == nil {
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
|
|
114
utils_message.go
114
utils_message.go
|
@ -5,42 +5,44 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (msg *Message) IsCommand(command string) bool {
|
// IsCommand checks that the current message is a bot command.
|
||||||
if !msg.IsText() {
|
func (msg *Message) IsCommand() bool {
|
||||||
return false
|
if !msg.IsText() || !msg.HasEntities() {
|
||||||
}
|
|
||||||
|
|
||||||
if !msg.HasEntities() {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
entity := msg.Entities[0]
|
entity := msg.Entities[0]
|
||||||
isBotCommand := entity.IsBotCommand() && entity.Offset == 0
|
return entity.IsBotCommand() && entity.Offset == 0
|
||||||
if command != "" {
|
|
||||||
return isBotCommand && strings.EqualFold(msg.Command(), command)
|
|
||||||
}
|
|
||||||
|
|
||||||
return isBotCommand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsCommandEqual checks that the current message is a specific bot command.
|
||||||
|
func (msg *Message) IsCommandEqual(command string) bool {
|
||||||
|
return msg.IsCommand() && strings.EqualFold(msg.Command(), command)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command returns identifier of the bot command without bot username, if it was
|
||||||
|
// available
|
||||||
func (msg *Message) Command() string {
|
func (msg *Message) Command() string {
|
||||||
if !msg.IsCommand("") {
|
if !msg.IsCommand() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Split(msg.RawCommand(), "@")[0]
|
return strings.Split(msg.RawCommand(), "@")[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RawCommand returns identifier of the bot command with bot username, if it was
|
||||||
|
// available
|
||||||
func (msg *Message) RawCommand() string {
|
func (msg *Message) RawCommand() string {
|
||||||
if !msg.IsCommand("") {
|
if !msg.IsCommand() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return string([]rune(msg.Text)[1:msg.Entities[0].Length])
|
return string([]rune(msg.Text)[1:msg.Entities[0].Length])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasCommandArgument checks that the current command message contains argument.
|
||||||
func (msg *Message) HasCommandArgument() bool {
|
func (msg *Message) HasCommandArgument() bool {
|
||||||
if !msg.IsCommand("") {
|
if !msg.IsCommand() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +54,7 @@ func (msg *Message) HasCommandArgument() bool {
|
||||||
return len([]rune(msg.Text)) != entity.Length
|
return len([]rune(msg.Text)) != entity.Length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommandArgument returns raw command argument.
|
||||||
func (msg *Message) CommandArgument() string {
|
func (msg *Message) CommandArgument() string {
|
||||||
if !msg.HasCommandArgument() {
|
if !msg.HasCommandArgument() {
|
||||||
return ""
|
return ""
|
||||||
|
@ -60,22 +63,17 @@ func (msg *Message) CommandArgument() string {
|
||||||
return string([]rune(msg.Text)[msg.Entities[0].Length+1:])
|
return string([]rune(msg.Text)[msg.Entities[0].Length+1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsReply checks that the current message is a reply on other message.
|
||||||
func (msg *Message) IsReply() bool {
|
func (msg *Message) IsReply() bool {
|
||||||
if msg == nil {
|
return msg != nil && msg.ReplyToMessage != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg.ReplyToMessage != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsForward checks that the current message is a forward of other message.
|
||||||
func (msg *Message) IsForward() bool {
|
func (msg *Message) IsForward() bool {
|
||||||
if msg == nil {
|
return msg != nil && msg.ForwardFrom != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg.ForwardFrom != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Time parse current message Date and returns time.Time.
|
||||||
func (msg *Message) Time() time.Time {
|
func (msg *Message) Time() time.Time {
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
|
@ -84,6 +82,7 @@ func (msg *Message) Time() time.Time {
|
||||||
return time.Unix(msg.Date, 0)
|
return time.Unix(msg.Date, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ForwardTime parse current message ForwardDate and returns time.Time.
|
||||||
func (msg *Message) ForwardTime() time.Time {
|
func (msg *Message) ForwardTime() time.Time {
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
|
@ -92,131 +91,157 @@ func (msg *Message) ForwardTime() time.Time {
|
||||||
return time.Unix(msg.ForwardDate, 0)
|
return time.Unix(msg.ForwardDate, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditTime parse current message EditDate and returns time.Time.
|
||||||
func (msg *Message) EditTime() time.Time {
|
func (msg *Message) EditTime() time.Time {
|
||||||
var t time.Time
|
var t time.Time
|
||||||
if msg == nil {
|
if msg == nil || !msg.HasBeenEdited() {
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
if !msg.HasBeenEdited() {
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
return time.Unix(msg.EditDate, 0)
|
return time.Unix(msg.EditDate, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasBeenEdited checks that the current message has been edited.
|
||||||
func (msg *Message) HasBeenEdited() bool {
|
func (msg *Message) HasBeenEdited() bool {
|
||||||
if msg == nil {
|
return msg != nil && msg.EditDate > 0
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg.EditDate > 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsText checks that the current message is just a text message.
|
||||||
func (msg *Message) IsText() bool {
|
func (msg *Message) IsText() bool {
|
||||||
if msg == nil {
|
return msg != nil && msg.Text != ""
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg.Text != ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsAudio checks that the current message is a audio.
|
||||||
func (msg *Message) IsAudio() bool {
|
func (msg *Message) IsAudio() bool {
|
||||||
return !msg.IsText() && msg.Audio != nil
|
return !msg.IsText() && msg.Audio != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsDocument checks that the current message is a document.
|
||||||
func (msg *Message) IsDocument() bool {
|
func (msg *Message) IsDocument() bool {
|
||||||
return !msg.IsText() && msg.Document != nil
|
return !msg.IsText() && msg.Document != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsGame checks that the current message is a game.
|
||||||
func (msg *Message) IsGame() bool {
|
func (msg *Message) IsGame() bool {
|
||||||
return !msg.IsText() && msg.Game != nil
|
return !msg.IsText() && msg.Game != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPhoto checks that the current message is a photo.
|
||||||
func (msg *Message) IsPhoto() bool {
|
func (msg *Message) IsPhoto() bool {
|
||||||
return !msg.IsText() && len(msg.Photo) > 0
|
return !msg.IsText() && len(msg.Photo) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsSticker checks that the current message is a sticker.
|
||||||
func (msg *Message) IsSticker() bool {
|
func (msg *Message) IsSticker() bool {
|
||||||
return !msg.IsText() && msg.Sticker != nil
|
return !msg.IsText() && msg.Sticker != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsVideo checks that the current message is a video.
|
||||||
func (msg *Message) IsVideo() bool {
|
func (msg *Message) IsVideo() bool {
|
||||||
return !msg.IsText() && msg.Video != nil
|
return !msg.IsText() && msg.Video != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsVoice checks that the current message is a voice.
|
||||||
func (msg *Message) IsVoice() bool {
|
func (msg *Message) IsVoice() bool {
|
||||||
return !msg.IsText() && msg.Voice != nil
|
return !msg.IsText() && msg.Voice != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsVideoNote checks that the current message is a video note.
|
||||||
func (msg *Message) IsVideoNote() bool {
|
func (msg *Message) IsVideoNote() bool {
|
||||||
return !msg.IsText() && msg.VideoNote != nil
|
return !msg.IsText() && msg.VideoNote != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsContact checks that the current message is a contact.
|
||||||
func (msg *Message) IsContact() bool {
|
func (msg *Message) IsContact() bool {
|
||||||
return !msg.IsText() && msg.Contact != nil
|
return !msg.IsText() && msg.Contact != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsLocation checks that the current message is a location.
|
||||||
func (msg *Message) IsLocation() bool {
|
func (msg *Message) IsLocation() bool {
|
||||||
return !msg.IsText() && msg.Location != nil
|
return !msg.IsText() && msg.Location != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsVenue checks that the current message is a venue.
|
||||||
func (msg *Message) IsVenue() bool {
|
func (msg *Message) IsVenue() bool {
|
||||||
return !msg.IsText() && msg.Venue != nil
|
return !msg.IsText() && msg.Venue != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNewChatMembersEvent checks that the current message is a event of entry of
|
||||||
|
// new members.
|
||||||
func (msg *Message) IsNewChatMembersEvent() bool {
|
func (msg *Message) IsNewChatMembersEvent() bool {
|
||||||
return !msg.IsText() && len(msg.NewChatMembers) > 0
|
return !msg.IsText() && len(msg.NewChatMembers) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsLeftChatMemberEvent checks that the current message is a event of members
|
||||||
|
// exit.
|
||||||
func (msg *Message) IsLeftChatMemberEvent() bool {
|
func (msg *Message) IsLeftChatMemberEvent() bool {
|
||||||
return !msg.IsText() && msg.LeftChatMember != nil
|
return !msg.IsText() && msg.LeftChatMember != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNewChatTitleEvent checks that the current message is a event of setting a
|
||||||
|
// new chat title.
|
||||||
func (msg *Message) IsNewChatTitleEvent() bool {
|
func (msg *Message) IsNewChatTitleEvent() bool {
|
||||||
return !msg.IsText() && msg.NewChatTitle != ""
|
return !msg.IsText() && msg.NewChatTitle != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNewChatPhotoEvent checks that the current message is a event of setting a
|
||||||
|
// new chat avatar.
|
||||||
func (msg *Message) IsNewChatPhotoEvent() bool {
|
func (msg *Message) IsNewChatPhotoEvent() bool {
|
||||||
return !msg.IsText() && len(msg.NewChatPhoto) > 0
|
return !msg.IsText() && len(msg.NewChatPhoto) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsDeleteChatPhotoEvent checks that the current message is a event of deleting
|
||||||
|
// a chat avatar.
|
||||||
func (msg *Message) IsDeleteChatPhotoEvent() bool {
|
func (msg *Message) IsDeleteChatPhotoEvent() bool {
|
||||||
return !msg.IsText() && msg.DeleteChatPhoto
|
return !msg.IsText() && msg.DeleteChatPhoto
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsGroupChatCreatedEvent checks that the current message is a event of creating
|
||||||
|
// a new group.
|
||||||
func (msg *Message) IsGroupChatCreatedEvent() bool {
|
func (msg *Message) IsGroupChatCreatedEvent() bool {
|
||||||
return !msg.IsText() && msg.GroupChatCreated
|
return !msg.IsText() && msg.GroupChatCreated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsSupergroupChatCreatedEvent checks that the current message is a event of
|
||||||
|
// creating a new supergroup.
|
||||||
func (msg *Message) IsSupergroupChatCreatedEvent() bool {
|
func (msg *Message) IsSupergroupChatCreatedEvent() bool {
|
||||||
return !msg.IsText() && msg.SupergroupChatCreated
|
return !msg.IsText() && msg.SupergroupChatCreated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsChannelChatCreatedEvent checks that the current message is a event of
|
||||||
|
// creating a new channel.
|
||||||
func (msg *Message) IsChannelChatCreatedEvent() bool {
|
func (msg *Message) IsChannelChatCreatedEvent() bool {
|
||||||
return !msg.IsText() && msg.ChannelChatCreated
|
return !msg.IsText() && msg.ChannelChatCreated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPinnedMessage checks that the current message is a event of pinning another
|
||||||
|
// message.
|
||||||
func (msg *Message) IsPinnedMessage() bool {
|
func (msg *Message) IsPinnedMessage() bool {
|
||||||
return !msg.IsText() && msg.PinnedMessage != nil
|
return !msg.IsText() && msg.PinnedMessage != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsInvoice checks that the current message is a invoice.
|
||||||
func (msg *Message) IsInvoice() bool {
|
func (msg *Message) IsInvoice() bool {
|
||||||
return !msg.IsText() && msg.Invoice != nil
|
return !msg.IsText() && msg.Invoice != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsSuccessfulPayment checks that the current message is a event of successful
|
||||||
|
// payment.
|
||||||
func (msg *Message) IsSuccessfulPayment() bool {
|
func (msg *Message) IsSuccessfulPayment() bool {
|
||||||
return !msg.IsText() && msg.SuccessfulPayment != nil
|
return !msg.IsText() && msg.SuccessfulPayment != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasEntities checks that the current message contains entities.
|
||||||
func (msg *Message) HasEntities() bool {
|
func (msg *Message) HasEntities() bool {
|
||||||
return msg.IsText() && len(msg.Entities) > 0
|
return msg.IsText() && len(msg.Entities) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasCaptionEntities checks that the current media contains entities in caption.
|
||||||
func (msg *Message) HasCaptionEntities() bool {
|
func (msg *Message) HasCaptionEntities() bool {
|
||||||
return !msg.IsText() && len(msg.CaptionEntities) > 0
|
return !msg.IsText() && len(msg.CaptionEntities) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasMentions checks that the current message contains mentions.
|
||||||
func (msg *Message) HasMentions() bool {
|
func (msg *Message) HasMentions() bool {
|
||||||
if !msg.HasEntities() {
|
if !msg.HasEntities() {
|
||||||
return false
|
return false
|
||||||
|
@ -231,6 +256,7 @@ func (msg *Message) HasMentions() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasCaptionMentions checks that the current media contains mentions in caption.
|
||||||
func (msg *Message) HasCaptionMentions() bool {
|
func (msg *Message) HasCaptionMentions() bool {
|
||||||
if !msg.HasCaptionEntities() {
|
if !msg.HasCaptionEntities() {
|
||||||
return false
|
return false
|
||||||
|
@ -245,14 +271,12 @@ func (msg *Message) HasCaptionMentions() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasCaption checks that the current media has caption.
|
||||||
func (msg *Message) HasCaption() bool {
|
func (msg *Message) HasCaption() bool {
|
||||||
return !msg.IsText() && msg.Caption != ""
|
return !msg.IsText() && msg.Caption != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasAuthorSignature checks that the current channel post has author signature.
|
||||||
func (msg *Message) HasAuthorSignature() bool {
|
func (msg *Message) HasAuthorSignature() bool {
|
||||||
if msg == nil {
|
return msg != nil && msg.AuthorSignature != ""
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg.AuthorSignature != ""
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,11 @@ import (
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// UpdatesChannel is a channel for reading updates of bot.
|
||||||
type UpdatesChannel <-chan Update
|
type UpdatesChannel <-chan Update
|
||||||
|
|
||||||
|
// NewLongPollingChannel creates channel for receive incoming updates using long
|
||||||
|
// polling.
|
||||||
func (bot *Bot) NewLongPollingChannel(params *GetUpdatesParameters) UpdatesChannel {
|
func (bot *Bot) NewLongPollingChannel(params *GetUpdatesParameters) UpdatesChannel {
|
||||||
if params == nil {
|
if params == nil {
|
||||||
params = &GetUpdatesParameters{
|
params = &GetUpdatesParameters{
|
||||||
|
@ -44,6 +47,8 @@ func (bot *Bot) NewLongPollingChannel(params *GetUpdatesParameters) UpdatesChann
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewWebhookChannel creates channel for receive incoming updates via an outgoing
|
||||||
|
// webhook.
|
||||||
func (bot *Bot) NewWebhookChannel(params *SetWebhookParameters, certFile, keyFile, set, listen, serve string) (updates UpdatesChannel) {
|
func (bot *Bot) NewWebhookChannel(params *SetWebhookParameters, certFile, keyFile, set, listen, serve string) (updates UpdatesChannel) {
|
||||||
if params == nil {
|
if params == nil {
|
||||||
params = &SetWebhookParameters{
|
params = &SetWebhookParameters{
|
||||||
|
@ -92,74 +97,50 @@ func (bot *Bot) NewWebhookChannel(params *SetWebhookParameters, certFile, keyFil
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMessage checks that the current update is a message creation event.
|
||||||
func (upd *Update) IsMessage() bool {
|
func (upd *Update) IsMessage() bool {
|
||||||
if upd == nil {
|
return upd != nil && upd.Message != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return upd.Message != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsEditedMessage checks that the current update is a editing message event.
|
||||||
func (upd *Update) IsEditedMessage() bool {
|
func (upd *Update) IsEditedMessage() bool {
|
||||||
if upd == nil {
|
return upd != nil && upd.EditedMessage != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return upd.EditedMessage != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsChannelPost checks that the current update is a post channel creation event.
|
||||||
func (upd *Update) IsChannelPost() bool {
|
func (upd *Update) IsChannelPost() bool {
|
||||||
if upd == nil {
|
return upd != nil && upd.ChannelPost != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return upd.ChannelPost != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsEditedChannelPost checks that the current update is a editing post channel
|
||||||
|
// event.
|
||||||
func (upd *Update) IsEditedChannelPost() bool {
|
func (upd *Update) IsEditedChannelPost() bool {
|
||||||
if upd == nil {
|
return upd != nil && upd.EditedChannelPost != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return upd.EditedChannelPost != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsInlineQuery checks that the current update is a inline query update.
|
||||||
func (upd *Update) IsInlineQuery() bool {
|
func (upd *Update) IsInlineQuery() bool {
|
||||||
if upd == nil {
|
return upd != nil && upd.InlineQuery != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return upd.InlineQuery != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsChosenInlineResult checks that the current update is a chosen inline result
|
||||||
|
// update.
|
||||||
func (upd *Update) IsChosenInlineResult() bool {
|
func (upd *Update) IsChosenInlineResult() bool {
|
||||||
if upd == nil {
|
return upd != nil && upd.ChosenInlineResult != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return upd.ChosenInlineResult != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsCallbackQuery checks that the current update is a callback query update.
|
||||||
func (upd *Update) IsCallbackQuery() bool {
|
func (upd *Update) IsCallbackQuery() bool {
|
||||||
if upd == nil {
|
return upd != nil && upd.CallbackQuery != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return upd.CallbackQuery != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsShippingQuery checks that the current update is a shipping query update.
|
||||||
func (upd *Update) IsShippingQuery() bool {
|
func (upd *Update) IsShippingQuery() bool {
|
||||||
if upd == nil {
|
return upd != nil && upd.ShippingQuery != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return upd.ShippingQuery != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPreCheckoutQuery checks that the current update is a pre checkout query
|
||||||
|
// update.
|
||||||
func (upd *Update) IsPreCheckoutQuery() bool {
|
func (upd *Update) IsPreCheckoutQuery() bool {
|
||||||
if upd == nil {
|
return upd != nil && upd.PreCheckoutQuery != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return upd.PreCheckoutQuery != nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Language parse LanguageCode of current user and returns language.Tag.
|
||||||
func (user *User) Language() *language.Tag {
|
func (user *User) Language() *language.Tag {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -19,6 +20,8 @@ func (user *User) Language() *language.Tag {
|
||||||
return &tag
|
return &tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FullName returns the full name of user or FirstName if LastName is not
|
||||||
|
// available.
|
||||||
func (user *User) FullName() string {
|
func (user *User) FullName() string {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return ""
|
return ""
|
||||||
|
|
8
variables.go
Normal file
8
variables.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package telegram
|
||||||
|
|
||||||
|
import "net/url"
|
||||||
|
|
||||||
|
var defaultURI = &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "api.telegram.org",
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user