commit
aa6057b861
|
@ -19,6 +19,10 @@ type EditMessageCaptionParameters struct {
|
||||||
// New caption of the message
|
// New caption of the message
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// A JSON-serialized object for an inline keyboard.
|
// A JSON-serialized object for an inline keyboard.
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
37
login/check_authorization.go
Normal file
37
login/check_authorization.go
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package login
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CheckAuthorization verify the authentication and the integrity of the data
|
||||||
|
// received by comparing the received hash parameter with the hexadecimal
|
||||||
|
// representation of the HMAC-SHA-256 signature of the data-check-string with the
|
||||||
|
// SHA256 hash of the bot's token used as a secret key.
|
||||||
|
func (user *User) CheckAuthorization(botToken string) (bool, error) {
|
||||||
|
dataCheckString := fmt.Sprint(
|
||||||
|
"auth_date=", user.AuthDate.Unix(),
|
||||||
|
"\n", "first_name=", user.FirstName,
|
||||||
|
// Eliminate 'hash' to avoid recursion and incorrect data validation.
|
||||||
|
"\n", "id=", user.ID,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Add optional values if exist
|
||||||
|
if user.LastName != "" {
|
||||||
|
dataCheckString += fmt.Sprint("\n", "last_name=", user.LastName)
|
||||||
|
}
|
||||||
|
if user.PhotoURL != "" {
|
||||||
|
dataCheckString += fmt.Sprint("\n", "photo_url=", user.PhotoURL)
|
||||||
|
}
|
||||||
|
if user.Username != "" {
|
||||||
|
dataCheckString += fmt.Sprint("\n", "username=", user.Username)
|
||||||
|
}
|
||||||
|
|
||||||
|
secretKey := sha256.Sum256([]byte(botToken))
|
||||||
|
hash := hmac.New(sha256.New, secretKey[0:])
|
||||||
|
_, err := hash.Write([]byte(dataCheckString))
|
||||||
|
return hex.EncodeToString(hash.Sum(nil)) == user.Hash, err
|
||||||
|
}
|
3
login/doc.go
Normal file
3
login/doc.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
// Package login contains methods for obtaining structure of the user data and
|
||||||
|
// its validation.
|
||||||
|
package login
|
41
login/new.go
Normal file
41
login/new.go
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package login
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// User contains data about authenticated user.
|
||||||
|
type User struct {
|
||||||
|
AuthDate time.Time `json:"auth_date"`
|
||||||
|
FirstName string `json:"first_name"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
LastName string `json:"last_name,omitempty"`
|
||||||
|
PhotoURL string `json:"photo_url,omitempty"`
|
||||||
|
Username string `json:"username,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// New create User structure from input url.Values.
|
||||||
|
func New(src url.Values) (*User, error) {
|
||||||
|
authDate, err := strconv.Atoi(src.Get("auth_date"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := strconv.Atoi(src.Get("id"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &User{
|
||||||
|
AuthDate: time.Unix(int64(authDate), 0),
|
||||||
|
FirstName: src.Get("first_name"),
|
||||||
|
Hash: src.Get("hash"),
|
||||||
|
ID: id,
|
||||||
|
LastName: src.Get("last_name"),
|
||||||
|
PhotoURL: src.Get("photo_url"),
|
||||||
|
Username: src.Get("username"),
|
||||||
|
}, nil
|
||||||
|
}
|
|
@ -371,6 +371,9 @@ type (
|
||||||
// Message is a service message about a successful payment, information
|
// Message is a service message about a successful payment, information
|
||||||
// about the payment.
|
// about the payment.
|
||||||
SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"`
|
SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"`
|
||||||
|
|
||||||
|
// The domain name of the website on which the user has logged in.
|
||||||
|
ConnectedWebsite string `json:"connected_website,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageEntity represents one special entity in a text message. For
|
// MessageEntity represents one special entity in a text message. For
|
||||||
|
@ -871,6 +874,10 @@ type (
|
||||||
|
|
||||||
// Caption of the photo to be sent, 0-200 characters
|
// Caption of the photo to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputMediaVideo represents a video to be sent.
|
// InputMediaVideo represents a video to be sent.
|
||||||
|
@ -888,6 +895,10 @@ type (
|
||||||
// Caption of the video to be sent, 0-200 characters
|
// Caption of the video to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Video width
|
// Video width
|
||||||
Width int `json:"width,omitempty"`
|
Width int `json:"width,omitempty"`
|
||||||
|
|
||||||
|
@ -896,6 +907,9 @@ type (
|
||||||
|
|
||||||
// Video duration
|
// Video duration
|
||||||
Duration int `json:"duration,omitempty"`
|
Duration int `json:"duration,omitempty"`
|
||||||
|
|
||||||
|
// Pass true, if the uploaded video is suitable for streaming
|
||||||
|
SupportsStreaming bool `json:"supports_streaming,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputFile represents the contents of a file to be uploaded. Must be posted
|
// InputFile represents the contents of a file to be uploaded. Must be posted
|
||||||
|
@ -1078,6 +1092,10 @@ type (
|
||||||
// Caption of the photo to be sent, 0-200 characters
|
// Caption of the photo to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Inline keyboard attached to the message
|
// Inline keyboard attached to the message
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
|
|
||||||
|
@ -1117,6 +1135,10 @@ type (
|
||||||
// Caption of the GIF file to be sent, 0-200 characters
|
// Caption of the GIF file to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Inline keyboard attached to the message
|
// Inline keyboard attached to the message
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
|
|
||||||
|
@ -1194,6 +1216,10 @@ type (
|
||||||
// Caption of the video to be sent, 0-200 characters
|
// Caption of the video to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Video width
|
// Video width
|
||||||
VideoWidth int `json:"video_width,omitempty"`
|
VideoWidth int `json:"video_width,omitempty"`
|
||||||
|
|
||||||
|
@ -1235,6 +1261,10 @@ type (
|
||||||
// Caption, 0-200 characters
|
// Caption, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Performer
|
// Performer
|
||||||
Performer string `json:"performer,omitempty"`
|
Performer string `json:"performer,omitempty"`
|
||||||
|
|
||||||
|
@ -1268,6 +1298,10 @@ type (
|
||||||
// Caption, 0-200 characters
|
// Caption, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Recording duration in seconds
|
// Recording duration in seconds
|
||||||
VoiceDuration int `json:"voice_duration,omitempty"`
|
VoiceDuration int `json:"voice_duration,omitempty"`
|
||||||
|
|
||||||
|
@ -1296,6 +1330,10 @@ type (
|
||||||
// Caption of the document to be sent, 0-200 characters
|
// Caption of the document to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// A valid URL for the file
|
// A valid URL for the file
|
||||||
DocumentURL string `json:"document_url"`
|
DocumentURL string `json:"document_url"`
|
||||||
|
|
||||||
|
@ -1473,6 +1511,10 @@ type (
|
||||||
// Caption of the photo to be sent, 0-200 characters
|
// Caption of the photo to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Inline keyboard attached to the message
|
// Inline keyboard attached to the message
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
|
|
||||||
|
@ -1501,6 +1543,10 @@ type (
|
||||||
// Caption of the GIF file to be sent, 0-200 characters
|
// Caption of the GIF file to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Inline keyboard attached to the message
|
// Inline keyboard attached to the message
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
|
|
||||||
|
@ -1529,6 +1575,10 @@ type (
|
||||||
// Caption of the MPEG-4 file to be sent, 0-200 characters
|
// Caption of the MPEG-4 file to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Inline keyboard attached to the message
|
// Inline keyboard attached to the message
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
|
|
||||||
|
@ -1580,6 +1630,10 @@ type (
|
||||||
// Caption of the document to be sent, 0-200 characters
|
// Caption of the document to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Inline keyboard attached to the message
|
// Inline keyboard attached to the message
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
|
|
||||||
|
@ -1611,6 +1665,10 @@ type (
|
||||||
// Caption of the video to be sent, 0-200 characters
|
// Caption of the video to be sent, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Inline keyboard attached to the message
|
// Inline keyboard attached to the message
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
|
|
||||||
|
@ -1638,6 +1696,10 @@ type (
|
||||||
// Caption, 0-200 characters
|
// Caption, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Inline keyboard attached to the message
|
// Inline keyboard attached to the message
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
|
|
||||||
|
@ -1662,6 +1724,10 @@ type (
|
||||||
// Caption, 0-200 characters
|
// Caption, 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Inline keyboard attached to the message
|
// Inline keyboard attached to the message
|
||||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
|
|
|
@ -19,6 +19,10 @@ type SendDocumentParameters struct {
|
||||||
// Document caption (may also be used when resending documents by file_id), 0-200 characters
|
// Document caption (may also be used when resending documents by file_id), 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Sends the message silently. Users will receive a notification with no sound.
|
// Sends the message silently. Users will receive a notification with no sound.
|
||||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,10 @@ type SendPhotoParameters struct {
|
||||||
// Photo caption (may also be used when resending photos by file_id), 0-200 characters
|
// Photo caption (may also be used when resending photos by file_id), 0-200 characters
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
|
|
||||||
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||||
|
// fixed-width text or inline URLs in the media caption.
|
||||||
|
ParseMode string `json:"parse_mode,omitempty"`
|
||||||
|
|
||||||
// Disables link previews for links in this message
|
// Disables link previews for links in this message
|
||||||
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
|
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user