♻️ Refactoring old code
This commit is contained in:
parent
04183af64f
commit
3398b9f75c
|
@ -22,3 +22,6 @@ _testmain.go
|
|||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
|
||||
ffjson-inception*
|
||||
*_ffjson_expose.go
|
|
@ -0,0 +1,57 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
type AddStickerToSetParameters struct {
|
||||
// User identifier of sticker set owner
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Sticker set name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More info on Sending Files »
|
||||
PNGSticker interface{} `json:"png_sticker"`
|
||||
|
||||
// One or more emoji corresponding to the sticker
|
||||
Emojis string `json:"emojis"`
|
||||
|
||||
// A JSON-serialized object for position where the mask should be placed on faces
|
||||
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
|
||||
}
|
||||
|
||||
// AddStickerToSet add a new sticker to a set created by the bot. Returns True
|
||||
// on success.
|
||||
func (b *Bot) AddStickerToSet(params *AddStickerToSetParameters) (ok bool, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.SetUint("user_id", params.UserID)
|
||||
|
||||
if !strings.HasSuffix(strings.ToLower(params.Name), strings.ToLower("_by_"+b.Username)) {
|
||||
params.Name = params.Name + "_by_" + b.Username
|
||||
}
|
||||
|
||||
args.Set("emojis", params.Emojis)
|
||||
|
||||
if params.MaskPosition != nil {
|
||||
mp, err := json.MarshalFast(params.MaskPosition)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
args.SetBytesV("mask_position", mp)
|
||||
}
|
||||
|
||||
resp, err := b.Upload(MethodAddStickerToSet, TypeSticker, "sticker", params.PNGSticker, args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,408 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: add.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *AddStickerToSetParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *AddStickerToSetParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{ "user_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.UserID), 10, j.UserID < 0)
|
||||
buf.WriteString(`,"name":`)
|
||||
fflib.WriteJsonString(buf, string(j.Name))
|
||||
buf.WriteString(`,"png_sticker":`)
|
||||
/* Interface types must use runtime reflection. type=interface {} kind=interface */
|
||||
err = buf.Encode(j.PNGSticker)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf.WriteString(`,"emojis":`)
|
||||
fflib.WriteJsonString(buf, string(j.Emojis))
|
||||
buf.WriteByte(',')
|
||||
if j.MaskPosition != nil {
|
||||
if true {
|
||||
/* Struct fall back. type=telegram.MaskPosition kind=struct */
|
||||
buf.WriteString(`"mask_position":`)
|
||||
err = buf.Encode(j.MaskPosition)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
}
|
||||
buf.Rewind(1)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtAddStickerToSetParametersbase = iota
|
||||
ffjtAddStickerToSetParametersnosuchkey
|
||||
|
||||
ffjtAddStickerToSetParametersUserID
|
||||
|
||||
ffjtAddStickerToSetParametersName
|
||||
|
||||
ffjtAddStickerToSetParametersPNGSticker
|
||||
|
||||
ffjtAddStickerToSetParametersEmojis
|
||||
|
||||
ffjtAddStickerToSetParametersMaskPosition
|
||||
)
|
||||
|
||||
var ffjKeyAddStickerToSetParametersUserID = []byte("user_id")
|
||||
|
||||
var ffjKeyAddStickerToSetParametersName = []byte("name")
|
||||
|
||||
var ffjKeyAddStickerToSetParametersPNGSticker = []byte("png_sticker")
|
||||
|
||||
var ffjKeyAddStickerToSetParametersEmojis = []byte("emojis")
|
||||
|
||||
var ffjKeyAddStickerToSetParametersMaskPosition = []byte("mask_position")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *AddStickerToSetParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *AddStickerToSetParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtAddStickerToSetParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtAddStickerToSetParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'e':
|
||||
|
||||
if bytes.Equal(ffjKeyAddStickerToSetParametersEmojis, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersEmojis
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'm':
|
||||
|
||||
if bytes.Equal(ffjKeyAddStickerToSetParametersMaskPosition, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersMaskPosition
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'n':
|
||||
|
||||
if bytes.Equal(ffjKeyAddStickerToSetParametersName, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersName
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'p':
|
||||
|
||||
if bytes.Equal(ffjKeyAddStickerToSetParametersPNGSticker, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersPNGSticker
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'u':
|
||||
|
||||
if bytes.Equal(ffjKeyAddStickerToSetParametersUserID, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyAddStickerToSetParametersMaskPosition, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersMaskPosition
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyAddStickerToSetParametersEmojis, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersEmojis
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyAddStickerToSetParametersPNGSticker, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersPNGSticker
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.SimpleLetterEqualFold(ffjKeyAddStickerToSetParametersName, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersName
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyAddStickerToSetParametersUserID, kn) {
|
||||
currentKey = ffjtAddStickerToSetParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtAddStickerToSetParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtAddStickerToSetParametersUserID:
|
||||
goto handle_UserID
|
||||
|
||||
case ffjtAddStickerToSetParametersName:
|
||||
goto handle_Name
|
||||
|
||||
case ffjtAddStickerToSetParametersPNGSticker:
|
||||
goto handle_PNGSticker
|
||||
|
||||
case ffjtAddStickerToSetParametersEmojis:
|
||||
goto handle_Emojis
|
||||
|
||||
case ffjtAddStickerToSetParametersMaskPosition:
|
||||
goto handle_MaskPosition
|
||||
|
||||
case ffjtAddStickerToSetParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_UserID:
|
||||
|
||||
/* handler: j.UserID type=int kind=int quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.UserID = int(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_Name:
|
||||
|
||||
/* handler: j.Name type=string kind=string quoted=false*/
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
|
||||
}
|
||||
}
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
outBuf := fs.Output.Bytes()
|
||||
|
||||
j.Name = string(string(outBuf))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_PNGSticker:
|
||||
|
||||
/* handler: j.PNGSticker type=interface {} kind=interface quoted=false*/
|
||||
|
||||
{
|
||||
/* Falling back. type=interface {} kind=interface */
|
||||
tbuf, err := fs.CaptureField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(tbuf, &j.PNGSticker)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_Emojis:
|
||||
|
||||
/* handler: j.Emojis type=string kind=string quoted=false*/
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
|
||||
}
|
||||
}
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
outBuf := fs.Output.Bytes()
|
||||
|
||||
j.Emojis = string(string(outBuf))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_MaskPosition:
|
||||
|
||||
/* handler: j.MaskPosition type=telegram.MaskPosition kind=struct quoted=false*/
|
||||
|
||||
{
|
||||
/* Falling back. type=telegram.MaskPosition kind=struct */
|
||||
tbuf, err := fs.CaptureField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(tbuf, &j.MaskPosition)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
type (
|
||||
// AnswerCallbackQueryParameters represents data for AnswerCallbackQuery method.
|
||||
AnswerCallbackQueryParameters struct {
|
||||
// Unique identifier for the query to be answered
|
||||
CallbackQueryID string `json:"callback_query_id"`
|
||||
|
||||
// Text of the notification. If not specified, nothing will be shown to the
|
||||
// user, 0-200 characters
|
||||
Text string `json:"text,omitempty"`
|
||||
|
||||
// URL that will be opened by the user's client. If you have created a Game
|
||||
// and accepted the conditions via @Botfather, specify the URL that opens
|
||||
// your game – note that this will only work if the query comes from a
|
||||
// callback_game button.
|
||||
//
|
||||
// Otherwise, you may use links like t.me/your_bot?start=XXXX that open your
|
||||
// bot with a parameter.
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
// If true, an alert will be shown by the client instead of a notification at
|
||||
// the top of the chat screen. Defaults to false.
|
||||
ShowAlert bool `json:"show_alert,omitempty"`
|
||||
|
||||
// The maximum amount of time in seconds that the result of the callback
|
||||
// query may be cached client-side. Telegram apps will support caching
|
||||
// starting in version 3.14. Defaults to 0.
|
||||
CacheTime int `json:"cache_time,omitempty"`
|
||||
}
|
||||
|
||||
// AnswerPreCheckoutQueryParameters represents data for AnswerPreCheckoutQuery
|
||||
// method.
|
||||
AnswerPreCheckoutQueryParameters struct {
|
||||
// Unique identifier for the query to be answered
|
||||
PreCheckoutQueryID string `json:"pre_checkout_query_id"`
|
||||
|
||||
// Required if ok is False. Error message in human readable form that
|
||||
// explains the reason for failure to proceed with the checkout (e.g. "Sorry,
|
||||
// somebody just bought the last of our amazing black T-shirts while you were
|
||||
// busy filling out your payment details. Please choose a different color or
|
||||
// garment!"). Telegram will display this message to the user.
|
||||
ErrorMessage string `json:"error_message,omitempty"`
|
||||
|
||||
// Specify True if everything is alright (goods are available, etc.) and the
|
||||
// bot is ready to proceed with the order. Use False if there are any
|
||||
// problems.
|
||||
Ok bool `json:"ok"`
|
||||
}
|
||||
|
||||
// AnswerShippingQueryParameters represents data for AnswerShippingQuery method.
|
||||
AnswerShippingQueryParameters struct {
|
||||
// Unique identifier for the query to be answered
|
||||
ShippingQueryID string `json:"shipping_query_id"`
|
||||
|
||||
// Required if ok is False. Error message in human readable form that
|
||||
// explains why it is impossible to complete the order (e.g. "Sorry, delivery
|
||||
// to your desired address is unavailable'). Telegram will display this
|
||||
// message to the user.
|
||||
ErrorMessage string `json:"error_message,omitempty"`
|
||||
|
||||
// Specify True if delivery to the specified address is possible and False
|
||||
// if there are any problems (for example, if delivery to the specified
|
||||
// address is not possible)
|
||||
Ok bool `json:"ok"`
|
||||
|
||||
// Required if ok is True. A JSON-serialized array of available shipping
|
||||
// options.
|
||||
ShippingOptions []ShippingOption `json:"shipping_options,omitempty"`
|
||||
}
|
||||
|
||||
// AnswerInlineQueryParameters represents data for AnswerInlineQuery method.
|
||||
AnswerInlineQueryParameters struct {
|
||||
// Unique identifier for the answered query
|
||||
InlineQueryID string `json:"inline_query_id"`
|
||||
|
||||
// Pass the offset that a client should send in the next query with the same
|
||||
// text to receive more results. Pass an empty string if there are no more
|
||||
// results or if you don‘t support pagination. Offset length can’t exceed 64
|
||||
// bytes.
|
||||
NextOffset string `json:"next_offset,omitempty"`
|
||||
|
||||
// If passed, clients will display a button with specified text that switches
|
||||
// the user to a private chat with the bot and sends the bot a start message
|
||||
// with the parameter switch_pm_parameter
|
||||
SwitchPrivateMessageText string `json:"switch_pm_text,omitempty"`
|
||||
|
||||
// Deep-linking parameter for the /start message sent to the bot when user
|
||||
// presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and -
|
||||
// are allowed.
|
||||
SwitchPrivateMessageParameter string `json:"switch_pm_parameter,omitempty"`
|
||||
|
||||
// A JSON-serialized array of results for the inline query
|
||||
Results []interface{} `json:"results"`
|
||||
|
||||
// The maximum amount of time in seconds that the result of the inline query
|
||||
// may be cached on the server. Defaults to 300.
|
||||
CacheTime int `json:"cache_time,omitempty"`
|
||||
|
||||
// Pass True, if results may be cached on the server side only for the user
|
||||
// that sent the query. By default, results may be returned to any user who
|
||||
// sends the same query
|
||||
IsPersonal bool `json:"is_personal,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
// NewAnswerCallbackQuery creates AnswerCallbackQueryParameters only with
|
||||
// required parameters.
|
||||
func NewAnswerCallbackQuery(callbackQueryID string) *AnswerCallbackQueryParameters {
|
||||
return &AnswerCallbackQueryParameters{CallbackQueryID: callbackQueryID}
|
||||
}
|
||||
|
||||
// NewAnswerPreCheckoutQuery creates AnswerPreCheckoutQueryParameters only with
|
||||
// required parameters.
|
||||
func NewAnswerPreCheckoutQuery(preCheckoutQueryID string, ok bool) *AnswerPreCheckoutQueryParameters {
|
||||
return &AnswerPreCheckoutQueryParameters{
|
||||
PreCheckoutQueryID: preCheckoutQueryID,
|
||||
Ok: ok,
|
||||
}
|
||||
}
|
||||
|
||||
// NewAnswerShippingQuery creates AnswerShippingQueryParameters only with
|
||||
// required parameters.
|
||||
func NewAnswerShippingQuery(shippingQueryID string, ok bool) *AnswerShippingQueryParameters {
|
||||
return &AnswerShippingQueryParameters{
|
||||
ShippingQueryID: shippingQueryID,
|
||||
Ok: ok,
|
||||
}
|
||||
}
|
||||
|
||||
// NewAnswerInlineQuery creates AnswerInlineQueryParameters only with required
|
||||
// parameters.
|
||||
func NewAnswerInlineQuery(inlineQueryID string, results ...interface{}) *AnswerInlineQueryParameters {
|
||||
return &AnswerInlineQueryParameters{
|
||||
InlineQueryID: inlineQueryID,
|
||||
Results: results,
|
||||
}
|
||||
}
|
||||
|
||||
// AnswerCallbackQuery send answers to callback queries sent from inline
|
||||
// keyboards. The answer will be displayed to the user as a notification at the
|
||||
// top of the chat screen or as an alert. On success, True is returned.
|
||||
//
|
||||
// Alternatively, the user can be redirected to the specified Game URL. For this
|
||||
// option to work, you must first create a game for your bot via @Botfather and
|
||||
// accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX
|
||||
// that open your bot with a parameter.
|
||||
func (bot *Bot) AnswerCallbackQuery(params *AnswerCallbackQueryParameters) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodAnswerCallbackQuery)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// AnswerPreCheckoutQuery respond to such pre-checkout queries.
|
||||
//
|
||||
// Once the user has confirmed their payment and shipping details, the Bot API
|
||||
// sends the final confirmation in the form of an Update with the field
|
||||
// pre_checkout_query. Use this method to respond to such pre-checkout queries.
|
||||
// On success, True is returned.
|
||||
//
|
||||
// Note: The Bot API must receive an answer within 10 seconds after the
|
||||
// pre-checkout query was sent.
|
||||
func (bot *Bot) AnswerPreCheckoutQuery(params *AnswerShippingQueryParameters) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodAnswerPreCheckoutQuery)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// AnswerShippingQuery reply to shipping queries.
|
||||
//
|
||||
// If you sent an invoice requesting a shipping address and the parameter
|
||||
// is_flexible was specified, the Bot API will send an Update with a
|
||||
// shipping_query field to the bot. On success, True is returned.
|
||||
func (bot *Bot) AnswerShippingQuery(params *AnswerShippingQueryParameters) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodAnswerShippingQuery)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// AnswerInlineQuery send answers to an inline query. On success, True is returned.
|
||||
//
|
||||
// No more than 50 results per query are allowed.
|
||||
func (bot *Bot) AnswerInlineQuery(params *AnswerInlineQueryParameters) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodAnswerInlineQuery)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// AnswerCallbackQueryParameters represents data for AnswerCallbackQuery method.
|
||||
type AnswerCallbackQueryParameters struct {
|
||||
// Unique identifier for the query to be answered
|
||||
CallbackQueryID string `json:"callback_query_id"`
|
||||
|
||||
// Text of the notification. If not specified, nothing will be shown to the
|
||||
// user, 0-200 characters
|
||||
Text string `json:"text,omitempty"`
|
||||
|
||||
// URL that will be opened by the user's client. If you have created a Game
|
||||
// and accepted the conditions via @Botfather, specify the URL that opens
|
||||
// your game – note that this will only work if the query comes from a
|
||||
// callback_game button.
|
||||
//
|
||||
// Otherwise, you may use links like t.me/your_bot?start=XXXX that open your
|
||||
// bot with a parameter.
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
// If true, an alert will be shown by the client instead of a notification at
|
||||
// the top of the chat screen. Defaults to false.
|
||||
ShowAlert bool `json:"show_alert,omitempty"`
|
||||
|
||||
// The maximum amount of time in seconds that the result of the callback
|
||||
// query may be cached client-side. Telegram apps will support caching
|
||||
// starting in version 3.14. Defaults to 0.
|
||||
CacheTime int `json:"cache_time,omitempty"`
|
||||
}
|
||||
|
||||
// NewAnswerCallbackQuery creates AnswerCallbackQueryParameters only with
|
||||
// required parameters.
|
||||
func NewAnswerCallbackQuery(callbackQueryID string) *AnswerCallbackQueryParameters {
|
||||
return &AnswerCallbackQueryParameters{CallbackQueryID: callbackQueryID}
|
||||
}
|
||||
|
||||
// AnswerCallbackQuery send answers to callback queries sent from inline
|
||||
// keyboards. The answer will be displayed to the user as a notification at the
|
||||
// top of the chat screen or as an alert. On success, True is returned.
|
||||
//
|
||||
// Alternatively, the user can be redirected to the specified Game URL. For this
|
||||
// option to work, you must first create a game for your bot via @Botfather and
|
||||
// accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX
|
||||
// that open your bot with a parameter.
|
||||
func (bot *Bot) AnswerCallbackQuery(params *AnswerCallbackQueryParameters) (ok bool, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodAnswerCallbackQuery)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,55 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// AnswerPreCheckoutQueryParameters represents data for AnswerPreCheckoutQuery
|
||||
// method.
|
||||
type AnswerPreCheckoutQueryParameters struct {
|
||||
// Unique identifier for the query to be answered
|
||||
PreCheckoutQueryID string `json:"pre_checkout_query_id"`
|
||||
|
||||
// Required if ok is False. Error message in human readable form that
|
||||
// explains the reason for failure to proceed with the checkout (e.g. "Sorry,
|
||||
// somebody just bought the last of our amazing black T-shirts while you were
|
||||
// busy filling out your payment details. Please choose a different color or
|
||||
// garment!"). Telegram will display this message to the user.
|
||||
ErrorMessage string `json:"error_message,omitempty"`
|
||||
|
||||
// Specify True if everything is alright (goods are available, etc.) and the
|
||||
// bot is ready to proceed with the order. Use False if there are any
|
||||
// problems.
|
||||
Ok bool `json:"ok"`
|
||||
}
|
||||
|
||||
// NewAnswerPreCheckoutQuery creates AnswerPreCheckoutQueryParameters only with
|
||||
// required parameters.
|
||||
func NewAnswerPreCheckoutQuery(preCheckoutQueryID string, ok bool) *AnswerPreCheckoutQueryParameters {
|
||||
return &AnswerPreCheckoutQueryParameters{
|
||||
PreCheckoutQueryID: preCheckoutQueryID,
|
||||
Ok: ok,
|
||||
}
|
||||
}
|
||||
|
||||
// AnswerPreCheckoutQuery respond to such pre-checkout queries.
|
||||
//
|
||||
// Once the user has confirmed their payment and shipping details, the Bot API
|
||||
// sends the final confirmation in the form of an Update with the field
|
||||
// pre_checkout_query. Use this method to respond to such pre-checkout queries.
|
||||
// On success, True is returned.
|
||||
//
|
||||
// Note: The Bot API must receive an answer within 10 seconds after the
|
||||
// pre-checkout query was sent.
|
||||
func (bot *Bot) AnswerPreCheckoutQuery(params *AnswerShippingQueryParameters) (ok bool, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodAnswerPreCheckoutQuery)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// AnswerShippingQueryParameters represents data for AnswerShippingQuery method.
|
||||
type AnswerShippingQueryParameters struct {
|
||||
// Unique identifier for the query to be answered
|
||||
ShippingQueryID string `json:"shipping_query_id"`
|
||||
|
||||
// Required if ok is False. Error message in human readable form that
|
||||
// explains why it is impossible to complete the order (e.g. "Sorry, delivery
|
||||
// to your desired address is unavailable'). Telegram will display this
|
||||
// message to the user.
|
||||
ErrorMessage string `json:"error_message,omitempty"`
|
||||
|
||||
// Specify True if delivery to the specified address is possible and False
|
||||
// if there are any problems (for example, if delivery to the specified
|
||||
// address is not possible)
|
||||
Ok bool `json:"ok"`
|
||||
|
||||
// Required if ok is True. A JSON-serialized array of available shipping
|
||||
// options.
|
||||
ShippingOptions []ShippingOption `json:"shipping_options,omitempty"`
|
||||
}
|
||||
|
||||
// NewAnswerShippingQuery creates AnswerShippingQueryParameters only with
|
||||
// required parameters.
|
||||
func NewAnswerShippingQuery(shippingQueryID string, ok bool) *AnswerShippingQueryParameters {
|
||||
return &AnswerShippingQueryParameters{
|
||||
ShippingQueryID: shippingQueryID,
|
||||
Ok: ok,
|
||||
}
|
||||
}
|
||||
|
||||
// AnswerShippingQuery reply to shipping queries.
|
||||
//
|
||||
// If you sent an invoice requesting a shipping address and the parameter
|
||||
// is_flexible was specified, the Bot API will send an Update with a
|
||||
// shipping_query field to the bot. On success, True is returned.
|
||||
func (bot *Bot) AnswerShippingQuery(params *AnswerShippingQueryParameters) (ok bool, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodAnswerShippingQuery)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
type CreateNewStickerSetParameters struct {
|
||||
// User identifier of created sticker set owner
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Short name of sticker set, to be used in t.me/addstickers/ URLs
|
||||
// (e.g., animals). Can contain only english letters, digits and
|
||||
// underscores. Must begin with a letter, can't contain consecutive
|
||||
// underscores and must end in “_by_<bot username>”. <bot_username>
|
||||
// is case insensitive. 1-64 characters.
|
||||
Name string `json:"name"`
|
||||
|
||||
// Sticker set title, 1-64 characters
|
||||
Title string `json:"title"`
|
||||
|
||||
// Png image with the sticker, must be up to 512 kilobytes in size,
|
||||
// dimensions must not exceed 512px, and either width or height must
|
||||
// be exactly 512px. Pass a file_id as a String to send a file that
|
||||
// already exists on the Telegram servers, pass an HTTP URL as a
|
||||
// String for Telegram to get a file from the Internet, or upload
|
||||
// a new one using multipart/form-data.
|
||||
PNGSticker interface{} `json:"png_sticker"`
|
||||
|
||||
// One or more emoji corresponding to the sticker
|
||||
Emojis string `json:"emojis"`
|
||||
|
||||
// Pass True, if a set of mask stickers should be created
|
||||
ContainsMasks bool `json:"contains_masks,omitempty"`
|
||||
|
||||
// A JSON-serialized object for position where the mask should be
|
||||
// placed on faces
|
||||
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
|
||||
}
|
||||
|
||||
// CreateNewStickerSet create new sticker set owned by a user. The bot will be
|
||||
// able to edit the created sticker set. Returns True on success.
|
||||
func (b *Bot) CreateNewStickerSet(params *CreateNewStickerSetParameters) (ok bool, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.SetUint("user_id", params.UserID)
|
||||
|
||||
if !strings.HasSuffix(strings.ToLower(params.Name), strings.ToLower("_by_"+b.Username)) {
|
||||
params.Name = params.Name + "_by_" + b.Username
|
||||
}
|
||||
|
||||
args.Set("name", params.Name)
|
||||
args.Set("title", params.Title)
|
||||
args.Set("emojis", params.Emojis)
|
||||
args.Set("contains_masks", strconv.FormatBool(params.ContainsMasks))
|
||||
|
||||
if params.MaskPosition != nil {
|
||||
mp, err := json.MarshalFast(params.MaskPosition)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
args.SetBytesV("mask_position", mp)
|
||||
}
|
||||
|
||||
resp, err := b.Upload(MethodCreateNewStickerSet, TypeSticker, "sticker", params.PNGSticker, args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,522 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: create.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *CreateNewStickerSetParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *CreateNewStickerSetParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{ "user_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.UserID), 10, j.UserID < 0)
|
||||
buf.WriteString(`,"name":`)
|
||||
fflib.WriteJsonString(buf, string(j.Name))
|
||||
buf.WriteString(`,"title":`)
|
||||
fflib.WriteJsonString(buf, string(j.Title))
|
||||
buf.WriteString(`,"png_sticker":`)
|
||||
/* Interface types must use runtime reflection. type=interface {} kind=interface */
|
||||
err = buf.Encode(j.PNGSticker)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf.WriteString(`,"emojis":`)
|
||||
fflib.WriteJsonString(buf, string(j.Emojis))
|
||||
buf.WriteByte(',')
|
||||
if j.ContainsMasks != false {
|
||||
if j.ContainsMasks {
|
||||
buf.WriteString(`"contains_masks":true`)
|
||||
} else {
|
||||
buf.WriteString(`"contains_masks":false`)
|
||||
}
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
if j.MaskPosition != nil {
|
||||
if true {
|
||||
/* Struct fall back. type=telegram.MaskPosition kind=struct */
|
||||
buf.WriteString(`"mask_position":`)
|
||||
err = buf.Encode(j.MaskPosition)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
}
|
||||
buf.Rewind(1)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtCreateNewStickerSetParametersbase = iota
|
||||
ffjtCreateNewStickerSetParametersnosuchkey
|
||||
|
||||
ffjtCreateNewStickerSetParametersUserID
|
||||
|
||||
ffjtCreateNewStickerSetParametersName
|
||||
|
||||
ffjtCreateNewStickerSetParametersTitle
|
||||
|
||||
ffjtCreateNewStickerSetParametersPNGSticker
|
||||
|
||||
ffjtCreateNewStickerSetParametersEmojis
|
||||
|
||||
ffjtCreateNewStickerSetParametersContainsMasks
|
||||
|
||||
ffjtCreateNewStickerSetParametersMaskPosition
|
||||
)
|
||||
|
||||
var ffjKeyCreateNewStickerSetParametersUserID = []byte("user_id")
|
||||
|
||||
var ffjKeyCreateNewStickerSetParametersName = []byte("name")
|
||||
|
||||
var ffjKeyCreateNewStickerSetParametersTitle = []byte("title")
|
||||
|
||||
var ffjKeyCreateNewStickerSetParametersPNGSticker = []byte("png_sticker")
|
||||
|
||||
var ffjKeyCreateNewStickerSetParametersEmojis = []byte("emojis")
|
||||
|
||||
var ffjKeyCreateNewStickerSetParametersContainsMasks = []byte("contains_masks")
|
||||
|
||||
var ffjKeyCreateNewStickerSetParametersMaskPosition = []byte("mask_position")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *CreateNewStickerSetParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *CreateNewStickerSetParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtCreateNewStickerSetParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtCreateNewStickerSetParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyCreateNewStickerSetParametersContainsMasks, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersContainsMasks
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'e':
|
||||
|
||||
if bytes.Equal(ffjKeyCreateNewStickerSetParametersEmojis, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersEmojis
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'm':
|
||||
|
||||
if bytes.Equal(ffjKeyCreateNewStickerSetParametersMaskPosition, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersMaskPosition
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'n':
|
||||
|
||||
if bytes.Equal(ffjKeyCreateNewStickerSetParametersName, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersName
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'p':
|
||||
|
||||
if bytes.Equal(ffjKeyCreateNewStickerSetParametersPNGSticker, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersPNGSticker
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 't':
|
||||
|
||||
if bytes.Equal(ffjKeyCreateNewStickerSetParametersTitle, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersTitle
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'u':
|
||||
|
||||
if bytes.Equal(ffjKeyCreateNewStickerSetParametersUserID, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyCreateNewStickerSetParametersMaskPosition, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersMaskPosition
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyCreateNewStickerSetParametersContainsMasks, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersContainsMasks
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyCreateNewStickerSetParametersEmojis, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersEmojis
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyCreateNewStickerSetParametersPNGSticker, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersPNGSticker
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.SimpleLetterEqualFold(ffjKeyCreateNewStickerSetParametersTitle, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersTitle
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.SimpleLetterEqualFold(ffjKeyCreateNewStickerSetParametersName, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersName
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyCreateNewStickerSetParametersUserID, kn) {
|
||||
currentKey = ffjtCreateNewStickerSetParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtCreateNewStickerSetParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtCreateNewStickerSetParametersUserID:
|
||||
goto handle_UserID
|
||||
|
||||
case ffjtCreateNewStickerSetParametersName:
|
||||
goto handle_Name
|
||||
|
||||
case ffjtCreateNewStickerSetParametersTitle:
|
||||
goto handle_Title
|
||||
|
||||
case ffjtCreateNewStickerSetParametersPNGSticker:
|
||||
goto handle_PNGSticker
|
||||
|
||||
case ffjtCreateNewStickerSetParametersEmojis:
|
||||
goto handle_Emojis
|
||||
|
||||
case ffjtCreateNewStickerSetParametersContainsMasks:
|
||||
goto handle_ContainsMasks
|
||||
|
||||
case ffjtCreateNewStickerSetParametersMaskPosition:
|
||||
goto handle_MaskPosition
|
||||
|
||||
case ffjtCreateNewStickerSetParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_UserID:
|
||||
|
||||
/* handler: j.UserID type=int kind=int quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.UserID = int(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_Name:
|
||||
|
||||
/* handler: j.Name type=string kind=string quoted=false*/
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
|
||||
}
|
||||
}
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
outBuf := fs.Output.Bytes()
|
||||
|
||||
j.Name = string(string(outBuf))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_Title:
|
||||
|
||||
/* handler: j.Title type=string kind=string quoted=false*/
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
|
||||
}
|
||||
}
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
outBuf := fs.Output.Bytes()
|
||||
|
||||
j.Title = string(string(outBuf))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_PNGSticker:
|
||||
|
||||
/* handler: j.PNGSticker type=interface {} kind=interface quoted=false*/
|
||||
|
||||
{
|
||||
/* Falling back. type=interface {} kind=interface */
|
||||
tbuf, err := fs.CaptureField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(tbuf, &j.PNGSticker)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_Emojis:
|
||||
|
||||
/* handler: j.Emojis type=string kind=string quoted=false*/
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
|
||||
}
|
||||
}
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
outBuf := fs.Output.Bytes()
|
||||
|
||||
j.Emojis = string(string(outBuf))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_ContainsMasks:
|
||||
|
||||
/* handler: j.ContainsMasks type=bool kind=bool quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
tmpb := fs.Output.Bytes()
|
||||
|
||||
if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {
|
||||
|
||||
j.ContainsMasks = true
|
||||
|
||||
} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {
|
||||
|
||||
j.ContainsMasks = false
|
||||
|
||||
} else {
|
||||
err = errors.New("unexpected bytes for true/false value")
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_MaskPosition:
|
||||
|
||||
/* handler: j.MaskPosition type=telegram.MaskPosition kind=struct quoted=false*/
|
||||
|
||||
{
|
||||
/* Falling back. type=telegram.MaskPosition kind=struct */
|
||||
tbuf, err := fs.CaptureField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(tbuf, &j.MaskPosition)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
type (
|
||||
// DeleteChatPhotoParameters represents data for DeleteChatPhoto method.
|
||||
DeleteChatPhotoParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// DeleteChatStickerSetParameters represents data for DeleteChatStickerSet method.
|
||||
DeleteChatStickerSetParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// DeleteMessageParameters represents data for DeleteMessage method.
|
||||
DeleteMessageParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Identifier of the message to delete
|
||||
MessageID int `json:"message_id"`
|
||||
}
|
||||
|
||||
// DeleteStickerFromSetParameters represents data for DeleteStickerFromSet method.
|
||||
DeleteStickerFromSetParameters struct {
|
||||
// File identifier of the sticker
|
||||
Sticker string `json:"sticker"`
|
||||
}
|
||||
)
|
||||
|
||||
// DeleteChatPhoto delete a chat photo. Photos can't be changed for private
|
||||
// chats. The bot must be an administrator in the chat for this to work and must
|
||||
// have the appropriate admin rights. Returns True on success.
|
||||
//
|
||||
// Note: In regular groups (non-supergroups), this method will only work if the
|
||||
// 'All Members Are Admins' setting is off in the target group.
|
||||
func (bot *Bot) DeleteChatPhoto(chatID int64) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&DeleteChatPhotoParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodDeleteChatPhoto)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteChatStickerSet delete a group sticker set from a supergroup. The bot must be an administrator
|
||||
// in the chat for this to work and must have the appropriate admin rights. Use the field
|
||||
// can_set_sticker_set optionally returned in getChat requests to check if the bot can use this
|
||||
// method. Returns True on success.
|
||||
func (bot *Bot) DeleteChatStickerSet(chatID int64) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&DeleteChatStickerSetParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodDeleteChatStickerSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteWebhook remove webhook integration if you decide to switch back to
|
||||
// getUpdates. Returns True on success. Requires no parameters.
|
||||
func (bot *Bot) DeleteWebhook() (ok bool, err error) {
|
||||
resp, err := bot.request(nil, MethodDeleteWebhook)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteMessage delete a message, including service messages, with the following
|
||||
// limitations: A message can only be deleted if it was sent less than 48 hours
|
||||
// ago; Bots can delete outgoing messages in groups and supergroups; Bots granted
|
||||
// can_post_messages permissions can delete outgoing messages in channels; If the
|
||||
// bot is an administrator of a group, it can delete any message there; If the
|
||||
// bot has can_delete_messages permission in a supergroup or a channel, it can
|
||||
// delete any message there. Returns True on success.
|
||||
func (bot *Bot) DeleteMessage(chatID int64, messageID int) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&DeleteMessageParameters{
|
||||
ChatID: chatID,
|
||||
MessageID: messageID,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodDeleteMessage)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteStickerFromSet delete a sticker from a set created by the bot. Returns
|
||||
// True on success.
|
||||
func (bot *Bot) DeleteStickerFromSet(sticker string) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&DeleteStickerFromSetParameters{Sticker: sticker})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodDeleteStickerFromSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// DeleteChatPhotoParameters represents data for DeleteChatPhoto method.
|
||||
type DeleteChatPhotoParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// DeleteChatPhoto delete a chat photo. Photos can't be changed for private
|
||||
// chats. The bot must be an administrator in the chat for this to work and must
|
||||
// have the appropriate admin rights. Returns True on success.
|
||||
//
|
||||
// Note: In regular groups (non-supergroups), this method will only work if the
|
||||
// 'All Members Are Admins' setting is off in the target group.
|
||||
func (bot *Bot) DeleteChatPhoto(chatID int64) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&DeleteChatPhotoParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodDeleteChatPhoto)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// DeleteChatStickerSetParameters represents data for DeleteChatStickerSet method.
|
||||
type DeleteChatStickerSetParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// DeleteChatStickerSet delete a group sticker set from a supergroup. The bot must be an administrator
|
||||
// in the chat for this to work and must have the appropriate admin rights. Use the field
|
||||
// can_set_sticker_set optionally returned in getChat requests to check if the bot can use this
|
||||
// method. Returns True on success.
|
||||
func (bot *Bot) DeleteChatStickerSet(chatID int64) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&DeleteChatStickerSetParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodDeleteChatStickerSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,851 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: delete.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *DeleteChatPhotoParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *DeleteChatPhotoParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtDeleteChatPhotoParametersbase = iota
|
||||
ffjtDeleteChatPhotoParametersnosuchkey
|
||||
|
||||
ffjtDeleteChatPhotoParametersChatID
|
||||
)
|
||||
|
||||
var ffjKeyDeleteChatPhotoParametersChatID = []byte("chat_id")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *DeleteChatPhotoParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *DeleteChatPhotoParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtDeleteChatPhotoParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtDeleteChatPhotoParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyDeleteChatPhotoParametersChatID, kn) {
|
||||
currentKey = ffjtDeleteChatPhotoParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyDeleteChatPhotoParametersChatID, kn) {
|
||||
currentKey = ffjtDeleteChatPhotoParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtDeleteChatPhotoParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtDeleteChatPhotoParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtDeleteChatPhotoParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *DeleteChatStickerSetParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *DeleteChatStickerSetParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtDeleteChatStickerSetParametersbase = iota
|
||||
ffjtDeleteChatStickerSetParametersnosuchkey
|
||||
|
||||
ffjtDeleteChatStickerSetParametersChatID
|
||||
)
|
||||
|
||||
var ffjKeyDeleteChatStickerSetParametersChatID = []byte("chat_id")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *DeleteChatStickerSetParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *DeleteChatStickerSetParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtDeleteChatStickerSetParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtDeleteChatStickerSetParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyDeleteChatStickerSetParametersChatID, kn) {
|
||||
currentKey = ffjtDeleteChatStickerSetParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyDeleteChatStickerSetParametersChatID, kn) {
|
||||
currentKey = ffjtDeleteChatStickerSetParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtDeleteChatStickerSetParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtDeleteChatStickerSetParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtDeleteChatStickerSetParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *DeleteMessageParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *DeleteMessageParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteString(`,"message_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.MessageID), 10, j.MessageID < 0)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtDeleteMessageParametersbase = iota
|
||||
ffjtDeleteMessageParametersnosuchkey
|
||||
|
||||
ffjtDeleteMessageParametersChatID
|
||||
|
||||
ffjtDeleteMessageParametersMessageID
|
||||
)
|
||||
|
||||
var ffjKeyDeleteMessageParametersChatID = []byte("chat_id")
|
||||
|
||||
var ffjKeyDeleteMessageParametersMessageID = []byte("message_id")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *DeleteMessageParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *DeleteMessageParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtDeleteMessageParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtDeleteMessageParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyDeleteMessageParametersChatID, kn) {
|
||||
currentKey = ffjtDeleteMessageParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'm':
|
||||
|
||||
if bytes.Equal(ffjKeyDeleteMessageParametersMessageID, kn) {
|
||||
currentKey = ffjtDeleteMessageParametersMessageID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyDeleteMessageParametersMessageID, kn) {
|
||||
currentKey = ffjtDeleteMessageParametersMessageID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyDeleteMessageParametersChatID, kn) {
|
||||
currentKey = ffjtDeleteMessageParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtDeleteMessageParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtDeleteMessageParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtDeleteMessageParametersMessageID:
|
||||
goto handle_MessageID
|
||||
|
||||
case ffjtDeleteMessageParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_MessageID:
|
||||
|
||||
/* handler: j.MessageID type=int kind=int quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.MessageID = int(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *DeleteStickerFromSetParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *DeleteStickerFromSetParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"sticker":`)
|
||||
fflib.WriteJsonString(buf, string(j.Sticker))
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtDeleteStickerFromSetParametersbase = iota
|
||||
ffjtDeleteStickerFromSetParametersnosuchkey
|
||||
|
||||
ffjtDeleteStickerFromSetParametersSticker
|
||||
)
|
||||
|
||||
var ffjKeyDeleteStickerFromSetParametersSticker = []byte("sticker")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *DeleteStickerFromSetParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *DeleteStickerFromSetParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtDeleteStickerFromSetParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtDeleteStickerFromSetParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 's':
|
||||
|
||||
if bytes.Equal(ffjKeyDeleteStickerFromSetParametersSticker, kn) {
|
||||
currentKey = ffjtDeleteStickerFromSetParametersSticker
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyDeleteStickerFromSetParametersSticker, kn) {
|
||||
currentKey = ffjtDeleteStickerFromSetParametersSticker
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtDeleteStickerFromSetParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtDeleteStickerFromSetParametersSticker:
|
||||
goto handle_Sticker
|
||||
|
||||
case ffjtDeleteStickerFromSetParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_Sticker:
|
||||
|
||||
/* handler: j.Sticker type=string kind=string quoted=false*/
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
|
||||
}
|
||||
}
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
outBuf := fs.Output.Bytes()
|
||||
|
||||
j.Sticker = string(string(outBuf))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// DeleteWebhook remove webhook integration if you decide to switch back to
|
||||
// getUpdates. Returns True on success. Requires no parameters.
|
||||
func (bot *Bot) DeleteWebhook() (ok bool, err error) {
|
||||
resp, err := bot.request(nil, MethodDeleteWebhook)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,8 +1,35 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
type (
|
||||
// EditMessageLiveLocationParameters represents data for EditMessageLiveLocation
|
||||
// method.
|
||||
EditMessageLiveLocationParameters struct {
|
||||
// Required if inline_message_id is not specified. Unique identifier for the
|
||||
// target chat or username of the target channel (in the format
|
||||
// @channelusername)
|
||||
ChatID int64 `json:"chat_id,omitempty"`
|
||||
|
||||
// Required if inline_message_id is not specified. Identifier of the sent
|
||||
// message
|
||||
MessageID int `json:"message_id,omitempty"`
|
||||
|
||||
// Required if chat_id and message_id are not specified. Identifier of the
|
||||
// inline message
|
||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||
|
||||
// Latitude of new location
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Longitude of new location
|
||||
Longitude float32 `json:"longitude"`
|
||||
|
||||
// A JSON-serialized object for a new inline keyboard.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// EditMessageTextParameters represents data for EditMessageText method.
|
||||
EditMessageTextParameters struct {
|
||||
// Required if inline_message_id is not specified. Unique identifier for the
|
||||
|
@ -94,17 +121,17 @@ type (
|
|||
// A JSON-serialized object for an inline keyboard.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// DeleteMessageParameters represents data for DeleteMessage method.
|
||||
DeleteMessageParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Identifier of the message to delete
|
||||
MessageID int `json:"message_id"`
|
||||
}
|
||||
)
|
||||
|
||||
// NewLiveLocation creates EditMessageLiveLocationParameters only with required
|
||||
// parameters.
|
||||
func NewLiveLocation(latitude, longitude float32) *EditMessageLiveLocationParameters {
|
||||
return &EditMessageLiveLocationParameters{
|
||||
Latitude: latitude,
|
||||
Longitude: longitude,
|
||||
}
|
||||
}
|
||||
|
||||
// NewMessageText creates EditMessageTextParameters only with required parameters.
|
||||
func NewMessageText(text string) *EditMessageTextParameters {
|
||||
return &EditMessageTextParameters{
|
||||
|
@ -112,11 +139,32 @@ func NewMessageText(text string) *EditMessageTextParameters {
|
|||
}
|
||||
}
|
||||
|
||||
// EditMessageLiveLocation edit live location messages sent by the bot or via the
|
||||
// bot (for inline bots). A location can be edited until its live_period expires
|
||||
// or editing is explicitly disabled by a call to stopMessageLiveLocation. On
|
||||
// success, if the edited message was sent by the bot, the edited Message is
|
||||
// returned, otherwise True is returned.
|
||||
func (bot *Bot) EditMessageLiveLocation(params *EditMessageLiveLocationParameters) (msg *Message, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodEditMessageLiveLocation)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// EditMessageText edit text and game messages sent by the bot or via the bot
|
||||
// (for inline bots). On success, if edited message is sent by the bot, the
|
||||
// edited Message is returned, otherwise True is returned.
|
||||
func (bot *Bot) EditMessageText(params *EditMessageTextParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -127,7 +175,7 @@ func (bot *Bot) EditMessageText(params *EditMessageTextParameters) (msg *Message
|
|||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -135,7 +183,7 @@ func (bot *Bot) EditMessageText(params *EditMessageTextParameters) (msg *Message
|
|||
// (for inline bots). On success, if edited message is sent by the bot, the
|
||||
// edited Message is returned, otherwise True is returned.
|
||||
func (bot *Bot) EditMessageCaption(params *EditMessageCaptionParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -146,7 +194,7 @@ func (bot *Bot) EditMessageCaption(params *EditMessageCaptionParameters) (msg *M
|
|||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -158,7 +206,7 @@ func (bot *Bot) EditMessageCaption(params *EditMessageCaptionParameters) (msg *M
|
|||
// bot, the edited Message is returned, otherwise True is returned.
|
||||
func (b *Bot) EditMessageMedia(emmp *EditMessageMediaParameters) (msg *Message, err error) {
|
||||
var src []byte
|
||||
src, err = json.Marshal(emmp)
|
||||
src, err = json.MarshalFast(emmp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -169,7 +217,7 @@ func (b *Bot) EditMessageMedia(emmp *EditMessageMediaParameters) (msg *Message,
|
|||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -177,7 +225,7 @@ func (b *Bot) EditMessageMedia(emmp *EditMessageMediaParameters) (msg *Message,
|
|||
// or via the bot (for inline bots). On success, if edited message is sent by the
|
||||
// bot, the edited Message is returned, otherwise True is returned.
|
||||
func (bot *Bot) EditMessageReplyMarkup(params *EditMessageReplyMarkupParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -188,31 +236,6 @@ func (bot *Bot) EditMessageReplyMarkup(params *EditMessageReplyMarkupParameters)
|
|||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteMessage delete a message, including service messages, with the following
|
||||
// limitations: A message can only be deleted if it was sent less than 48 hours
|
||||
// ago; Bots can delete outgoing messages in groups and supergroups; Bots granted
|
||||
// can_post_messages permissions can delete outgoing messages in channels; If the
|
||||
// bot is an administrator of a group, it can delete any message there; If the
|
||||
// bot has can_delete_messages permission in a supergroup or a channel, it can
|
||||
// delete any message there. Returns True on success.
|
||||
func (bot *Bot) DeleteMessage(chatID int64, messageID int) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&DeleteMessageParameters{
|
||||
ChatID: chatID,
|
||||
MessageID: messageID,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodDeleteMessage)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,59 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// EditMessageLiveLocationParameters represents data for EditMessageLiveLocation
|
||||
// method.
|
||||
type EditMessageLiveLocationParameters struct {
|
||||
// Required if inline_message_id is not specified. Unique identifier for the
|
||||
// target chat or username of the target channel (in the format
|
||||
// @channelusername)
|
||||
ChatID int64 `json:"chat_id,omitempty"`
|
||||
|
||||
// Required if inline_message_id is not specified. Identifier of the sent
|
||||
// message
|
||||
MessageID int `json:"message_id,omitempty"`
|
||||
|
||||
// Required if chat_id and message_id are not specified. Identifier of the
|
||||
// inline message
|
||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||
|
||||
// Latitude of new location
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Longitude of new location
|
||||
Longitude float32 `json:"longitude"`
|
||||
|
||||
// A JSON-serialized object for a new inline keyboard.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// NewLiveLocation creates EditMessageLiveLocationParameters only with required
|
||||
// parameters.
|
||||
func NewLiveLocation(latitude, longitude float32) *EditMessageLiveLocationParameters {
|
||||
return &EditMessageLiveLocationParameters{
|
||||
Latitude: latitude,
|
||||
Longitude: longitude,
|
||||
}
|
||||
}
|
||||
|
||||
// EditMessageLiveLocation edit live location messages sent by the bot or via the
|
||||
// bot (for inline bots). A location can be edited until its live_period expires
|
||||
// or editing is explicitly disabled by a call to stopMessageLiveLocation. On
|
||||
// success, if the edited message was sent by the bot, the edited Message is
|
||||
// returned, otherwise True is returned.
|
||||
func (bot *Bot) EditMessageLiveLocation(params *EditMessageLiveLocationParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodEditMessageLiveLocation)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
@ -12,7 +13,7 @@ type ExportChatInviteLinkParameters struct {
|
|||
// bot must be an administrator in the chat for this to work and must have the
|
||||
// appropriate admin rights. Returns exported invite link as String on success.
|
||||
func (bot *Bot) ExportChatInviteLink(chatID int64) (inviteLink string, err error) {
|
||||
dst, err := json.Marshal(&ExportChatInviteLinkParameters{ChatID: chatID})
|
||||
dst, err := json.MarshalFast(&ExportChatInviteLinkParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -22,6 +23,6 @@ func (bot *Bot) ExportChatInviteLink(chatID int64) (inviteLink string, err error
|
|||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &inviteLink)
|
||||
err = json.UnmarshalFast(*resp.Result, &inviteLink)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: export.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *ExportChatInviteLinkParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *ExportChatInviteLinkParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtExportChatInviteLinkParametersbase = iota
|
||||
ffjtExportChatInviteLinkParametersnosuchkey
|
||||
|
||||
ffjtExportChatInviteLinkParametersChatID
|
||||
)
|
||||
|
||||
var ffjKeyExportChatInviteLinkParametersChatID = []byte("chat_id")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *ExportChatInviteLinkParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *ExportChatInviteLinkParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtExportChatInviteLinkParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtExportChatInviteLinkParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyExportChatInviteLinkParametersChatID, kn) {
|
||||
currentKey = ffjtExportChatInviteLinkParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyExportChatInviteLinkParametersChatID, kn) {
|
||||
currentKey = ffjtExportChatInviteLinkParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtExportChatInviteLinkParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtExportChatInviteLinkParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtExportChatInviteLinkParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
@ -31,7 +32,7 @@ func NewForwardMessage(from, to int64, messageID int) *ForwardMessageParameters
|
|||
|
||||
// ForwardMessage forward messages of any kind. On success, the sent Message is returned.
|
||||
func (bot *Bot) ForwardMessage(params *ForwardMessageParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -42,6 +43,6 @@ func (bot *Bot) ForwardMessage(params *ForwardMessageParameters) (msg *Message,
|
|||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,380 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: forward.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *ForwardMessageParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *ForwardMessageParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteString(`,"from_chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.FromChatID), 10, j.FromChatID < 0)
|
||||
buf.WriteByte(',')
|
||||
if j.DisableNotification != false {
|
||||
if j.DisableNotification {
|
||||
buf.WriteString(`"disable_notification":true`)
|
||||
} else {
|
||||
buf.WriteString(`"disable_notification":false`)
|
||||
}
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
buf.WriteString(`"message_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.MessageID), 10, j.MessageID < 0)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtForwardMessageParametersbase = iota
|
||||
ffjtForwardMessageParametersnosuchkey
|
||||
|
||||
ffjtForwardMessageParametersChatID
|
||||
|
||||
ffjtForwardMessageParametersFromChatID
|
||||
|
||||
ffjtForwardMessageParametersDisableNotification
|
||||
|
||||
ffjtForwardMessageParametersMessageID
|
||||
)
|
||||
|
||||
var ffjKeyForwardMessageParametersChatID = []byte("chat_id")
|
||||
|
||||
var ffjKeyForwardMessageParametersFromChatID = []byte("from_chat_id")
|
||||
|
||||
var ffjKeyForwardMessageParametersDisableNotification = []byte("disable_notification")
|
||||
|
||||
var ffjKeyForwardMessageParametersMessageID = []byte("message_id")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *ForwardMessageParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *ForwardMessageParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtForwardMessageParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtForwardMessageParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyForwardMessageParametersChatID, kn) {
|
||||
currentKey = ffjtForwardMessageParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'd':
|
||||
|
||||
if bytes.Equal(ffjKeyForwardMessageParametersDisableNotification, kn) {
|
||||
currentKey = ffjtForwardMessageParametersDisableNotification
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'f':
|
||||
|
||||
if bytes.Equal(ffjKeyForwardMessageParametersFromChatID, kn) {
|
||||
currentKey = ffjtForwardMessageParametersFromChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'm':
|
||||
|
||||
if bytes.Equal(ffjKeyForwardMessageParametersMessageID, kn) {
|
||||
currentKey = ffjtForwardMessageParametersMessageID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyForwardMessageParametersMessageID, kn) {
|
||||
currentKey = ffjtForwardMessageParametersMessageID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyForwardMessageParametersDisableNotification, kn) {
|
||||
currentKey = ffjtForwardMessageParametersDisableNotification
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyForwardMessageParametersFromChatID, kn) {
|
||||
currentKey = ffjtForwardMessageParametersFromChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyForwardMessageParametersChatID, kn) {
|
||||
currentKey = ffjtForwardMessageParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtForwardMessageParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtForwardMessageParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtForwardMessageParametersFromChatID:
|
||||
goto handle_FromChatID
|
||||
|
||||
case ffjtForwardMessageParametersDisableNotification:
|
||||
goto handle_DisableNotification
|
||||
|
||||
case ffjtForwardMessageParametersMessageID:
|
||||
goto handle_MessageID
|
||||
|
||||
case ffjtForwardMessageParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_FromChatID:
|
||||
|
||||
/* handler: j.FromChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.FromChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_DisableNotification:
|
||||
|
||||
/* handler: j.DisableNotification type=bool kind=bool quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
tmpb := fs.Output.Bytes()
|
||||
|
||||
if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {
|
||||
|
||||
j.DisableNotification = true
|
||||
|
||||
} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {
|
||||
|
||||
j.DisableNotification = false
|
||||
|
||||
} else {
|
||||
err = errors.New("unexpected bytes for true/false value")
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_MessageID:
|
||||
|
||||
/* handler: j.MessageID type=int kind=int quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.MessageID = int(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,314 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
type (
|
||||
// GetChatParameters represents data for GetChat method.
|
||||
GetChatParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// GetChatAdministratorsParameters represents data for GetChatAdministrators
|
||||
// method.
|
||||
GetChatAdministratorsParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// GetChatMemberParameters represents data for GetChatMember method.
|
||||
GetChatMemberParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Unique identifier of the target user
|
||||
UserID int `json:"user_id"`
|
||||
}
|
||||
|
||||
// GetChatMembersCountParameters represents data for GetChatMembersCount method.
|
||||
GetChatMembersCountParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// GetFileParameters represents data for GetFile method.
|
||||
GetFileParameters struct {
|
||||
// File identifier to get info about
|
||||
FileID string `json:"file_id"`
|
||||
}
|
||||
|
||||
// GetUpdatesParameters represents data for GetUpdates method.
|
||||
GetUpdatesParameters struct {
|
||||
// Identifier of the first update to be returned. Must be greater by one than the highest among the
|
||||
// identifiers of previously received updates. By default, updates starting with the earliest unconfirmed
|
||||
// update are returned. An update is considered confirmed as soon as getUpdates is called with an offset
|
||||
// higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset
|
||||
// update from the end of the updates queue. All previous updates will forgotten.
|
||||
Offset int `json:"offset,omitempty"`
|
||||
|
||||
// Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100.
|
||||
Limit int `json:"limit,omitempty"`
|
||||
|
||||
// Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short
|
||||
// polling should be used for testing purposes only.
|
||||
Timeout int `json:"timeout,omitempty"`
|
||||
|
||||
// List the types of updates you want your bot to receive. For example, specify ["message",
|
||||
// "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete
|
||||
// list of available update types. Specify an empty list to receive all updates regardless of type (default).
|
||||
// If not specified, the previous setting will be used.
|
||||
//
|
||||
// Please note that this parameter doesn't affect updates created before the call to the getUpdates, so
|
||||
// unwanted updates may be received for a short period of time.
|
||||
AllowedUpdates []string `json:"allowed_updates,omitempty"`
|
||||
}
|
||||
|
||||
// GetUserProfilePhotosParameters represents data for GetUserProfilePhotos method.
|
||||
GetUserProfilePhotosParameters struct {
|
||||
// Unique identifier of the target user
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Sequential number of the first photo to be returned. By default, all
|
||||
// photos are returned.
|
||||
Offset int `json:"offset,omitempty"`
|
||||
|
||||
// Limits the number of photos to be retrieved. Values between 1—100 are
|
||||
// accepted. Defaults to 100.
|
||||
Limit int `json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
// GetGameHighScoresParameters represents data for GetGameHighScores method.
|
||||
GetGameHighScoresParameters struct {
|
||||
// Target user id
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Required if inline_message_id is not specified. Identifier of the sent
|
||||
// message
|
||||
MessageID int `json:"message_id,omitempty"`
|
||||
|
||||
// Required if inline_message_id is not specified. Unique identifier for the
|
||||
// target chat
|
||||
ChatID int64 `json:"chat_id,omitempty"`
|
||||
|
||||
// Required if chat_id and message_id are not specified. Identifier of the
|
||||
// inline message
|
||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||
}
|
||||
|
||||
// GetStickerSetParameters represents data for GetStickerSet method.
|
||||
GetStickerSetParameters struct {
|
||||
// Name of the sticker set
|
||||
Name string `json:"name"`
|
||||
}
|
||||
)
|
||||
|
||||
// NewGameHighScores creates GetGameHighScoresParameters only with required parameters.
|
||||
func NewGameHighScores(userID int) *GetGameHighScoresParameters {
|
||||
return &GetGameHighScoresParameters{
|
||||
UserID: userID,
|
||||
}
|
||||
}
|
||||
|
||||
// GetChat get up to date information about the chat (current name of the user
|
||||
// for one-on-one conversations, current username of a user, group or channel,
|
||||
// etc.). Returns a Chat object on success.
|
||||
func (bot *Bot) GetChat(chatID int64) (chat *Chat, err error) {
|
||||
dst, err := json.MarshalFast(&GetChatParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetChat)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
chat = new(Chat)
|
||||
err = json.UnmarshalFast(*resp.Result, chat)
|
||||
return
|
||||
}
|
||||
|
||||
// GetChatAdministrators get a list of administrators in a chat. On success,
|
||||
// returns an Array of ChatMember objects that contains information about all
|
||||
// chat administrators except other bots. If the chat is a group or a supergroup
|
||||
// and no administrators were appointed, only the creator will be returned.
|
||||
func (bot *Bot) GetChatAdministrators(chatID int64) (members []ChatMember, err error) {
|
||||
dst, err := json.MarshalFast(&GetChatAdministratorsParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetChatAdministrators)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &members)
|
||||
return
|
||||
}
|
||||
|
||||
// GetChatMember get information about a member of a chat. Returns a ChatMember
|
||||
// object on success.
|
||||
func (bot *Bot) GetChatMember(chatID int64, userID int) (member *ChatMember, err error) {
|
||||
dst, err := json.MarshalFast(&GetChatMemberParameters{
|
||||
ChatID: chatID,
|
||||
UserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetChatMember)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
member = new(ChatMember)
|
||||
err = json.UnmarshalFast(*resp.Result, member)
|
||||
return
|
||||
}
|
||||
|
||||
// GetChatMembersCount get the number of members in a chat. Returns Int on
|
||||
// success.
|
||||
func (bot *Bot) GetChatMembersCount(chatID int64) (count int, err error) {
|
||||
dst, err := json.MarshalFast(&GetChatMembersCountParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetChatMembersCount)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &count)
|
||||
return
|
||||
}
|
||||
|
||||
// GetFile get basic info about a file and prepare it for downloading. For the
|
||||
// moment, bots can download files of up to 20MB in size. On success, a File
|
||||
// object is returned. The file can then be downloaded via the link
|
||||
// https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is
|
||||
// taken from the response. It is guaranteed that the link will be valid for at
|
||||
// least 1 hour. When the link expires, a new one can be requested by calling
|
||||
// getFile again.
|
||||
//
|
||||
// Note: This function may not preserve the original file name and MIME type. You
|
||||
// should save the file's MIME type and name (if available) when the File object
|
||||
// is received.
|
||||
func (bot *Bot) GetFile(fileID string) (file *File, err error) {
|
||||
dst, err := json.MarshalFast(&GetFileParameters{FileID: fileID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetFile)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
file = new(File)
|
||||
err = json.UnmarshalFast(*resp.Result, file)
|
||||
return
|
||||
}
|
||||
|
||||
// GetMe testing your bot's auth token. Requires no parameters. Returns basic
|
||||
// information about the bot in form of a User object.
|
||||
func (bot *Bot) GetMe() (me *User, err error) {
|
||||
resp, err := bot.request(nil, MethodGetMe)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
me = new(User)
|
||||
err = json.UnmarshalFast(*resp.Result, me)
|
||||
return
|
||||
}
|
||||
|
||||
// GetUpdates receive incoming updates using long polling. An Array of Update objects is returned.
|
||||
func (bot *Bot) GetUpdates(params *GetUpdatesParameters) (updates []Update, err error) {
|
||||
if params == nil {
|
||||
params = &GetUpdatesParameters{Limit: 100}
|
||||
}
|
||||
|
||||
src, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(src, MethodGetUpdates)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
updates = make([]Update, params.Limit)
|
||||
err = json.UnmarshalFast(*resp.Result, &updates)
|
||||
return
|
||||
}
|
||||
|
||||
// GetUserProfilePhotos get a list of profile pictures for a user. Returns a UserProfilePhotos object.
|
||||
func (bot *Bot) GetUserProfilePhotos(params *GetUserProfilePhotosParameters) (photos *UserProfilePhotos, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetUserProfilePhotos)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
photos = new(UserProfilePhotos)
|
||||
err = json.UnmarshalFast(*resp.Result, photos)
|
||||
return
|
||||
}
|
||||
|
||||
// GetWebhookInfo get current webhook status. Requires no parameters. On success,
|
||||
// returns a WebhookInfo object. If the bot is using getUpdates, will return an
|
||||
// object with the url field empty.
|
||||
func (bot *Bot) GetWebhookInfo() (info *WebhookInfo, err error) {
|
||||
resp, err := bot.request(nil, MethodGetWebhookInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
info = new(WebhookInfo)
|
||||
err = json.UnmarshalFast(*resp.Result, info)
|
||||
return
|
||||
}
|
||||
|
||||
// GetGameHighScores get data for high score tables. Will return the score of the
|
||||
// specified user and several of his neighbors in a game. On success, returns an
|
||||
// Array of GameHighScore objects.
|
||||
func (bot *Bot) GetGameHighScores(params *GetGameHighScoresParameters) (scores []GameHighScore, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetGameHighScores)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &scores)
|
||||
return
|
||||
}
|
||||
|
||||
// GetStickerSet get a sticker set. On success, a StickerSet object is returned.
|
||||
func (bot *Bot) GetStickerSet(name string) (set *StickerSet, err error) {
|
||||
dst, err := json.MarshalFast(&GetStickerSetParameters{Name: name})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetStickerSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
set = new(StickerSet)
|
||||
err = json.UnmarshalFast(*resp.Result, set)
|
||||
return
|
||||
}
|
28
get_chat.go
28
get_chat.go
|
@ -1,28 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// GetChatParameters represents data for GetChat method.
|
||||
type GetChatParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// GetChat get up to date information about the chat (current name of the user
|
||||
// for one-on-one conversations, current username of a user, group or channel,
|
||||
// etc.). Returns a Chat object on success.
|
||||
func (bot *Bot) GetChat(chatID int64) (chat *Chat, err error) {
|
||||
dst, err := json.Marshal(&GetChatParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetChat)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
chat = new(Chat)
|
||||
err = json.Unmarshal(*resp.Result, chat)
|
||||
return
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// GetChatAdministratorsParameters represents data for GetChatAdministrators
|
||||
// method.
|
||||
type GetChatAdministratorsParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// GetChatAdministrators get a list of administrators in a chat. On success,
|
||||
// returns an Array of ChatMember objects that contains information about all
|
||||
// chat administrators except other bots. If the chat is a group or a supergroup
|
||||
// and no administrators were appointed, only the creator will be returned.
|
||||
func (bot *Bot) GetChatAdministrators(chatID int64) (members []ChatMember, err error) {
|
||||
dst, err := json.Marshal(&GetChatAdministratorsParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetChatAdministrators)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &members)
|
||||
return
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// GetChatMemberParameters represents data for GetChatMember method.
|
||||
type GetChatMemberParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Unique identifier of the target user
|
||||
UserID int `json:"user_id"`
|
||||
}
|
||||
|
||||
// GetChatMember get information about a member of a chat. Returns a ChatMember
|
||||
// object on success.
|
||||
func (bot *Bot) GetChatMember(chatID int64, userID int) (member *ChatMember, err error) {
|
||||
dst, err := json.Marshal(&GetChatMemberParameters{
|
||||
ChatID: chatID,
|
||||
UserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetChatMember)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
member = new(ChatMember)
|
||||
err = json.Unmarshal(*resp.Result, member)
|
||||
return
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// GetChatMembersCountParameters represents data for GetChatMembersCount method.
|
||||
type GetChatMembersCountParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}
|
||||
|
||||
// GetChatMembersCount get the number of members in a chat. Returns Int on
|
||||
// success.
|
||||
func (bot *Bot) GetChatMembersCount(chatID int64) (count int, err error) {
|
||||
dst, err := json.Marshal(&GetChatMembersCountParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetChatMembersCount)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &count)
|
||||
return
|
||||
}
|
File diff suppressed because it is too large
Load Diff
36
get_file.go
36
get_file.go
|
@ -1,36 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// GetFileParameters represents data for GetFile method.
|
||||
type GetFileParameters struct {
|
||||
// File identifier to get info about
|
||||
FileID string `json:"file_id"`
|
||||
}
|
||||
|
||||
// GetFile get basic info about a file and prepare it for downloading. For the
|
||||
// moment, bots can download files of up to 20MB in size. On success, a File
|
||||
// object is returned. The file can then be downloaded via the link
|
||||
// https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is
|
||||
// taken from the response. It is guaranteed that the link will be valid for at
|
||||
// least 1 hour. When the link expires, a new one can be requested by calling
|
||||
// getFile again.
|
||||
//
|
||||
// Note: This function may not preserve the original file name and MIME type. You
|
||||
// should save the file's MIME type and name (if available) when the File object
|
||||
// is received.
|
||||
func (bot *Bot) GetFile(fileID string) (file *File, err error) {
|
||||
dst, err := json.Marshal(&GetFileParameters{FileID: fileID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetFile)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
file = new(File)
|
||||
err = json.Unmarshal(*resp.Result, file)
|
||||
return
|
||||
}
|
16
get_me.go
16
get_me.go
|
@ -1,16 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// GetMe testing your bot's auth token. Requires no parameters. Returns basic
|
||||
// information about the bot in form of a User object.
|
||||
func (bot *Bot) GetMe() (me *User, err error) {
|
||||
resp, err := bot.request(nil, MethodGetMe)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
me = new(User)
|
||||
err = json.Unmarshal(*resp.Result, me)
|
||||
return
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// GetUpdatesParameters represents data for GetUpdates method.
|
||||
type GetUpdatesParameters struct {
|
||||
// Identifier of the first update to be returned. Must be greater by one than
|
||||
// the highest among the identifiers of previously received updates. By
|
||||
// default, updates starting with the earliest unconfirmed update are
|
||||
// returned. An update is considered confirmed as soon as getUpdates is
|
||||
// called with an offset higher than its update_id. The negative offset can
|
||||
// be specified to retrieve updates starting from -offset update from the
|
||||
// end of the updates queue. All previous updates will forgotten.
|
||||
Offset int `json:"offset,omitempty"`
|
||||
|
||||
// Limits the number of updates to be retrieved. Values between 1—100 are
|
||||
// accepted. Defaults to 100.
|
||||
Limit int `json:"limit,omitempty"`
|
||||
|
||||
// Timeout in seconds for long polling. Defaults to 0, i.e. usual short
|
||||
// polling. Should be positive, short polling should be used for testing
|
||||
// purposes only.
|
||||
Timeout int `json:"timeout,omitempty"`
|
||||
|
||||
// List the types of updates you want your bot to receive. For example,
|
||||
// specify [“message”, “edited_channel_post”, “callback_query”] to only
|
||||
// receive updates of these types. See Update for a complete list of
|
||||
// available update types. Specify an empty list to receive all updates
|
||||
// regardless of type (default). If not specified, the previous setting will
|
||||
// be used.
|
||||
//
|
||||
// Please note that this parameter doesn't affect updates created before the
|
||||
// call to the getUpdates, so unwanted updates may be received for a short
|
||||
// period of time.
|
||||
AllowedUpdates []string `json:"allowed_updates,omitempty"`
|
||||
}
|
||||
|
||||
// GetUpdates receive incoming updates using long polling. An Array of
|
||||
// Update objects is returned.
|
||||
func (bot *Bot) GetUpdates(params *GetUpdatesParameters) (updates []Update, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetUpdates)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if params == nil {
|
||||
params = new(GetUpdatesParameters)
|
||||
params.Limit = 100
|
||||
}
|
||||
|
||||
updates = make([]Update, params.Limit)
|
||||
err = json.Unmarshal(*resp.Result, &updates)
|
||||
return
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// GetUserProfilePhotosParameters represents data for GetUserProfilePhotos method.
|
||||
type GetUserProfilePhotosParameters struct {
|
||||
// Unique identifier of the target user
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Sequential number of the first photo to be returned. By default, all
|
||||
// photos are returned.
|
||||
Offset int `json:"offset,omitempty"`
|
||||
|
||||
// Limits the number of photos to be retrieved. Values between 1—100 are
|
||||
// accepted. Defaults to 100.
|
||||
Limit int `json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
// GetUserProfilePhotos get a list of profile pictures for a user. Returns a UserProfilePhotos object.
|
||||
func (bot *Bot) GetUserProfilePhotos(params *GetUserProfilePhotosParameters) (photos *UserProfilePhotos, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetUserProfilePhotos)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
photos = new(UserProfilePhotos)
|
||||
err = json.Unmarshal(*resp.Result, photos)
|
||||
return
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// GetWebhookInfo get current webhook status. Requires no parameters. On success,
|
||||
// returns a WebhookInfo object. If the bot is using getUpdates, will return an
|
||||
// object with the url field empty.
|
||||
func (bot *Bot) GetWebhookInfo() (info *WebhookInfo, err error) {
|
||||
resp, err := bot.request(nil, MethodGetWebhookInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
info = new(WebhookInfo)
|
||||
err = json.Unmarshal(*resp.Result, info)
|
||||
return
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
@ -25,7 +26,7 @@ type KickChatMemberParameters struct {
|
|||
// Admins' setting is off in the target group. Otherwise members may only be removed by the group's
|
||||
// creator or by the member that added them.
|
||||
func (bot *Bot) KickChatMember(params *KickChatMemberParameters) (ok bool, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -35,6 +36,6 @@ func (bot *Bot) KickChatMember(params *KickChatMemberParameters) (ok bool, err e
|
|||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,311 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: kick.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *KickChatMemberParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *KickChatMemberParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteString(`,"user_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.UserID), 10, j.UserID < 0)
|
||||
buf.WriteString(`,"until_date":`)
|
||||
fflib.FormatBits2(buf, uint64(j.UntilDate), 10, j.UntilDate < 0)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtKickChatMemberParametersbase = iota
|
||||
ffjtKickChatMemberParametersnosuchkey
|
||||
|
||||
ffjtKickChatMemberParametersChatID
|
||||
|
||||
ffjtKickChatMemberParametersUserID
|
||||
|
||||
ffjtKickChatMemberParametersUntilDate
|
||||
)
|
||||
|
||||
var ffjKeyKickChatMemberParametersChatID = []byte("chat_id")
|
||||
|
||||
var ffjKeyKickChatMemberParametersUserID = []byte("user_id")
|
||||
|
||||
var ffjKeyKickChatMemberParametersUntilDate = []byte("until_date")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *KickChatMemberParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *KickChatMemberParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtKickChatMemberParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtKickChatMemberParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyKickChatMemberParametersChatID, kn) {
|
||||
currentKey = ffjtKickChatMemberParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'u':
|
||||
|
||||
if bytes.Equal(ffjKeyKickChatMemberParametersUserID, kn) {
|
||||
currentKey = ffjtKickChatMemberParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
|
||||
} else if bytes.Equal(ffjKeyKickChatMemberParametersUntilDate, kn) {
|
||||
currentKey = ffjtKickChatMemberParametersUntilDate
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyKickChatMemberParametersUntilDate, kn) {
|
||||
currentKey = ffjtKickChatMemberParametersUntilDate
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyKickChatMemberParametersUserID, kn) {
|
||||
currentKey = ffjtKickChatMemberParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyKickChatMemberParametersChatID, kn) {
|
||||
currentKey = ffjtKickChatMemberParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtKickChatMemberParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtKickChatMemberParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtKickChatMemberParametersUserID:
|
||||
goto handle_UserID
|
||||
|
||||
case ffjtKickChatMemberParametersUntilDate:
|
||||
goto handle_UntilDate
|
||||
|
||||
case ffjtKickChatMemberParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_UserID:
|
||||
|
||||
/* handler: j.UserID type=int kind=int quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.UserID = int(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_UntilDate:
|
||||
|
||||
/* handler: j.UntilDate type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.UntilDate = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
@ -10,7 +11,7 @@ type LeaveChatParameters struct {
|
|||
|
||||
// LeaveChat leave a group, supergroup or channel. Returns True on success.
|
||||
func (bot *Bot) LeaveChat(chatID int64) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&LeaveChatParameters{ChatID: chatID})
|
||||
dst, err := json.MarshalFast(&LeaveChatParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -20,6 +21,6 @@ func (bot *Bot) LeaveChat(chatID int64) (ok bool, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: leave.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *LeaveChatParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *LeaveChatParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtLeaveChatParametersbase = iota
|
||||
ffjtLeaveChatParametersnosuchkey
|
||||
|
||||
ffjtLeaveChatParametersChatID
|
||||
)
|
||||
|
||||
var ffjKeyLeaveChatParametersChatID = []byte("chat_id")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *LeaveChatParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *LeaveChatParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtLeaveChatParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtLeaveChatParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyLeaveChatParametersChatID, kn) {
|
||||
currentKey = ffjtLeaveChatParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyLeaveChatParametersChatID, kn) {
|
||||
currentKey = ffjtLeaveChatParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtLeaveChatParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtLeaveChatParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtLeaveChatParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
152
methods_games.go
152
methods_games.go
|
@ -1,152 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
type (
|
||||
// SendGameParameters represents data for SendGame method.
|
||||
SendGameParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Short name of the game, serves as the unique identifier for the game. Set
|
||||
// up your games via Botfather.
|
||||
GameShortName string `json:"game_short_name"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one ‘Play
|
||||
// game_title’ button will be shown. If not empty, the first button must
|
||||
// launch the game.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SetGameScoreParameters represents data for SetGameScore method.
|
||||
SetGameScoreParameters struct {
|
||||
// User identifier
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// New score, must be non-negative
|
||||
Score int `json:"score"`
|
||||
|
||||
// Required if inline_message_id is not specified. Identifier of the sent
|
||||
// message
|
||||
MessageID int `json:"message_id,omitempty"`
|
||||
|
||||
// Pass True, if the high score is allowed to decrease. This can be useful
|
||||
// when fixing mistakes or banning cheaters
|
||||
Force bool `json:"force,omitempty"`
|
||||
|
||||
// Pass True, if the game message should not be automatically edited to
|
||||
// include the current scoreboard
|
||||
DisableEditMessage bool `json:"disable_edit_message,omitempty"`
|
||||
|
||||
// Required if inline_message_id is not specified. Unique identifier for the
|
||||
// target chat
|
||||
ChatID int64 `json:"chat_id,omitempty"`
|
||||
|
||||
// Required if chat_id and message_id are not specified. Identifier of the
|
||||
// inline message
|
||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||
}
|
||||
|
||||
// GetGameHighScoresParameters represents data for GetGameHighScores method.
|
||||
GetGameHighScoresParameters struct {
|
||||
// Target user id
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Required if inline_message_id is not specified. Identifier of the sent
|
||||
// message
|
||||
MessageID int `json:"message_id,omitempty"`
|
||||
|
||||
// Required if inline_message_id is not specified. Unique identifier for the
|
||||
// target chat
|
||||
ChatID int64 `json:"chat_id,omitempty"`
|
||||
|
||||
// Required if chat_id and message_id are not specified. Identifier of the
|
||||
// inline message
|
||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
// NewGame creates SendGameParameters only with required parameters.
|
||||
func NewGame(chatID int64, gameShortName string) *SendGameParameters {
|
||||
return &SendGameParameters{
|
||||
ChatID: chatID,
|
||||
GameShortName: gameShortName,
|
||||
}
|
||||
}
|
||||
|
||||
// SendGame send a game. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendGame(params *SendGameParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendGame)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// NewGameScore creates SetGameScoreParameters only with required parameters.
|
||||
func NewGameScore(userID, score int) *SetGameScoreParameters {
|
||||
return &SetGameScoreParameters{
|
||||
UserID: userID,
|
||||
Score: score,
|
||||
}
|
||||
}
|
||||
|
||||
// SetGameScore set the score of the specified user in a game. On success, if the
|
||||
// message was sent by the bot, returns the edited Message, otherwise returns
|
||||
// True. Returns an error, if the new score is not greater than the user's
|
||||
// current score in the chat and force is False.
|
||||
func (bot *Bot) SetGameScore(params *SetGameScoreParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSetGameScore)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// NewGameHighScores creates GetGameHighScoresParameters only with required parameters.
|
||||
func NewGameHighScores(userID int) *GetGameHighScoresParameters {
|
||||
return &GetGameHighScoresParameters{
|
||||
UserID: userID,
|
||||
}
|
||||
}
|
||||
|
||||
// GetGameHighScores get data for high score tables. Will return the score of the
|
||||
// specified user and several of his neighbors in a game. On success, returns an
|
||||
// Array of GameHighScore objects.
|
||||
func (bot *Bot) GetGameHighScores(params *GetGameHighScoresParameters) (scores []GameHighScore, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetGameHighScores)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &scores)
|
||||
return
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// AnswerInlineQueryParameters represents data for AnswerInlineQuery method.
|
||||
type AnswerInlineQueryParameters struct {
|
||||
// Unique identifier for the answered query
|
||||
InlineQueryID string `json:"inline_query_id"`
|
||||
|
||||
// Pass the offset that a client should send in the next query with the same
|
||||
// text to receive more results. Pass an empty string if there are no more
|
||||
// results or if you don‘t support pagination. Offset length can’t exceed 64
|
||||
// bytes.
|
||||
NextOffset string `json:"next_offset,omitempty"`
|
||||
|
||||
// If passed, clients will display a button with specified text that switches
|
||||
// the user to a private chat with the bot and sends the bot a start message
|
||||
// with the parameter switch_pm_parameter
|
||||
SwitchPrivateMessageText string `json:"switch_pm_text,omitempty"`
|
||||
|
||||
// Deep-linking parameter for the /start message sent to the bot when user
|
||||
// presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and -
|
||||
// are allowed.
|
||||
SwitchPrivateMessageParameter string `json:"switch_pm_parameter,omitempty"`
|
||||
|
||||
// A JSON-serialized array of results for the inline query
|
||||
Results []interface{} `json:"results"`
|
||||
|
||||
// The maximum amount of time in seconds that the result of the inline query
|
||||
// may be cached on the server. Defaults to 300.
|
||||
CacheTime int `json:"cache_time,omitempty"`
|
||||
|
||||
// Pass True, if results may be cached on the server side only for the user
|
||||
// that sent the query. By default, results may be returned to any user who
|
||||
// sends the same query
|
||||
IsPersonal bool `json:"is_personal,omitempty"`
|
||||
}
|
||||
|
||||
// NewAnswerInlineQuery creates AnswerInlineQueryParameters only with required
|
||||
// parameters.
|
||||
func NewAnswerInlineQuery(inlineQueryID string, results ...interface{}) *AnswerInlineQueryParameters {
|
||||
return &AnswerInlineQueryParameters{
|
||||
InlineQueryID: inlineQueryID,
|
||||
Results: results,
|
||||
}
|
||||
}
|
||||
|
||||
// AnswerInlineQuery send answers to an inline query. On success, True is returned.
|
||||
//
|
||||
// No more than 50 results per query are allowed.
|
||||
func (bot *Bot) AnswerInlineQuery(params *AnswerInlineQueryParameters) (ok bool, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodAnswerInlineQuery)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,279 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
type (
|
||||
// SendStickerParameters represents data for SetSticker method.
|
||||
SendStickerParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Sticker to send
|
||||
Sticker interface{} `json:"sticker"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification
|
||||
// with no sound
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an
|
||||
// inline keyboard, custom reply keyboard, instructions to remove
|
||||
// reply keyboard or to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// GetStickerSetParameters represents data for GetStickerSet method.
|
||||
GetStickerSetParameters struct {
|
||||
// Name of the sticker set
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
UploadStickerFileParameters struct {
|
||||
// User identifier of sticker file owner
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Png image with the sticker, must be up to 512 kilobytes in size,
|
||||
// dimensions must not exceed 512px, and either width or height
|
||||
// must be exactly 512px.
|
||||
PNGSticker interface{} `json:"png_sticker"`
|
||||
}
|
||||
|
||||
CreateNewStickerSetParameters struct {
|
||||
// User identifier of created sticker set owner
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Short name of sticker set, to be used in t.me/addstickers/ URLs
|
||||
// (e.g., animals). Can contain only english letters, digits and
|
||||
// underscores. Must begin with a letter, can't contain consecutive
|
||||
// underscores and must end in “_by_<bot username>”. <bot_username>
|
||||
// is case insensitive. 1-64 characters.
|
||||
Name string `json:"name"`
|
||||
|
||||
// Sticker set title, 1-64 characters
|
||||
Title string `json:"title"`
|
||||
|
||||
// Png image with the sticker, must be up to 512 kilobytes in size,
|
||||
// dimensions must not exceed 512px, and either width or height must
|
||||
// be exactly 512px. Pass a file_id as a String to send a file that
|
||||
// already exists on the Telegram servers, pass an HTTP URL as a
|
||||
// String for Telegram to get a file from the Internet, or upload
|
||||
// a new one using multipart/form-data.
|
||||
PNGSticker interface{} `json:"png_sticker"`
|
||||
|
||||
// One or more emoji corresponding to the sticker
|
||||
Emojis string `json:"emojis"`
|
||||
|
||||
// Pass True, if a set of mask stickers should be created
|
||||
ContainsMasks bool `json:"contains_masks,omitempty"`
|
||||
|
||||
// A JSON-serialized object for position where the mask should be
|
||||
// placed on faces
|
||||
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
|
||||
}
|
||||
|
||||
AddStickerToSetParameters struct {
|
||||
// User identifier of sticker set owner
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Sticker set name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More info on Sending Files »
|
||||
PNGSticker interface{} `json:"png_sticker"`
|
||||
|
||||
// One or more emoji corresponding to the sticker
|
||||
Emojis string `json:"emojis"`
|
||||
|
||||
// A JSON-serialized object for position where the mask should be placed on faces
|
||||
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
|
||||
}
|
||||
|
||||
// SetStickerPositionInSetParameters represents data for SetStickerPositionInSet
|
||||
// method.
|
||||
SetStickerPositionInSetParameters struct {
|
||||
// File identifier of the sticker
|
||||
Sticker string `json:"sticker"`
|
||||
|
||||
// New sticker position in the set, zero-based
|
||||
Position int `json:"position"`
|
||||
}
|
||||
|
||||
// DeleteStickerFromSetParameters represents data for DeleteStickerFromSet method.
|
||||
DeleteStickerFromSetParameters struct {
|
||||
// File identifier of the sticker
|
||||
Sticker string `json:"sticker"`
|
||||
}
|
||||
)
|
||||
|
||||
// SendSticker send .webp stickers. On success, the sent Message is returned.
|
||||
func (b *Bot) SendSticker(params *SendStickerParameters) (*Message, error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Set("chat_id", strconv.FormatInt(params.ChatID, 10))
|
||||
args.Set("disable_notification", strconv.FormatBool(params.DisableNotification))
|
||||
if params.ReplyToMessageID > 0 {
|
||||
args.SetUint("reply_to_message_id", params.ReplyToMessageID)
|
||||
}
|
||||
if params.ReplyMarkup != nil {
|
||||
rm, err := json.Marshal(params.ReplyMarkup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
args.SetBytesV("reply_markup", rm)
|
||||
}
|
||||
|
||||
resp, err := b.Upload(MethodSendSticker, TypeSticker, "sticker", params.Sticker, args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var m Message
|
||||
err = json.Unmarshal(*resp.Result, &m)
|
||||
return &m, err
|
||||
}
|
||||
|
||||
// GetStickerSet get a sticker set. On success, a StickerSet object is returned.
|
||||
func (bot *Bot) GetStickerSet(name string) (set *StickerSet, err error) {
|
||||
dst, err := json.Marshal(&GetStickerSetParameters{Name: name})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodGetStickerSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
set = new(StickerSet)
|
||||
err = json.Unmarshal(*resp.Result, set)
|
||||
return
|
||||
}
|
||||
|
||||
// UploadStickerFile upload a .png file with a sticker for later use in
|
||||
// createNewStickerSet and addStickerToSet methods (can be used multiple times).
|
||||
// Returns the uploaded File on success.
|
||||
func (b *Bot) UploadStickerFile(userID int, pngSticker interface{}) (*File, error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.SetUint("user_id", userID)
|
||||
|
||||
resp, err := b.Upload(MethodUploadStickerFile, TypeSticker, "sticker", pngSticker, args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var f File
|
||||
err = json.Unmarshal(*resp.Result, &f)
|
||||
return &f, err
|
||||
}
|
||||
|
||||
// CreateNewStickerSet create new sticker set owned by a user. The bot will be
|
||||
// able to edit the created sticker set. Returns True on success.
|
||||
func (b *Bot) CreateNewStickerSet(params *CreateNewStickerSetParameters) (ok bool, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.SetUint("user_id", params.UserID)
|
||||
|
||||
if !strings.HasSuffix(strings.ToLower(params.Name), strings.ToLower("_by_"+b.Username)) {
|
||||
params.Name = params.Name + "_by_" + b.Username
|
||||
}
|
||||
|
||||
args.Set("name", params.Name)
|
||||
args.Set("title", params.Title)
|
||||
args.Set("emojis", params.Emojis)
|
||||
args.Set("contains_masks", strconv.FormatBool(params.ContainsMasks))
|
||||
|
||||
if params.MaskPosition != nil {
|
||||
mp, err := json.Marshal(params.MaskPosition)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
args.SetBytesV("mask_position", mp)
|
||||
}
|
||||
|
||||
resp, err := b.Upload(MethodCreateNewStickerSet, TypeSticker, "sticker", params.PNGSticker, args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// AddStickerToSet add a new sticker to a set created by the bot. Returns True
|
||||
// on success.
|
||||
func (b *Bot) AddStickerToSet(params *AddStickerToSetParameters) (ok bool, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.SetUint("user_id", params.UserID)
|
||||
|
||||
if !strings.HasSuffix(strings.ToLower(params.Name), strings.ToLower("_by_"+b.Username)) {
|
||||
params.Name = params.Name + "_by_" + b.Username
|
||||
}
|
||||
|
||||
args.Set("emojis", params.Emojis)
|
||||
|
||||
if params.MaskPosition != nil {
|
||||
mp, err := json.Marshal(params.MaskPosition)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
args.SetBytesV("mask_position", mp)
|
||||
}
|
||||
|
||||
resp, err := b.Upload(MethodAddStickerToSet, TypeSticker, "sticker", params.PNGSticker, args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// SetStickerPositionInSet move a sticker in a set created by the bot to a
|
||||
// specific position. Returns True on success.
|
||||
func (b *Bot) SetStickerPositionInSet(sticker string, position int) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&SetStickerPositionInSetParameters{
|
||||
Sticker: sticker,
|
||||
Position: position,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := b.request(dst, MethodSetStickerPositionInSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteStickerFromSet delete a sticker from a set created by the bot. Returns
|
||||
// True on success.
|
||||
func (bot *Bot) DeleteStickerFromSet(sticker string) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&DeleteStickerFromSetParameters{Sticker: sticker})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodDeleteStickerFromSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
@ -20,7 +21,7 @@ type PinChatMessageParameters struct {
|
|||
// chat for this to work and must have the 'can_pin_messages' admin right in the supergroup or
|
||||
// 'can_edit_messages' admin right in the channel. Returns True on success.
|
||||
func (bot *Bot) PinChatMessage(params *PinChatMessageParameters) (ok bool, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -30,6 +31,6 @@ func (bot *Bot) PinChatMessage(params *PinChatMessageParameters) (ok bool, err e
|
|||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,323 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: pin.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *PinChatMessageParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *PinChatMessageParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteString(`,"message_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.MessageID), 10, j.MessageID < 0)
|
||||
if j.DisableNotification {
|
||||
buf.WriteString(`,"disable_notification":true`)
|
||||
} else {
|
||||
buf.WriteString(`,"disable_notification":false`)
|
||||
}
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtPinChatMessageParametersbase = iota
|
||||
ffjtPinChatMessageParametersnosuchkey
|
||||
|
||||
ffjtPinChatMessageParametersChatID
|
||||
|
||||
ffjtPinChatMessageParametersMessageID
|
||||
|
||||
ffjtPinChatMessageParametersDisableNotification
|
||||
)
|
||||
|
||||
var ffjKeyPinChatMessageParametersChatID = []byte("chat_id")
|
||||
|
||||
var ffjKeyPinChatMessageParametersMessageID = []byte("message_id")
|
||||
|
||||
var ffjKeyPinChatMessageParametersDisableNotification = []byte("disable_notification")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *PinChatMessageParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *PinChatMessageParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtPinChatMessageParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtPinChatMessageParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyPinChatMessageParametersChatID, kn) {
|
||||
currentKey = ffjtPinChatMessageParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'd':
|
||||
|
||||
if bytes.Equal(ffjKeyPinChatMessageParametersDisableNotification, kn) {
|
||||
currentKey = ffjtPinChatMessageParametersDisableNotification
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'm':
|
||||
|
||||
if bytes.Equal(ffjKeyPinChatMessageParametersMessageID, kn) {
|
||||
currentKey = ffjtPinChatMessageParametersMessageID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyPinChatMessageParametersDisableNotification, kn) {
|
||||
currentKey = ffjtPinChatMessageParametersDisableNotification
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyPinChatMessageParametersMessageID, kn) {
|
||||
currentKey = ffjtPinChatMessageParametersMessageID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyPinChatMessageParametersChatID, kn) {
|
||||
currentKey = ffjtPinChatMessageParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtPinChatMessageParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtPinChatMessageParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtPinChatMessageParametersMessageID:
|
||||
goto handle_MessageID
|
||||
|
||||
case ffjtPinChatMessageParametersDisableNotification:
|
||||
goto handle_DisableNotification
|
||||
|
||||
case ffjtPinChatMessageParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_MessageID:
|
||||
|
||||
/* handler: j.MessageID type=int kind=int quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.MessageID = int(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_DisableNotification:
|
||||
|
||||
/* handler: j.DisableNotification type=bool kind=bool quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
tmpb := fs.Output.Bytes()
|
||||
|
||||
if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {
|
||||
|
||||
j.DisableNotification = true
|
||||
|
||||
} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {
|
||||
|
||||
j.DisableNotification = false
|
||||
|
||||
} else {
|
||||
err = errors.New("unexpected bytes for true/false value")
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
11
request.go
11
request.go
|
@ -5,7 +5,6 @@ import (
|
|||
"path"
|
||||
"strconv"
|
||||
|
||||
"github.com/kirillDanshin/dlog"
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
@ -38,16 +37,16 @@ func (bot *Bot) request(dst []byte, method string) (response *Response, err erro
|
|||
defer http.ReleaseResponse(resp)
|
||||
|
||||
err = bot.Client.Do(req, resp)
|
||||
dlog.Ln("Request:")
|
||||
dlog.D(req)
|
||||
dlog.Ln("Response:")
|
||||
dlog.D(resp)
|
||||
// dlog.Ln("Request:")
|
||||
// dlog.D(req)
|
||||
// dlog.Ln("Response:")
|
||||
// dlog.D(resp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
response = new(Response)
|
||||
if err = json.Unmarshal(resp.Body(), response); err != nil {
|
||||
if err = json.UnmarshalFast(resp.Body(), response); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,796 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
type (
|
||||
// SendAnimationParameters represents data for SendAnimation method.
|
||||
SendAnimationParameters struct {
|
||||
// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. More info on Sending Files »
|
||||
Animation InputFile `json:"animation"`
|
||||
|
||||
// Duration of sent animation in seconds
|
||||
Duration int `json:"duration,omitempty"`
|
||||
|
||||
// Animation width
|
||||
Width int `json:"width,omitempty"`
|
||||
|
||||
// Animation height
|
||||
Height int `json:"height,omitempty"`
|
||||
|
||||
// Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
|
||||
Thumb InputFile `json:"thumb,omitempty"`
|
||||
|
||||
// Animation caption (may also be used when resending animation by file_id), 0-200 characters
|
||||
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.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SendChatActionParameters represents data for SendChatAction method.
|
||||
SendChatActionParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Type of action to broadcast
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
// SendContactParameters represents data for SendContact method.
|
||||
SendContactParameters struct {
|
||||
// Unique identifier for the target private chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Contact's phone number
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
|
||||
// Contact's first name
|
||||
FirstName string `json:"first_name"`
|
||||
|
||||
// Contact's last name
|
||||
LastName string `json:"last_name"`
|
||||
|
||||
// Additional data about the contact in the form of a vCard, 0-2048 bytes
|
||||
VCard string `json:"vcard,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
|
||||
// price' button will be shown. If not empty, the first button must be a Pay
|
||||
// button.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SendDocumentParameters represents data for SendDocument method.
|
||||
SendDocumentParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// File to send. Pass a file_id as String to send a file that exists on the Telegram servers
|
||||
// (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or
|
||||
// upload a new one using multipart/form-data.
|
||||
Document InputFile `json:"document"`
|
||||
|
||||
// Document caption (may also be used when resending documents by file_id), 0-200 characters
|
||||
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.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply
|
||||
// keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SendInvoiceParameters represents data for SendInvoice method.
|
||||
SendInvoiceParameters struct {
|
||||
// Unique identifier for the target private chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Product name, 1-32 characters
|
||||
Title string `json:"title"`
|
||||
|
||||
// Product description, 1-255 characters
|
||||
Description string `json:"description"`
|
||||
|
||||
// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
|
||||
// the user, use for your internal processes.
|
||||
Payload string `json:"payload"`
|
||||
|
||||
// Payments provider token, obtained via Botfather
|
||||
ProviderToken string `json:"provider_token"`
|
||||
|
||||
// Unique deep-linking parameter that can be used to generate this invoice
|
||||
// when used as a start parameter
|
||||
StartParameter string `json:"start_parameter"`
|
||||
|
||||
// Three-letter ISO 4217 currency code, see more on currencies
|
||||
Currency string `json:"currency"`
|
||||
|
||||
// JSON-encoded data about the invoice, which will be shared with the payment
|
||||
// provider. A detailed description of required fields should be provided by
|
||||
// the payment provider.
|
||||
ProviderData string `json:"provider_data,omitempty"`
|
||||
|
||||
// URL of the product photo for the invoice. Can be a photo of the goods or a
|
||||
// marketing image for a service. People like it better when they see what
|
||||
// they are paying for.
|
||||
PhotoURL string `json:"photo_url,omitempty"`
|
||||
|
||||
// Price breakdown, a list of components (e.g. product price, tax, discount,
|
||||
// delivery cost, delivery tax, bonus, etc.)
|
||||
Prices []LabeledPrice `json:"prices"`
|
||||
|
||||
// Photo size
|
||||
PhotoSize int `json:"photo_size,omitempty"`
|
||||
|
||||
// Photo width
|
||||
PhotoWidth int `json:"photo_width,omitempty"`
|
||||
|
||||
// Photo height
|
||||
PhotoHeight int `json:"photo_height,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Pass True, if you require the user's full name to complete the order
|
||||
NeedName bool `json:"need_name,omitempty"`
|
||||
|
||||
// Pass True, if you require the user's phone number to complete the order
|
||||
NeedPhoneNumber bool `json:"need_phone_number,omitempty"`
|
||||
|
||||
// Pass True, if you require the user's email to complete the order
|
||||
NeedEmail bool `json:"need_email,omitempty"`
|
||||
|
||||
// Pass True, if you require the user's shipping address to complete the
|
||||
// order
|
||||
NeedShippingAddress bool `json:"need_shipping_address,omitempty"`
|
||||
|
||||
// Pass True, if the final price depends on the shipping method
|
||||
IsFlexible bool `json:"is_flexible,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
|
||||
// price' button will be shown. If not empty, the first button must be a Pay
|
||||
// button.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SendLocationParameters represents data for SendLocation method.
|
||||
SendLocationParameters struct {
|
||||
// Unique identifier for the target private chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Latitude of the location
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Longitude of the location
|
||||
Longitude float32 `json:"longitude"`
|
||||
|
||||
// Period in seconds for which the location will be updated (see Live
|
||||
// Locations), should be between 60 and 86400.
|
||||
LivePeriod int `json:"live_period,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
|
||||
// price' button will be shown. If not empty, the first button must be a Pay
|
||||
// button.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SendMediaGroupParameters represents data for SendMediaGroup method.
|
||||
SendMediaGroupParameters struct {
|
||||
// Unique identifier for the target chat.
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// A JSON-serialized array describing photos and videos to be sent, must
|
||||
// include 2–10 items
|
||||
Media []interface{} `json:"media"`
|
||||
|
||||
// Sends the messages silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the messages are a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
}
|
||||
|
||||
// SendMessageParameters represents data for SendMessage method.
|
||||
SendMessageParameters struct {
|
||||
// Unique identifier for the target chat or username of the target channel
|
||||
// (in the format @channelusername)
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Text of the message to be sent
|
||||
Text string `json:"text"`
|
||||
|
||||
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||
// fixed-width text or inline URLs in your bot's message.
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
|
||||
// Disables link previews for links in this message
|
||||
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline
|
||||
// keyboard, custom reply keyboard, instructions to remove reply keyboard or
|
||||
// to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SendPhotoParameters represents data for SendPhoto method.
|
||||
SendPhotoParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Photo to send. Pass a file_id as String to send a photo that exists on the
|
||||
// Telegram servers (recommended), pass an HTTP URL as a String for Telegram
|
||||
// to get a photo from the Internet, or upload a new photo using
|
||||
// multipart/form-data.
|
||||
Photo InputFile `json:"photo"`
|
||||
|
||||
// Photo caption (may also be used when resending photos by file_id), 0-200
|
||||
// characters
|
||||
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
|
||||
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline
|
||||
// keyboard, custom reply keyboard, instructions to remove reply keyboard or
|
||||
// to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
SendPollConfig struct {
|
||||
// Unique identifier for the target chat. A native poll can't be sent to a private chat.
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Poll question, 1-255 characters
|
||||
Question string `json:"question"`
|
||||
|
||||
// List of answer options, 2-10 strings 1-100 characters each
|
||||
Options []string `json:"options"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard,
|
||||
// instructions to remove reply keyboard or to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SendVenueParameters represents data for SendVenue method.
|
||||
SendVenueParameters struct {
|
||||
// Unique identifier for the target private chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Latitude of the venue
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Longitude of the venue
|
||||
Longitude float32 `json:"longitude"`
|
||||
|
||||
// Name of the venue
|
||||
Title string `json:"title"`
|
||||
|
||||
// Address of the venue
|
||||
Address string `json:"address"`
|
||||
|
||||
// Foursquare identifier of the venue
|
||||
FoursquareID string `json:"foursquare_id,omitempty"`
|
||||
|
||||
// Foursquare type of the venue, if known. (For example,
|
||||
// "arts_entertainment/default", "arts_entertainment/aquarium" or
|
||||
// "food/icecream".)
|
||||
FoursquareType string `json:"foursquare_type,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
|
||||
// price' button will be shown. If not empty, the first button must be a Pay
|
||||
// button.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SendGameParameters represents data for SendGame method.
|
||||
SendGameParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Short name of the game, serves as the unique identifier for the game. Set
|
||||
// up your games via Botfather.
|
||||
GameShortName string `json:"game_short_name"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one ‘Play
|
||||
// game_title’ button will be shown. If not empty, the first button must
|
||||
// launch the game.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// SendStickerParameters represents data for SetSticker method.
|
||||
SendStickerParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Sticker to send
|
||||
Sticker interface{} `json:"sticker"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification
|
||||
// with no sound
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an
|
||||
// inline keyboard, custom reply keyboard, instructions to remove
|
||||
// reply keyboard or to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
// NewAnimation creates SendAnimationParameters only with required parameters.
|
||||
func NewAnimation(chatID int64, animation interface{}) *SendAnimationParameters {
|
||||
return &SendAnimationParameters{
|
||||
ChatID: chatID,
|
||||
Animation: animation,
|
||||
}
|
||||
}
|
||||
|
||||
// NewContact creates SendContactParameters only with required parameters.
|
||||
func NewContact(chatID int64, phoneNumber, firstName string) *SendContactParameters {
|
||||
return &SendContactParameters{
|
||||
ChatID: chatID,
|
||||
PhoneNumber: phoneNumber,
|
||||
FirstName: firstName,
|
||||
}
|
||||
}
|
||||
|
||||
// NewDocument creates SendDocumentParameters only with required parameters.
|
||||
func NewDocument(chatID int64, document interface{}) *SendDocumentParameters {
|
||||
return &SendDocumentParameters{
|
||||
ChatID: chatID,
|
||||
Document: document,
|
||||
}
|
||||
}
|
||||
|
||||
// NewInvoice creates SendInvoiceParameters only with required parameters.
|
||||
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices ...LabeledPrice) *SendInvoiceParameters {
|
||||
return &SendInvoiceParameters{
|
||||
ChatID: chatID,
|
||||
Title: title,
|
||||
Description: description,
|
||||
Payload: payload,
|
||||
ProviderToken: providerToken,
|
||||
StartParameter: startParameter,
|
||||
Currency: currency,
|
||||
Prices: prices,
|
||||
}
|
||||
}
|
||||
|
||||
// NewLocation creates SendLocationParameters only with required parameters.
|
||||
func NewLocation(chatID int64, latitude, longitude float32) *SendLocationParameters {
|
||||
return &SendLocationParameters{
|
||||
ChatID: chatID,
|
||||
Latitude: latitude,
|
||||
Longitude: longitude,
|
||||
}
|
||||
}
|
||||
|
||||
// NewMediaGroup creates SendMediaGroupParameters only with required parameters.
|
||||
func NewMediaGroup(chatID int64, media ...interface{}) *SendMediaGroupParameters {
|
||||
return &SendMediaGroupParameters{
|
||||
ChatID: chatID,
|
||||
Media: media,
|
||||
}
|
||||
}
|
||||
|
||||
// NewMessage creates SendMessageParameters only with required parameters.
|
||||
func NewMessage(chatID int64, text string) *SendMessageParameters {
|
||||
return &SendMessageParameters{
|
||||
ChatID: chatID,
|
||||
Text: text,
|
||||
}
|
||||
}
|
||||
|
||||
// NewPhoto creates SendPhotoParameters only with required parameters.
|
||||
func NewPhoto(chatID int64, photo interface{}) *SendPhotoParameters {
|
||||
return &SendPhotoParameters{
|
||||
ChatID: chatID,
|
||||
Photo: photo,
|
||||
}
|
||||
}
|
||||
|
||||
func NewPoll(chatID int64, question string, options ...string) SendPollConfig {
|
||||
return SendPollConfig{
|
||||
ChatID: chatID,
|
||||
Question: question,
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
|
||||
// NewVenue creates SendVenueParameters only with required parameters.
|
||||
func NewVenue(chatID int64, latitude, longitude float32, title, address string) *SendVenueParameters {
|
||||
return &SendVenueParameters{
|
||||
ChatID: chatID,
|
||||
Latitude: latitude,
|
||||
Longitude: longitude,
|
||||
Title: title,
|
||||
Address: address,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGame creates SendGameParameters only with required parameters.
|
||||
func NewGame(chatID int64, gameShortName string) *SendGameParameters {
|
||||
return &SendGameParameters{
|
||||
ChatID: chatID,
|
||||
GameShortName: gameShortName,
|
||||
}
|
||||
}
|
||||
|
||||
// SendAnimation send animation files (GIF or H.264/MPEG-4 AVC video without
|
||||
// sound). On success, the sent Message is returned. Bots can currently send
|
||||
// animation files of up to 50 MB in size, this limit may be changed in the
|
||||
// future.
|
||||
func (bot *Bot) SendAnimation(params *SendAnimationParameters) (msg *Message, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(params.ChatID, 10))
|
||||
|
||||
if params.Caption != "" {
|
||||
args.Add("caption", params.Caption)
|
||||
}
|
||||
|
||||
if params.ReplyMarkup != nil {
|
||||
dst, err := json.MarshalFast(params.ReplyMarkup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args.Add("reply_markup", string(dst))
|
||||
}
|
||||
|
||||
if params.ReplyToMessageID != 0 {
|
||||
args.Add("reply_to_message_id", strconv.Itoa(params.ReplyToMessageID))
|
||||
}
|
||||
|
||||
args.Add("disable_notification", strconv.FormatBool(params.DisableNotification))
|
||||
|
||||
resp, err := bot.Upload(MethodSendAnimation, "animation", "", params.Animation, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SendChatAction tell the user that something is happening on the bot's side.
|
||||
// The status is set for 5 seconds or less (when a message arrives from your bot,
|
||||
// Telegram clients clear its typing status). Returns True on success.
|
||||
//
|
||||
// We only recommend using this method when a response from the bot will take a
|
||||
// noticeable amount of time to arrive.
|
||||
func (bot *Bot) SendChatAction(chatID int64, action string) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&SendChatActionParameters{
|
||||
ChatID: chatID,
|
||||
Action: action,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendChatAction)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// SendContact send phone contacts. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendContact(params *SendContactParameters) (msg *Message, err error) {
|
||||
dst, err := json.MarshalFast(*params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendContact)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SendDocument send general files. On success, the sent Message is returned. Bots can currently send
|
||||
// files of any type of up to 50 MB in size, this limit may be changed in the future.
|
||||
func (bot *Bot) SendDocument(params *SendDocumentParameters) (msg *Message, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(params.ChatID, 10))
|
||||
|
||||
if params.Caption != "" {
|
||||
args.Add("caption", params.Caption)
|
||||
}
|
||||
|
||||
if params.ReplyMarkup != nil {
|
||||
dst, err := json.MarshalFast(params.ReplyMarkup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args.Add("reply_markup", string(dst))
|
||||
}
|
||||
|
||||
if params.ReplyToMessageID != 0 {
|
||||
args.Add("reply_to_message_id", strconv.Itoa(params.ReplyToMessageID))
|
||||
}
|
||||
|
||||
args.Add("disable_notification", strconv.FormatBool(params.DisableNotification))
|
||||
|
||||
resp, err := bot.Upload(MethodSendDocument, "document", "", params.Document, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SendInvoice send invoices. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendInvoice(params *SendInvoiceParameters) (msg *Message, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendInvoice)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SendLocation send point on the map. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendLocation(params *SendLocationParameters) (msg *Message, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendLocation)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SendMediaGroup send a group of photos or videos as an album. On success, an array of the sent
|
||||
// Messages is returned.
|
||||
func (bot *Bot) SendMediaGroup(params *SendMediaGroupParameters) (album []Message, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendMediaGroup)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &album)
|
||||
return
|
||||
}
|
||||
|
||||
// SendMessage send text messages. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendMessage(params *SendMessageParameters) (msg *Message, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendMessage)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SendPhoto send photos. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendPhoto(params *SendPhotoParameters) (msg *Message, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(params.ChatID, 10))
|
||||
|
||||
if params.Caption != "" {
|
||||
args.Add("caption", params.Caption)
|
||||
}
|
||||
|
||||
if params.ReplyMarkup != nil {
|
||||
dst, err := json.MarshalFast(params.ReplyMarkup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args.Add("reply_markup", string(dst))
|
||||
}
|
||||
|
||||
if params.ReplyToMessageID != 0 {
|
||||
args.Add("reply_to_message_id", strconv.Itoa(params.ReplyToMessageID))
|
||||
}
|
||||
|
||||
args.Add("disable_notification", strconv.FormatBool(params.DisableNotification))
|
||||
|
||||
resp, err := bot.Upload(MethodSendPhoto, "photo", "", params.Photo, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SendPoll send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is
|
||||
// returned.
|
||||
func (b *Bot) SendPoll(params SendPollConfig) (*Message, error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := b.request(dst, MethodSendPoll)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var msg Message
|
||||
err = json.UnmarshalFast(*resp.Result, &msg)
|
||||
return &msg, err
|
||||
}
|
||||
|
||||
// SendVenue send information about a venue. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendVenue(params *SendVenueParameters) (msg *Message, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendVenue)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SendGame send a game. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendGame(params *SendGameParameters) (msg *Message, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendGame)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SendSticker send .webp stickers. On success, the sent Message is returned.
|
||||
func (b *Bot) SendSticker(params *SendStickerParameters) (*Message, error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Set("chat_id", strconv.FormatInt(params.ChatID, 10))
|
||||
args.Set("disable_notification", strconv.FormatBool(params.DisableNotification))
|
||||
if params.ReplyToMessageID > 0 {
|
||||
args.SetUint("reply_to_message_id", params.ReplyToMessageID)
|
||||
}
|
||||
if params.ReplyMarkup != nil {
|
||||
rm, err := json.MarshalFast(params.ReplyMarkup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
args.SetBytesV("reply_markup", rm)
|
||||
}
|
||||
|
||||
resp, err := b.Upload(MethodSendSticker, TypeSticker, "sticker", params.Sticker, args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var m Message
|
||||
err = json.UnmarshalFast(*resp.Result, &m)
|
||||
return &m, err
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// SendAnimationParameters represents data for SendAnimation method.
|
||||
type SendAnimationParameters struct {
|
||||
// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. More info on Sending Files »
|
||||
Animation InputFile `json:"animation"`
|
||||
|
||||
// Duration of sent animation in seconds
|
||||
Duration int `json:"duration,omitempty"`
|
||||
|
||||
// Animation width
|
||||
Width int `json:"width,omitempty"`
|
||||
|
||||
// Animation height
|
||||
Height int `json:"height,omitempty"`
|
||||
|
||||
// Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
|
||||
Thumb InputFile `json:"thumb,omitempty"`
|
||||
|
||||
// Animation caption (may also be used when resending animation by file_id), 0-200 characters
|
||||
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.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// NewAnimation creates SendAnimationParameters only with required parameters.
|
||||
func NewAnimation(chatID int64, animation interface{}) *SendAnimationParameters {
|
||||
return &SendAnimationParameters{
|
||||
ChatID: chatID,
|
||||
Animation: animation,
|
||||
}
|
||||
}
|
||||
|
||||
// SendAnimation send animation files (GIF or H.264/MPEG-4 AVC video without
|
||||
// sound). On success, the sent Message is returned. Bots can currently send
|
||||
// animation files of up to 50 MB in size, this limit may be changed in the
|
||||
// future.
|
||||
func (bot *Bot) SendAnimation(params *SendAnimationParameters) (msg *Message, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(params.ChatID, 10))
|
||||
|
||||
if params.Caption != "" {
|
||||
args.Add("caption", params.Caption)
|
||||
}
|
||||
|
||||
if params.ReplyMarkup != nil {
|
||||
dst, err := json.Marshal(params.ReplyMarkup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args.Add("reply_markup", string(dst))
|
||||
}
|
||||
|
||||
if params.ReplyToMessageID != 0 {
|
||||
args.Add("reply_to_message_id", strconv.Itoa(params.ReplyToMessageID))
|
||||
}
|
||||
|
||||
args.Add("disable_notification", strconv.FormatBool(params.DisableNotification))
|
||||
|
||||
resp, err := bot.Upload(MethodSendAnimation, "animation", "", params.Animation, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SendChatActionParameters represents data for SendChatAction method.
|
||||
type SendChatActionParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Type of action to broadcast
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
// SendChatAction tell the user that something is happening on the bot's side.
|
||||
// The status is set for 5 seconds or less (when a message arrives from your bot,
|
||||
// Telegram clients clear its typing status). Returns True on success.
|
||||
//
|
||||
// We only recommend using this method when a response from the bot will take a
|
||||
// noticeable amount of time to arrive.
|
||||
func (bot *Bot) SendChatAction(chatID int64, action string) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&SendChatActionParameters{
|
||||
ChatID: chatID,
|
||||
Action: action,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendChatAction)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SendContactParameters represents data for SendContact method.
|
||||
type SendContactParameters struct {
|
||||
// Unique identifier for the target private chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Contact's phone number
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
|
||||
// Contact's first name
|
||||
FirstName string `json:"first_name"`
|
||||
|
||||
// Contact's last name
|
||||
LastName string `json:"last_name"`
|
||||
|
||||
// Additional data about the contact in the form of a vCard, 0-2048 bytes
|
||||
VCard string `json:"vcard,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
|
||||
// price' button will be shown. If not empty, the first button must be a Pay
|
||||
// button.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// NewContact creates SendContactParameters only with required parameters.
|
||||
func NewContact(chatID int64, phoneNumber, firstName string) *SendContactParameters {
|
||||
return &SendContactParameters{
|
||||
ChatID: chatID,
|
||||
PhoneNumber: phoneNumber,
|
||||
FirstName: firstName,
|
||||
}
|
||||
}
|
||||
|
||||
// SendContact send phone contacts. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendContact(params *SendContactParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(*params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendContact)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// SendDocumentParameters represents data for SendDocument method.
|
||||
type SendDocumentParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// File to send. Pass a file_id as String to send a file that exists on the Telegram servers
|
||||
// (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or
|
||||
// upload a new one using multipart/form-data.
|
||||
Document InputFile `json:"document"`
|
||||
|
||||
// Document caption (may also be used when resending documents by file_id), 0-200 characters
|
||||
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.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply
|
||||
// keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// NewDocument creates SendDocumentParameters only with required parameters.
|
||||
func NewDocument(chatID int64, document interface{}) *SendDocumentParameters {
|
||||
return &SendDocumentParameters{
|
||||
ChatID: chatID,
|
||||
Document: document,
|
||||
}
|
||||
}
|
||||
|
||||
// SendDocument send general files. On success, the sent Message is returned. Bots can currently send
|
||||
// files of any type of up to 50 MB in size, this limit may be changed in the future.
|
||||
func (bot *Bot) SendDocument(params *SendDocumentParameters) (msg *Message, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(params.ChatID, 10))
|
||||
|
||||
if params.Caption != "" {
|
||||
args.Add("caption", params.Caption)
|
||||
}
|
||||
|
||||
if params.ReplyMarkup != nil {
|
||||
dst, err := json.Marshal(params.ReplyMarkup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args.Add("reply_markup", string(dst))
|
||||
}
|
||||
|
||||
if params.ReplyToMessageID != 0 {
|
||||
args.Add("reply_to_message_id", strconv.Itoa(params.ReplyToMessageID))
|
||||
}
|
||||
|
||||
args.Add("disable_notification", strconv.FormatBool(params.DisableNotification))
|
||||
|
||||
resp, err := bot.Upload(MethodSendDocument, "document", "", params.Document, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
File diff suppressed because it is too large
Load Diff
111
send_invoice.go
111
send_invoice.go
|
@ -1,111 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SendInvoiceParameters represents data for SendInvoice method.
|
||||
type SendInvoiceParameters struct {
|
||||
// Unique identifier for the target private chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Product name, 1-32 characters
|
||||
Title string `json:"title"`
|
||||
|
||||
// Product description, 1-255 characters
|
||||
Description string `json:"description"`
|
||||
|
||||
// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
|
||||
// the user, use for your internal processes.
|
||||
Payload string `json:"payload"`
|
||||
|
||||
// Payments provider token, obtained via Botfather
|
||||
ProviderToken string `json:"provider_token"`
|
||||
|
||||
// Unique deep-linking parameter that can be used to generate this invoice
|
||||
// when used as a start parameter
|
||||
StartParameter string `json:"start_parameter"`
|
||||
|
||||
// Three-letter ISO 4217 currency code, see more on currencies
|
||||
Currency string `json:"currency"`
|
||||
|
||||
// JSON-encoded data about the invoice, which will be shared with the payment
|
||||
// provider. A detailed description of required fields should be provided by
|
||||
// the payment provider.
|
||||
ProviderData string `json:"provider_data,omitempty"`
|
||||
|
||||
// URL of the product photo for the invoice. Can be a photo of the goods or a
|
||||
// marketing image for a service. People like it better when they see what
|
||||
// they are paying for.
|
||||
PhotoURL string `json:"photo_url,omitempty"`
|
||||
|
||||
// Price breakdown, a list of components (e.g. product price, tax, discount,
|
||||
// delivery cost, delivery tax, bonus, etc.)
|
||||
Prices []LabeledPrice `json:"prices"`
|
||||
|
||||
// Photo size
|
||||
PhotoSize int `json:"photo_size,omitempty"`
|
||||
|
||||
// Photo width
|
||||
PhotoWidth int `json:"photo_width,omitempty"`
|
||||
|
||||
// Photo height
|
||||
PhotoHeight int `json:"photo_height,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Pass True, if you require the user's full name to complete the order
|
||||
NeedName bool `json:"need_name,omitempty"`
|
||||
|
||||
// Pass True, if you require the user's phone number to complete the order
|
||||
NeedPhoneNumber bool `json:"need_phone_number,omitempty"`
|
||||
|
||||
// Pass True, if you require the user's email to complete the order
|
||||
NeedEmail bool `json:"need_email,omitempty"`
|
||||
|
||||
// Pass True, if you require the user's shipping address to complete the
|
||||
// order
|
||||
NeedShippingAddress bool `json:"need_shipping_address,omitempty"`
|
||||
|
||||
// Pass True, if the final price depends on the shipping method
|
||||
IsFlexible bool `json:"is_flexible,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
|
||||
// price' button will be shown. If not empty, the first button must be a Pay
|
||||
// button.
|
||||
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 {
|
||||
return &SendInvoiceParameters{
|
||||
ChatID: chatID,
|
||||
Title: title,
|
||||
Description: description,
|
||||
Payload: payload,
|
||||
ProviderToken: providerToken,
|
||||
StartParameter: startParameter,
|
||||
Currency: currency,
|
||||
Prices: prices,
|
||||
}
|
||||
}
|
||||
|
||||
// SendInvoice send invoices. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendInvoice(params *SendInvoiceParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendInvoice)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SendLocationParameters represents data for SendLocation method.
|
||||
type SendLocationParameters struct {
|
||||
// Unique identifier for the target private chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Latitude of the location
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Longitude of the location
|
||||
Longitude float32 `json:"longitude"`
|
||||
|
||||
// Period in seconds for which the location will be updated (see Live
|
||||
// Locations), should be between 60 and 86400.
|
||||
LivePeriod int `json:"live_period,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
|
||||
// price' button will be shown. If not empty, the first button must be a Pay
|
||||
// button.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// NewLocation creates SendLocationParameters only with required parameters.
|
||||
func NewLocation(chatID int64, latitude, longitude float32) *SendLocationParameters {
|
||||
return &SendLocationParameters{
|
||||
ChatID: chatID,
|
||||
Latitude: latitude,
|
||||
Longitude: longitude,
|
||||
}
|
||||
}
|
||||
|
||||
// SendLocation send point on the map. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendLocation(params *SendLocationParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendLocation)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SendMediaGroupParameters represents data for SendMediaGroup method.
|
||||
type SendMediaGroupParameters struct {
|
||||
// Unique identifier for the target chat.
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// A JSON-serialized array describing photos and videos to be sent, must
|
||||
// include 2–10 items
|
||||
Media []interface{} `json:"media"`
|
||||
|
||||
// Sends the messages silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the messages are a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
}
|
||||
|
||||
// NewMediaGroup creates SendMediaGroupParameters only with required parameters.
|
||||
func NewMediaGroup(chatID int64, media ...interface{}) *SendMediaGroupParameters {
|
||||
return &SendMediaGroupParameters{
|
||||
ChatID: chatID,
|
||||
Media: media,
|
||||
}
|
||||
}
|
||||
|
||||
// SendMediaGroup send a group of photos or videos as an album. On success, an array of the sent
|
||||
// Messages is returned.
|
||||
func (bot *Bot) SendMediaGroup(params *SendMediaGroupParameters) (album []Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendMediaGroup)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &album)
|
||||
return
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SendMessageParameters represents data for SendMessage method.
|
||||
type SendMessageParameters struct {
|
||||
// Unique identifier for the target chat or username of the target channel
|
||||
// (in the format @channelusername)
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Text of the message to be sent
|
||||
Text string `json:"text"`
|
||||
|
||||
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||
// fixed-width text or inline URLs in your bot's message.
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
|
||||
// Disables link previews for links in this message
|
||||
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline
|
||||
// keyboard, custom reply keyboard, instructions to remove reply keyboard or
|
||||
// to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// NewMessage creates SendMessageParameters only with required parameters.
|
||||
func NewMessage(chatID int64, text string) *SendMessageParameters {
|
||||
return &SendMessageParameters{
|
||||
ChatID: chatID,
|
||||
Text: text,
|
||||
}
|
||||
}
|
||||
|
||||
// SendMessage send text messages. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendMessage(params *SendMessageParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendMessage)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// SendPhotoParameters represents data for SendPhoto method.
|
||||
type SendPhotoParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Photo to send. Pass a file_id as String to send a photo that exists on the
|
||||
// Telegram servers (recommended), pass an HTTP URL as a String for Telegram
|
||||
// to get a photo from the Internet, or upload a new photo using
|
||||
// multipart/form-data.
|
||||
Photo InputFile `json:"photo"`
|
||||
|
||||
// Photo caption (may also be used when resending photos by file_id), 0-200
|
||||
// characters
|
||||
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
|
||||
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline
|
||||
// keyboard, custom reply keyboard, instructions to remove reply keyboard or
|
||||
// to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// NewPhoto creates SendPhotoParameters only with required parameters.
|
||||
func NewPhoto(chatID int64, photo interface{}) *SendPhotoParameters {
|
||||
return &SendPhotoParameters{
|
||||
ChatID: chatID,
|
||||
Photo: photo,
|
||||
}
|
||||
}
|
||||
|
||||
// SendPhoto send photos. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendPhoto(params *SendPhotoParameters) (msg *Message, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(params.ChatID, 10))
|
||||
|
||||
if params.Caption != "" {
|
||||
args.Add("caption", params.Caption)
|
||||
}
|
||||
|
||||
if params.ReplyMarkup != nil {
|
||||
dst, err := json.Marshal(params.ReplyMarkup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args.Add("reply_markup", string(dst))
|
||||
}
|
||||
|
||||
if params.ReplyToMessageID != 0 {
|
||||
args.Add("reply_to_message_id", strconv.Itoa(params.ReplyToMessageID))
|
||||
}
|
||||
|
||||
args.Add("disable_notification", strconv.FormatBool(params.DisableNotification))
|
||||
|
||||
resp, err := bot.Upload(MethodSendPhoto, "photo", "", params.Photo, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
50
send_poll.go
50
send_poll.go
|
@ -1,50 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
type SendPollConfig struct {
|
||||
// Unique identifier for the target chat. A native poll can't be sent to a private chat.
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Poll question, 1-255 characters
|
||||
Question string `json:"question"`
|
||||
|
||||
// List of answer options, 2-10 strings 1-100 characters each
|
||||
Options []string `json:"options"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard,
|
||||
// instructions to remove reply keyboard or to force a reply from the user.
|
||||
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
func NewPoll(chatID int64, question string, options ...string) SendPollConfig {
|
||||
return SendPollConfig{
|
||||
ChatID: chatID,
|
||||
Question: question,
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
|
||||
// SendPoll send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is
|
||||
// returned.
|
||||
func (b *Bot) SendPoll(params SendPollConfig) (*Message, error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := b.request(dst, MethodSendPoll)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var msg Message
|
||||
err = json.Unmarshal(*resp.Result, &msg)
|
||||
return &msg, err
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SendVenueParameters represents data for SendVenue method.
|
||||
type SendVenueParameters struct {
|
||||
// Unique identifier for the target private chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Latitude of the venue
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Longitude of the venue
|
||||
Longitude float32 `json:"longitude"`
|
||||
|
||||
// Name of the venue
|
||||
Title string `json:"title"`
|
||||
|
||||
// Address of the venue
|
||||
Address string `json:"address"`
|
||||
|
||||
// Foursquare identifier of the venue
|
||||
FoursquareID string `json:"foursquare_id,omitempty"`
|
||||
|
||||
// Foursquare type of the venue, if known. (For example,
|
||||
// "arts_entertainment/default", "arts_entertainment/aquarium" or
|
||||
// "food/icecream".)
|
||||
FoursquareType string `json:"foursquare_type,omitempty"`
|
||||
|
||||
// Sends the message silently. Users will receive a notification with no
|
||||
// sound.
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
|
||||
// If the message is a reply, ID of the original message
|
||||
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||
|
||||
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
|
||||
// price' button will be shown. If not empty, the first button must be a Pay
|
||||
// button.
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// NewVenue creates SendVenueParameters only with required parameters.
|
||||
func NewVenue(chatID int64, latitude, longitude float32, title, address string) *SendVenueParameters {
|
||||
return &SendVenueParameters{
|
||||
ChatID: chatID,
|
||||
Latitude: latitude,
|
||||
Longitude: longitude,
|
||||
Title: title,
|
||||
Address: address,
|
||||
}
|
||||
}
|
||||
|
||||
// SendVenue send information about a venue. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendVenue(params *SendVenueParameters) (msg *Message, err error) {
|
||||
dst, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSendVenue)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.Unmarshal(*resp.Result, msg)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,337 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
type (
|
||||
// SetChatDescriptionParameters represents data for SetChatDescription method.
|
||||
SetChatDescriptionParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// New chat description, 0-255 characters
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// SetChatPhotoParameters represents data for SetChatPhoto method.
|
||||
SetChatPhotoParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// New chat photo, uploaded using multipart/form-data
|
||||
ChatPhoto interface{} `json:"chat_photo"`
|
||||
}
|
||||
|
||||
// SetChatStickerSetParameters represents data for SetChatStickerSet method.
|
||||
SetChatStickerSetParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Name of the sticker set to be set as the group sticker set
|
||||
StickerSetName string `json:"sticker_set_name"`
|
||||
}
|
||||
|
||||
// SetChatTitleParameters represents data for SetChatTitle method.
|
||||
SetChatTitleParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// New chat title, 1-255 characters
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
SetPassportDataErrorsParameters struct {
|
||||
// User identifier
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// A JSON-serialized array describing the errors
|
||||
Errors []PassportElementError `json:"errors"`
|
||||
}
|
||||
|
||||
// SetWebhookParameters represents data for SetWebhook method.
|
||||
SetWebhookParameters struct {
|
||||
// HTTPS url to send updates to. Use an empty string to remove webhook
|
||||
// integration
|
||||
URL string `json:"url"`
|
||||
|
||||
// Upload your public key certificate so that the root certificate in use can
|
||||
// be checked. See our self-signed guide for details.
|
||||
Certificate InputFile `json:"certificate,omitempty"`
|
||||
|
||||
// Maximum allowed number of simultaneous HTTPS connections to the webhook
|
||||
// for update delivery, 1-100. Defaults to 40. Use lower values to limit the
|
||||
// load on your bot‘s server, and higher values to increase your bot’s
|
||||
// throughput.
|
||||
MaxConnections int `json:"max_connections,omitempty"`
|
||||
|
||||
// List the types of updates you want your bot to receive. For example,
|
||||
// specify [“message”, “edited_channel_post”, “callback_query”] to only
|
||||
// receive updates of these types. See Update for a complete list of
|
||||
// available update types. Specify an empty list to receive all updates
|
||||
// regardless of type (default). If not specified, the previous setting will
|
||||
// be used.
|
||||
//
|
||||
// Please note that this parameter doesn't affect updates created before the
|
||||
// call to the setWebhook, so unwanted updates may be received for a short
|
||||
// period of time.
|
||||
AllowedUpdates []string `json:"allowed_updates,omitempty"`
|
||||
}
|
||||
|
||||
// SetGameScoreParameters represents data for SetGameScore method.
|
||||
SetGameScoreParameters struct {
|
||||
// User identifier
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// New score, must be non-negative
|
||||
Score int `json:"score"`
|
||||
|
||||
// Required if inline_message_id is not specified. Identifier of the sent
|
||||
// message
|
||||
MessageID int `json:"message_id,omitempty"`
|
||||
|
||||
// Pass True, if the high score is allowed to decrease. This can be useful
|
||||
// when fixing mistakes or banning cheaters
|
||||
Force bool `json:"force,omitempty"`
|
||||
|
||||
// Pass True, if the game message should not be automatically edited to
|
||||
// include the current scoreboard
|
||||
DisableEditMessage bool `json:"disable_edit_message,omitempty"`
|
||||
|
||||
// Required if inline_message_id is not specified. Unique identifier for the
|
||||
// target chat
|
||||
ChatID int64 `json:"chat_id,omitempty"`
|
||||
|
||||
// Required if chat_id and message_id are not specified. Identifier of the
|
||||
// inline message
|
||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||
}
|
||||
|
||||
// SetStickerPositionInSetParameters represents data for SetStickerPositionInSet
|
||||
// method.
|
||||
SetStickerPositionInSetParameters struct {
|
||||
// File identifier of the sticker
|
||||
Sticker string `json:"sticker"`
|
||||
|
||||
// New sticker position in the set, zero-based
|
||||
Position int `json:"position"`
|
||||
}
|
||||
)
|
||||
|
||||
// NewWebhook creates new SetWebhookParameters only with required parameters.
|
||||
func NewWebhook(url string, file interface{}) *SetWebhookParameters {
|
||||
return &SetWebhookParameters{
|
||||
URL: url,
|
||||
Certificate: file,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGameScore creates SetGameScoreParameters only with required parameters.
|
||||
func NewGameScore(userID, score int) *SetGameScoreParameters {
|
||||
return &SetGameScoreParameters{
|
||||
UserID: userID,
|
||||
Score: score,
|
||||
}
|
||||
}
|
||||
|
||||
// SetChatDescription change the description of a supergroup or a channel. The
|
||||
// bot must be an administrator in the chat for this to work and must have the
|
||||
// appropriate admin rights. Returns True on success.
|
||||
func (bot *Bot) SetChatDescription(chatID int64, description string) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&SetChatDescriptionParameters{
|
||||
ChatID: chatID,
|
||||
Description: description,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSetChatDescription)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// SetChatPhoto set a new profile photo for the chat. Photos can't be changed for private chats. The
|
||||
// bot must be an administrator in the chat for this to work and must have the appropriate admin
|
||||
// rights. Returns True on success.
|
||||
//
|
||||
// Note: In regular groups (non-supergroups), this method will only work if the 'All Members Are
|
||||
// Admins' setting is off in the target group.
|
||||
func (bot *Bot) SetChatPhoto(chatID int64, chatPhoto interface{}) (ok bool, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.Upload(MethodSetChatPhoto, TypePhoto, "chat_photo", chatPhoto, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// SetChatStickerSet set a new group sticker set for a supergroup. The bot must be an administrator
|
||||
// in the chat for this to work and must have the appropriate admin rights. Use the field
|
||||
// can_set_sticker_set optionally returned in getChat requests to check if the bot can use this
|
||||
// method. Returns True on success.
|
||||
func (bot *Bot) SetChatStickerSet(chatID int64, stickerSetName string) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&SetChatStickerSetParameters{
|
||||
ChatID: chatID,
|
||||
StickerSetName: stickerSetName,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSetChatStickerSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// SetChatTitle change the title of a chat. Titles can't be changed for private
|
||||
// chats. The bot must be an administrator in the chat for this to work and must
|
||||
// have the appropriate admin rights. Returns True on success.
|
||||
//
|
||||
// Note: In regular groups (non-supergroups), this method will only work if the
|
||||
// 'All Members Are Admins' setting is off in the target group.
|
||||
func (bot *Bot) SetChatTitle(chatID int64, title string) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&SetChatTitleParameters{
|
||||
ChatID: chatID,
|
||||
Title: title,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSetChatTitle)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// SetPassportDataErrors informs a user that some of the Telegram Passport
|
||||
// elements they provided contains errors. The user will not be able to re-submit
|
||||
// their Passport to you until the errors are fixed (the contents of the field
|
||||
// for which you returned the error must change). Returns True on success.
|
||||
//
|
||||
// Use this if the data submitted by the user doesn't satisfy the standards your
|
||||
// service requires for any reason. For example, if a birthday date seems
|
||||
// invalid, a submitted document is blurry, a scan shows evidence of tampering,
|
||||
// etc. Supply some details in the error message to make sure the user knows how
|
||||
// to correct the issues.
|
||||
func (b *Bot) SetPassportDataErrors(userId int, errors []PassportElementError) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&SetPassportDataErrorsParameters{
|
||||
UserID: userId,
|
||||
Errors: errors,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := b.request(dst, MethodSetPassportDataErrors)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// SetWebhook specify a url and receive incoming updates via an outgoing webhook.
|
||||
// Whenever there is an update for the bot, we will send an HTTPS POST request to
|
||||
// the specified url, containing a JSON-serialized Update. In case of an
|
||||
// unsuccessful request, we will give up after a reasonable amount of attempts.
|
||||
// Returns true.
|
||||
//
|
||||
// If you'd like to make sure that the Webhook request comes from Telegram, we
|
||||
// recommend using a secret path in the URL, e.g. https://www.example.com/<token>.
|
||||
// Since nobody else knows your bot‘s token, you can be pretty sure it’s us.
|
||||
func (bot *Bot) SetWebhook(params *SetWebhookParameters) (ok bool, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("url", params.URL)
|
||||
|
||||
if len(params.AllowedUpdates) > 0 {
|
||||
args.Add("allowed_updates", strings.Join(params.AllowedUpdates, ","))
|
||||
}
|
||||
if params.MaxConnections > 0 &&
|
||||
params.MaxConnections <= 100 {
|
||||
args.Add("max_connections", strconv.Itoa(params.MaxConnections))
|
||||
}
|
||||
|
||||
var resp *Response
|
||||
if params.Certificate != nil {
|
||||
resp, err = bot.Upload(MethodSetWebhook, "certificate", "cert.pem", params.Certificate, args)
|
||||
} else {
|
||||
var dst []byte
|
||||
dst, err = json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err = bot.request(dst, MethodSetWebhook)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
||||
|
||||
// SetGameScore set the score of the specified user in a game. On success, if the
|
||||
// message was sent by the bot, returns the edited Message, otherwise returns
|
||||
// True. Returns an error, if the new score is not greater than the user's
|
||||
// current score in the chat and force is False.
|
||||
func (bot *Bot) SetGameScore(params *SetGameScoreParameters) (msg *Message, err error) {
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSetGameScore)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msg = new(Message)
|
||||
err = json.UnmarshalFast(*resp.Result, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// SetStickerPositionInSet move a sticker in a set created by the bot to a
|
||||
// specific position. Returns True on success.
|
||||
func (b *Bot) SetStickerPositionInSet(sticker string, position int) (ok bool, err error) {
|
||||
dst, err := json.MarshalFast(&SetStickerPositionInSetParameters{
|
||||
Sticker: sticker,
|
||||
Position: position,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := b.request(dst, MethodSetStickerPositionInSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SetChatDescriptionParameters represents data for SetChatDescription method.
|
||||
type SetChatDescriptionParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// New chat description, 0-255 characters
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// SetChatDescription change the description of a supergroup or a channel. The
|
||||
// bot must be an administrator in the chat for this to work and must have the
|
||||
// appropriate admin rights. Returns True on success.
|
||||
func (bot *Bot) SetChatDescription(chatID int64, description string) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&SetChatDescriptionParameters{
|
||||
ChatID: chatID,
|
||||
Description: description,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSetChatDescription)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// SetChatPhotoParameters represents data for SetChatPhoto method.
|
||||
type SetChatPhotoParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// New chat photo, uploaded using multipart/form-data
|
||||
ChatPhoto interface{} `json:"chat_photo"`
|
||||
}
|
||||
|
||||
// SetChatPhoto set a new profile photo for the chat. Photos can't be changed for private chats. The
|
||||
// bot must be an administrator in the chat for this to work and must have the appropriate admin
|
||||
// rights. Returns True on success.
|
||||
//
|
||||
// Note: In regular groups (non-supergroups), this method will only work if the 'All Members Are
|
||||
// Admins' setting is off in the target group.
|
||||
func (bot *Bot) SetChatPhoto(chatID int64, chatPhoto interface{}) (ok bool, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.Upload(MethodSetChatPhoto, TypePhoto, "chat_photo", chatPhoto, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SetChatStickerSetParameters represents data for SetChatStickerSet method.
|
||||
type SetChatStickerSetParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// Name of the sticker set to be set as the group sticker set
|
||||
StickerSetName string `json:"sticker_set_name"`
|
||||
}
|
||||
|
||||
// SetChatStickerSet set a new group sticker set for a supergroup. The bot must be an administrator
|
||||
// in the chat for this to work and must have the appropriate admin rights. Use the field
|
||||
// can_set_sticker_set optionally returned in getChat requests to check if the bot can use this
|
||||
// method. Returns True on success.
|
||||
func (bot *Bot) SetChatStickerSet(chatID int64, stickerSetName string) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&SetChatStickerSetParameters{
|
||||
ChatID: chatID,
|
||||
StickerSetName: stickerSetName,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSetChatStickerSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
// SetChatTitleParameters represents data for SetChatTitle method.
|
||||
type SetChatTitleParameters struct {
|
||||
// Unique identifier for the target chat
|
||||
ChatID int64 `json:"chat_id"`
|
||||
|
||||
// New chat title, 1-255 characters
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// SetChatTitle change the title of a chat. Titles can't be changed for private
|
||||
// chats. The bot must be an administrator in the chat for this to work and must
|
||||
// have the appropriate admin rights. Returns True on success.
|
||||
//
|
||||
// Note: In regular groups (non-supergroups), this method will only work if the
|
||||
// 'All Members Are Admins' setting is off in the target group.
|
||||
func (bot *Bot) SetChatTitle(chatID int64, title string) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&SetChatTitleParameters{
|
||||
ChatID: chatID,
|
||||
Title: title,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, MethodSetChatTitle)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,39 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
||||
type SetPassportDataErrorsParameters struct {
|
||||
// User identifier
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// A JSON-serialized array describing the errors
|
||||
Errors []PassportElementError `json:"errors"`
|
||||
}
|
||||
|
||||
// SetPassportDataErrors informs a user that some of the Telegram Passport
|
||||
// elements they provided contains errors. The user will not be able to re-submit
|
||||
// their Passport to you until the errors are fixed (the contents of the field
|
||||
// for which you returned the error must change). Returns True on success.
|
||||
//
|
||||
// Use this if the data submitted by the user doesn't satisfy the standards your
|
||||
// service requires for any reason. For example, if a birthday date seems
|
||||
// invalid, a submitted document is blurry, a scan shows evidence of tampering,
|
||||
// etc. Supply some details in the error message to make sure the user knows how
|
||||
// to correct the issues.
|
||||
func (b *Bot) SetPassportDataErrors(userId int, errors []PassportElementError) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&SetPassportDataErrorsParameters{
|
||||
UserID: userId,
|
||||
Errors: errors,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := b.request(dst, MethodSetPassportDataErrors)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// SetWebhookParameters represents data for SetWebhook method.
|
||||
type SetWebhookParameters struct {
|
||||
// HTTPS url to send updates to. Use an empty string to remove webhook
|
||||
// integration
|
||||
URL string `json:"url"`
|
||||
|
||||
// Upload your public key certificate so that the root certificate in use can
|
||||
// be checked. See our self-signed guide for details.
|
||||
Certificate InputFile `json:"certificate,omitempty"`
|
||||
|
||||
// Maximum allowed number of simultaneous HTTPS connections to the webhook
|
||||
// for update delivery, 1-100. Defaults to 40. Use lower values to limit the
|
||||
// load on your bot‘s server, and higher values to increase your bot’s
|
||||
// throughput.
|
||||
MaxConnections int `json:"max_connections,omitempty"`
|
||||
|
||||
// List the types of updates you want your bot to receive. For example,
|
||||
// specify [“message”, “edited_channel_post”, “callback_query”] to only
|
||||
// receive updates of these types. See Update for a complete list of
|
||||
// available update types. Specify an empty list to receive all updates
|
||||
// regardless of type (default). If not specified, the previous setting will
|
||||
// be used.
|
||||
//
|
||||
// Please note that this parameter doesn't affect updates created before the
|
||||
// call to the setWebhook, so unwanted updates may be received for a short
|
||||
// period of time.
|
||||
AllowedUpdates []string `json:"allowed_updates,omitempty"`
|
||||
}
|
||||
|
||||
// NewWebhook creates new SetWebhookParameters only with required parameters.
|
||||
func NewWebhook(url string, file interface{}) *SetWebhookParameters {
|
||||
return &SetWebhookParameters{
|
||||
URL: url,
|
||||
Certificate: file,
|
||||
}
|
||||
}
|
||||
|
||||
// SetWebhook specify a url and receive incoming updates via an outgoing webhook.
|
||||
// Whenever there is an update for the bot, we will send an HTTPS POST request to
|
||||
// the specified url, containing a JSON-serialized Update. In case of an
|
||||
// unsuccessful request, we will give up after a reasonable amount of attempts.
|
||||
// Returns true.
|
||||
//
|
||||
// If you'd like to make sure that the Webhook request comes from Telegram, we
|
||||
// recommend using a secret path in the URL, e.g. https://www.example.com/<token>.
|
||||
// Since nobody else knows your bot‘s token, you can be pretty sure it’s us.
|
||||
func (bot *Bot) SetWebhook(params *SetWebhookParameters) (ok bool, err error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("url", params.URL)
|
||||
|
||||
if len(params.AllowedUpdates) > 0 {
|
||||
args.Add("allowed_updates", strings.Join(params.AllowedUpdates, ","))
|
||||
}
|
||||
if params.MaxConnections > 0 &&
|
||||
params.MaxConnections <= 100 {
|
||||
args.Add("max_connections", strconv.Itoa(params.MaxConnections))
|
||||
}
|
||||
|
||||
var resp *Response
|
||||
if params.Certificate != nil {
|
||||
resp, err = bot.Upload(MethodSetWebhook, "certificate", "cert.pem", params.Certificate, args)
|
||||
} else {
|
||||
var dst []byte
|
||||
dst, err = json.Marshal(params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err = bot.request(dst, MethodSetWebhook)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
@ -14,7 +15,7 @@ type StopPollConfig struct {
|
|||
}
|
||||
|
||||
func (b *Bot) StopPoll(params StopPollConfig) (*Poll, error) {
|
||||
dst, err := json.Marshal(params)
|
||||
dst, err := json.MarshalFast(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -25,6 +26,6 @@ func (b *Bot) StopPoll(params StopPollConfig) (*Poll, error) {
|
|||
}
|
||||
|
||||
var poll Poll
|
||||
err = json.Unmarshal(*resp.Result, &poll)
|
||||
err = json.UnmarshalFast(*resp.Result, &poll)
|
||||
return &poll, err
|
||||
}
|
|
@ -0,0 +1,316 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: stop.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *StopPollConfig) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *StopPollConfig) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{ "chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteString(`,"message_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.MessageID), 10, j.MessageID < 0)
|
||||
buf.WriteByte(',')
|
||||
if j.ReplyMarkup != nil {
|
||||
if true {
|
||||
/* Struct fall back. type=telegram.InlineKeyboardMarkup kind=struct */
|
||||
buf.WriteString(`"reply_markup":`)
|
||||
err = buf.Encode(j.ReplyMarkup)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
}
|
||||
buf.Rewind(1)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtStopPollConfigbase = iota
|
||||
ffjtStopPollConfignosuchkey
|
||||
|
||||
ffjtStopPollConfigChatID
|
||||
|
||||
ffjtStopPollConfigMessageID
|
||||
|
||||
ffjtStopPollConfigReplyMarkup
|
||||
)
|
||||
|
||||
var ffjKeyStopPollConfigChatID = []byte("chat_id")
|
||||
|
||||
var ffjKeyStopPollConfigMessageID = []byte("message_id")
|
||||
|
||||
var ffjKeyStopPollConfigReplyMarkup = []byte("reply_markup")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *StopPollConfig) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *StopPollConfig) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtStopPollConfigbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtStopPollConfignosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyStopPollConfigChatID, kn) {
|
||||
currentKey = ffjtStopPollConfigChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'm':
|
||||
|
||||
if bytes.Equal(ffjKeyStopPollConfigMessageID, kn) {
|
||||
currentKey = ffjtStopPollConfigMessageID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'r':
|
||||
|
||||
if bytes.Equal(ffjKeyStopPollConfigReplyMarkup, kn) {
|
||||
currentKey = ffjtStopPollConfigReplyMarkup
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyStopPollConfigReplyMarkup, kn) {
|
||||
currentKey = ffjtStopPollConfigReplyMarkup
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyStopPollConfigMessageID, kn) {
|
||||
currentKey = ffjtStopPollConfigMessageID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyStopPollConfigChatID, kn) {
|
||||
currentKey = ffjtStopPollConfigChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtStopPollConfignosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtStopPollConfigChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtStopPollConfigMessageID:
|
||||
goto handle_MessageID
|
||||
|
||||
case ffjtStopPollConfigReplyMarkup:
|
||||
goto handle_ReplyMarkup
|
||||
|
||||
case ffjtStopPollConfignosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_MessageID:
|
||||
|
||||
/* handler: j.MessageID type=int kind=int quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.MessageID = int(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_ReplyMarkup:
|
||||
|
||||
/* handler: j.ReplyMarkup type=telegram.InlineKeyboardMarkup kind=struct quoted=false*/
|
||||
|
||||
{
|
||||
/* Falling back. type=telegram.InlineKeyboardMarkup kind=struct */
|
||||
tbuf, err := fs.CaptureField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(tbuf, &j.ReplyMarkup)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
http "github.com/valyala/fasthttp"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
var bot = new(tg.Bot)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
photoURL = http.AcquireURI()
|
||||
defer http.ReleaseURI(photoURL)
|
||||
|
||||
photoURL.SetScheme("https")
|
||||
photoURL.SetHost("simg3.gelbooru.com")
|
||||
photoURL.SetPath(path.Join("images", "46", "24", "46246c1b8c4fcc37050085a850c165c4.jpg"))
|
||||
|
||||
bot.AccessToken = os.Getenv("BOT_ACCESS_TOKEN")
|
||||
os.Exit(m.Run())
|
||||
}
|
|
@ -1,210 +0,0 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
const (
|
||||
chatID = 76918703
|
||||
superGroupID = -1001120141283
|
||||
)
|
||||
|
||||
func TestSendChatAction(t *testing.T) {
|
||||
ok, err := bot.SendChatAction(chatID, telegram.ActionTyping)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestKickChatMember(t *testing.T) {
|
||||
ok, err := bot.KickChatMember(&telegram.KickChatMemberParameters{
|
||||
ChatID: superGroupID,
|
||||
UserID: chatID,
|
||||
UntilDate: time.Now().Add(time.Second * 30).Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnbanChatMember(t *testing.T) {
|
||||
ok, err := bot.UnbanChatMember(superGroupID, chatID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func TestExportChatInviteLink(t *testing.T) {
|
||||
inviteLink, err := bot.ExportChatInviteLink(superGroupID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
t.Log("InviteLink:", inviteLink)
|
||||
if inviteLink == "" {
|
||||
t.Error("unexpected result: inviteLink is empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetChatPhoto(t *testing.T) {
|
||||
ok, err := bot.SetChatPhoto(superGroupID, "./photo.png")
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteChatPhoto(t *testing.T) {
|
||||
ok, err := bot.DeleteChatPhoto(superGroupID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetChatTitle(t *testing.T) {
|
||||
ok, err := bot.SetChatTitle(superGroupID, "Go Telegram Bot API")
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetChatDescription(t *testing.T) {
|
||||
ok, err := bot.SetChatDescription(
|
||||
superGroupID,
|
||||
fmt.Sprint("Go Telegram BotAPI testing chat (", time.Now().Unix(), ")"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPinChatMessage(t *testing.T) {
|
||||
ok, err := bot.PinChatMessage(&telegram.PinChatMessageParameters{
|
||||
ChatID: superGroupID,
|
||||
MessageID: replyToMessageID,
|
||||
DisableNotification: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnpinChatMessage(t *testing.T) {
|
||||
ok, err := bot.UnpinChatMessage(superGroupID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestLeaveChat(t *testing.T) {
|
||||
ErrNotMember := "Forbidden: bot is not a member of the supergroup chat"
|
||||
ok, err := bot.LeaveChat(-1001037355946)
|
||||
if err != nil &&
|
||||
err.Error() != ErrNotMember {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok &&
|
||||
err.Error() != ErrNotMember {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func TestGetChat(t *testing.T) {
|
||||
chat, err := bot.GetChat(superGroupID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if chat == nil {
|
||||
t.Error("unexpected result: chat is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetChatAdministrators(t *testing.T) {
|
||||
admins, err := bot.GetChatAdministrators(superGroupID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if len(admins) <= 0 {
|
||||
t.Error("unexpected result: admins not exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetChatMembersCount(t *testing.T) {
|
||||
total, err := bot.GetChatMembersCount(superGroupID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
t.Log(total, "members")
|
||||
if total <= 0 {
|
||||
t.Error("unexpected result: members count is 0")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetChatMember(t *testing.T) {
|
||||
member, err := bot.GetChatMember(superGroupID, chatID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if member == nil {
|
||||
t.Error("unexpected result: member is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetChatStickerSet(t *testing.T) {
|
||||
ErrCantSetStickerSet := "Bad Request: can't set supergroup sticker set"
|
||||
ok, err := bot.SetChatStickerSet(superGroupID, "HentaiDB")
|
||||
if err != nil &&
|
||||
err.Error() != ErrCantSetStickerSet {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok &&
|
||||
err.Error() != ErrCantSetStickerSet {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteChatStickerSet(t *testing.T) {
|
||||
ErrCantSetStickerSet := "Bad Request: can't set supergroup sticker set"
|
||||
ok, err := bot.DeleteChatStickerSet(superGroupID)
|
||||
if err != nil &&
|
||||
err.Error() != ErrCantSetStickerSet {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok &&
|
||||
err.Error() != ErrCantSetStickerSet {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
func TestGetMe(t *testing.T) {
|
||||
var err error
|
||||
bot.User, err = bot.GetMe()
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
t.FailNow()
|
||||
}
|
||||
if bot.User == nil {
|
||||
t.Error("unexpected result: bot user is nil")
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUserProfilePhotos(t *testing.T) {
|
||||
photos, err := bot.GetUserProfilePhotos(&telegram.GetUserProfilePhotosParameters{
|
||||
UserID: chatID,
|
||||
Offset: 0,
|
||||
Limit: 100,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if photos == nil {
|
||||
t.Error("unexpected result: photos is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFile(t *testing.T) {
|
||||
file, err := bot.GetFile(documentFileID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if file == nil {
|
||||
t.Error("unexpected result: file is nil")
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
const replyToMessageID = 35
|
||||
|
||||
func TestSendMessage(t *testing.T) {
|
||||
resp, err := bot.SendMessage(
|
||||
telegram.NewMessage(chatID, "Hello, World"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: message is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestForwardMessage(t *testing.T) {
|
||||
resp, err := bot.ForwardMessage(
|
||||
telegram.NewForwardMessage(chatID, superGroupID, replyToMessageID),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: message is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditMessageText(t *testing.T) {
|
||||
text := telegram.NewMessageText(
|
||||
fmt.Sprint("Go Telegram BotAPI testing chat (", time.Now().Unix(), ")"),
|
||||
)
|
||||
text.ChatID = chatID
|
||||
text.MessageID = replyToMessageID
|
||||
resp, err := bot.EditMessageText(text)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: resp is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditMessageCaption(t *testing.T) {
|
||||
var caption telegram.EditMessageCaptionParameters
|
||||
caption.Caption = fmt.Sprint("Go Telegram BotAPI testing chat (", time.Now().Unix(), ")")
|
||||
caption.ChatID = chatID
|
||||
caption.MessageID = messageID
|
||||
resp, err := bot.EditMessageCaption(&caption)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: resp is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditMessageReplyMarkup(t *testing.T) {
|
||||
var markup telegram.EditMessageReplyMarkupParameters
|
||||
markup.ChatID = superGroupID
|
||||
markup.MessageID = replyToMessageID
|
||||
markup.ReplyMarkup = telegram.NewInlineKeyboardMarkup(
|
||||
telegram.NewInlineKeyboardRow(
|
||||
telegram.NewInlineKeyboardButton(
|
||||
"hello",
|
||||
fmt.Sprint(time.Now().Unix()),
|
||||
),
|
||||
),
|
||||
)
|
||||
resp, err := bot.EditMessageReplyMarkup(&markup)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: resp is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteMessage(t *testing.T) {
|
||||
ok, err := bot.DeleteMessage(chatID, messageID)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
BIN
test/photo.png
BIN
test/photo.png
Binary file not shown.
Before Width: | Height: | Size: 21 KiB |
|
@ -1,101 +0,0 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
http "github.com/valyala/fasthttp"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
const (
|
||||
photoFileID = "AgADAgADw6cxG4zHKAkr42N7RwEN3IFShCoABHQwXEtVks4EH2wBAAEC"
|
||||
documentFileID = "BQADAgADOQADjMcoCcioX1GrDvp3Ag"
|
||||
// audioFileID = "BQADAgADRgADjMcoCdXg3lSIN49lAg"
|
||||
// voiceFileID = "AwADAgADWQADjMcoCeul6r_q52IyAg"
|
||||
// videoFileID = "BAADAgADZgADjMcoCav432kYe0FRAg"
|
||||
// videoNoteFileID = "DQADAgADdQAD70cQSUK41dLsRMqfAg"
|
||||
// stickerFileID = "BQADAgADcwADjMcoCbdl-6eB--YPAg"
|
||||
)
|
||||
|
||||
var (
|
||||
photoURL *http.URI
|
||||
messageID int
|
||||
)
|
||||
|
||||
func TestSendPhoto(t *testing.T) {
|
||||
resp, err := bot.SendPhoto(
|
||||
tg.NewPhoto(chatID, photoFileID),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: message is nil")
|
||||
} else {
|
||||
messageID = resp.ID
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendDocument(t *testing.T) {
|
||||
resp, err := bot.SendDocument(
|
||||
tg.NewDocument(chatID, documentFileID),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: message is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendMediaGroup(t *testing.T) {
|
||||
resp, err := bot.SendMediaGroup(
|
||||
tg.NewMediaGroup(
|
||||
chatID,
|
||||
tg.NewInputMediaPhoto(photoFileID),
|
||||
tg.NewInputMediaPhoto(photoURL.String()),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if len(resp) <= 0 {
|
||||
t.Error("unexpected result: message is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendLocation(t *testing.T) {
|
||||
resp, err := bot.SendLocation(
|
||||
tg.NewLocation(chatID, 36.724510, 139.268181),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: resp is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendVenue(t *testing.T) {
|
||||
resp, err := bot.SendVenue(
|
||||
tg.NewVenue(chatID, 36.724510, 139.268181, "Japan", "Japan"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: resp is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendContact(t *testing.T) {
|
||||
resp, err := bot.SendContact(
|
||||
tg.NewContact(chatID, "+42410", "Telegram"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if resp == nil {
|
||||
t.Error("unexpected result: message is nil")
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package test
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetUpdates(t *testing.T) {
|
||||
updates, err := bot.GetUpdates(nil)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if len(updates) <= 0 {
|
||||
t.Error("unexpected result: no updates")
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
func TestSetWebhook(t *testing.T) {
|
||||
ok, err := bot.SetWebhook(
|
||||
telegram.NewWebhook("https://toby3d.ru/telegram", nil),
|
||||
)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteWebhook(t *testing.T) {
|
||||
ok, err := bot.DeleteWebhook()
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if !ok {
|
||||
t.Error("unexpected result: ok is not true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWebhookInfo(t *testing.T) {
|
||||
info, err := bot.GetWebhookInfo()
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if info == nil {
|
||||
t.Error("unexpected result: info is nil")
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,46 +0,0 @@
|
|||
package telegram
|
||||
|
||||
type (
|
||||
// Game represents a game. Use BotFather to create and edit games, their
|
||||
// short names will act as unique identifiers.
|
||||
Game struct {
|
||||
// Title of the game
|
||||
Title string `json:"title"`
|
||||
|
||||
// Description of the game
|
||||
Description string `json:"description"`
|
||||
|
||||
// Brief description of the game or high scores included in the game
|
||||
// message. Can be automatically edited to include current high scores
|
||||
// for the game when the bot calls setGameScore, or manually edited
|
||||
// using editMessageText. 0-4096 characters.
|
||||
Text string `json:"text,omitempty"`
|
||||
|
||||
// Photo that will be displayed in the game message in chats.
|
||||
Photo []PhotoSize `json:"photo"`
|
||||
|
||||
// Special entities that appear in text, such as usernames, URLs, bot
|
||||
// commands, etc.
|
||||
TextEntities []MessageEntity `json:"text_entities,omitempty"`
|
||||
|
||||
// Animation that will be displayed in the game message in chats. Upload
|
||||
// via BotFather
|
||||
Animation *Animation `json:"animation,omitempty"`
|
||||
}
|
||||
|
||||
// CallbackGame a placeholder, currently holds no information. Use BotFather
|
||||
// to set up your game.
|
||||
CallbackGame struct{}
|
||||
|
||||
// GameHighScore represents one row of the high scores table for a game.
|
||||
GameHighScore struct {
|
||||
// Position in high score table for the game
|
||||
Position int `json:"position"`
|
||||
|
||||
// Score
|
||||
Score int `json:"score"`
|
||||
|
||||
// User
|
||||
User *User `json:"user"`
|
||||
}
|
||||
)
|
|
@ -1,840 +0,0 @@
|
|||
package telegram
|
||||
|
||||
type (
|
||||
// InlineQuery represents an incoming inline query. When the user sends an
|
||||
// empty query, your bot could return some default or trending results.
|
||||
InlineQuery struct {
|
||||
// Unique identifier for this query
|
||||
ID string `json:"id"`
|
||||
|
||||
// Text of the query (up to 512 characters)
|
||||
Query string `json:"query"`
|
||||
|
||||
// Offset of the results to be returned, can be controlled by the bot
|
||||
Offset string `json:"offset"`
|
||||
|
||||
// Sender
|
||||
From *User `json:"from"`
|
||||
|
||||
// Sender location, only for bots that request user location
|
||||
Location *Location `json:"location,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResult represents one result of an inline query.
|
||||
InlineQueryResult interface {
|
||||
ResultID() string
|
||||
ResultType() string
|
||||
ResultReplyMarkup() *InlineKeyboardMarkup
|
||||
}
|
||||
|
||||
// InlineQueryResultArticle represents a link to an article or web page.
|
||||
InlineQueryResultArticle struct {
|
||||
// Type of the result, must be article
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 Bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// Title of the result
|
||||
Title string `json:"title"`
|
||||
|
||||
// URL of the result
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
// Short description of the result
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// Url of the thumbnail for the result
|
||||
ThumbURL string `json:"thumb_url,omitempty"`
|
||||
|
||||
// Content of the message to be sent
|
||||
InputMessageContent interface{} `json:"input_message_content"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Pass True, if you don't want the URL to be shown in the message
|
||||
HideURL bool `json:"hide_url,omitempty"`
|
||||
|
||||
// Thumbnail width
|
||||
ThumbWidth int `json:"thumb_width,omitempty"`
|
||||
|
||||
// Thumbnail height
|
||||
ThumbHeight int `json:"thumb_height,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultPhoto represents a link to a photo. By default, this
|
||||
// photo will be sent by the user with optional caption. Alternatively, you
|
||||
// can use input_message_content to send a message with the specified content
|
||||
// instead of the photo.
|
||||
InlineQueryResultPhoto struct {
|
||||
// Type of the result, must be photo
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid URL of the photo. Photo must be in jpeg format. Photo size
|
||||
// must not exceed 5MB
|
||||
PhotoURL string `json:"photo_url"`
|
||||
|
||||
// URL of the thumbnail for the photo
|
||||
ThumbURL string `json:"thumb_url"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title,omitempty"`
|
||||
|
||||
// Short description of the result
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// Caption of the photo to be sent, 0-200 characters
|
||||
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"`
|
||||
|
||||
// Width of the photo
|
||||
PhotoWidth int `json:"photo_width,omitempty"`
|
||||
|
||||
// Height of the photo
|
||||
PhotoHeight int `json:"photo_height,omitempty"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the photo
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultGif represents a link to an animated GIF file. By
|
||||
// default, this animated GIF file will be sent by the user with optional
|
||||
// caption. Alternatively, you can use input_message_content to send a
|
||||
// message with the specified content instead of the animation.
|
||||
InlineQueryResultGif struct {
|
||||
// Type of the result, must be gif
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid URL for the GIF file. File size must not exceed 1MB
|
||||
GifURL string `json:"gif_url"`
|
||||
|
||||
// URL of the static thumbnail for the result (jpeg or gif)
|
||||
ThumbURL string `json:"thumb_url"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title,omitempty"`
|
||||
|
||||
// Caption of the GIF file to be sent, 0-200 characters
|
||||
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"`
|
||||
|
||||
// Width of the GIF
|
||||
GifWidth int `json:"gif_width,omitempty"`
|
||||
|
||||
// Height of the GIF
|
||||
GifHeight int `json:"gif_height,omitempty"`
|
||||
|
||||
// Duration of the GIF
|
||||
GifDuration int `json:"gif_duration,omitempty"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the GIF animation
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultMpeg4Gif represents a link to a video animation
|
||||
// (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4
|
||||
// file will be sent by the user with optional caption. Alternatively, you
|
||||
// can use input_message_content to send a message with the specified content
|
||||
// instead of the animation.
|
||||
InlineQueryResultMpeg4Gif struct {
|
||||
// Type of the result, must be mpeg4_gif
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid URL for the MP4 file. File size must not exceed 1MB
|
||||
Mpeg4URL string `json:"mpeg4_url"`
|
||||
|
||||
// URL of the static thumbnail (jpeg or gif) for the result
|
||||
ThumbURL string `json:"thumb_url"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title,omitempty"`
|
||||
|
||||
// Caption of the MPEG-4 file to be sent, 0-200 characters
|
||||
Caption string `json:"caption,omitempty"`
|
||||
|
||||
// Video width
|
||||
Mpeg4Width int `json:"mpeg4_width,omitempty"`
|
||||
|
||||
// Video height
|
||||
Mpeg4Height int `json:"mpeg4_height,omitempty"`
|
||||
|
||||
// Video duration
|
||||
Mpeg4Duration int `json:"mpeg4_duration,omitempty"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the video animation
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultVideo represents a link to a page containing an embedded
|
||||
// video player or a video file. By default, this video file will be sent by
|
||||
// the user with an optional caption. Alternatively, you can use
|
||||
// input_message_content to send a message with the specified content
|
||||
// instead of the video.
|
||||
//
|
||||
// If an InlineQueryResultVideo message contains an embedded video (e.g.,
|
||||
// YouTube), you must replace its content using input_message_content.
|
||||
InlineQueryResultVideo struct {
|
||||
// Type of the result, must be video
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid URL for the embedded video player or video file
|
||||
VideoURL string `json:"video_url"`
|
||||
|
||||
// Mime type of the content of video url, "text/html" or "video/mp4"
|
||||
MimeType string `json:"mime_type"`
|
||||
|
||||
// URL of the thumbnail (jpeg only) for the video
|
||||
ThumbURL string `json:"thumb_url"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title"`
|
||||
|
||||
// Caption of the video to be sent, 0-200 characters
|
||||
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"`
|
||||
|
||||
// Short description of the result
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// Video width
|
||||
VideoWidth int `json:"video_width,omitempty"`
|
||||
|
||||
// Video height
|
||||
VideoHeight int `json:"video_height,omitempty"`
|
||||
|
||||
// Video duration in seconds
|
||||
VideoDuration int `json:"video_duration,omitempty"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the video. This field is
|
||||
// required if InlineQueryResultVideo is used to send an HTML-page as a
|
||||
// result (e.g., a YouTube video).
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultAudio represents a link to an mp3 audio file. By default,
|
||||
// this audio file will be sent by the user. Alternatively, you can use
|
||||
// input_message_content to send a message with the specified content
|
||||
// instead of the audio.
|
||||
InlineQueryResultAudio struct {
|
||||
// Type of the result, must be audio
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid URL for the audio file
|
||||
AudioURL string `json:"audio_url"`
|
||||
|
||||
// Title
|
||||
Title string `json:"title"`
|
||||
|
||||
// Caption, 0-200 characters
|
||||
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 string `json:"performer,omitempty"`
|
||||
|
||||
// Audio duration in seconds
|
||||
AudioDuration int `json:"audio_duration,omitempty"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the audio
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultVoice represents a link to a voice recording in an .ogg
|
||||
// container encoded with OPUS. By default, this voice recording will be
|
||||
// sent by the user. Alternatively, you can use input_message_content to
|
||||
// send a message with the specified content instead of the the voice message.
|
||||
InlineQueryResultVoice struct {
|
||||
// Type of the result, must be voice
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid URL for the voice recording
|
||||
VoiceURL string `json:"voice_url"`
|
||||
|
||||
// Recording title
|
||||
Title string `json:"title"`
|
||||
|
||||
// Caption, 0-200 characters
|
||||
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
|
||||
VoiceDuration int `json:"voice_duration,omitempty"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the voice recording
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultDocument represents a link to a file. By default, this
|
||||
// file will be sent by the user with an optional caption. Alternatively,
|
||||
// you can use input_message_content to send a message with the specified
|
||||
// content instead of the file. Currently, only .PDF and .ZIP files can be
|
||||
// sent using this method.
|
||||
InlineQueryResultDocument struct {
|
||||
// Type of the result, must be document
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title"`
|
||||
|
||||
// Caption of the document to be sent, 0-200 characters
|
||||
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
|
||||
DocumentURL string `json:"document_url"`
|
||||
|
||||
// Mime type of the content of the file, either "application/pdf" or
|
||||
// "application/zip"
|
||||
MimeType string `json:"mime_type"`
|
||||
|
||||
// Short description of the result
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// URL of the thumbnail (jpeg only) for the file
|
||||
ThumbURL string `json:"thumb_url,omitempty"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the file
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
|
||||
// Thumbnail width
|
||||
ThumbWidth int `json:"thumb_width,omitempty"`
|
||||
|
||||
// Thumbnail height
|
||||
ThumbHeight int `json:"thumb_height,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultLocation represents a location on a map. By default, the
|
||||
// location will be sent by the user. Alternatively, you can use
|
||||
// input_message_content to send a message with the specified content
|
||||
// instead of the location.
|
||||
InlineQueryResultLocation struct {
|
||||
// Type of the result, must be location
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 Bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// Location title
|
||||
Title string `json:"title"`
|
||||
|
||||
// Url of the thumbnail for the result
|
||||
ThumbURL string `json:"thumb_url,omitempty"`
|
||||
|
||||
// Location latitude in degrees
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Location longitude in degrees
|
||||
Longitude float32 `json:"longitude"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the location
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
|
||||
// Thumbnail width
|
||||
ThumbWidth int `json:"thumb_width,omitempty"`
|
||||
|
||||
// Thumbnail height
|
||||
ThumbHeight int `json:"thumb_height,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultVenue represents a venue. By default, the venue will be
|
||||
// sent by the user. Alternatively, you can use input_message_content to
|
||||
// send a message with the specified content instead of the venue.
|
||||
InlineQueryResultVenue struct {
|
||||
// Type of the result, must be venue
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 Bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// Title of the venue
|
||||
Title string `json:"title"`
|
||||
|
||||
// Address of the venue
|
||||
Address string `json:"address"`
|
||||
|
||||
// Foursquare identifier of the venue if known
|
||||
FoursquareID string `json:"foursquare_id,omitempty"`
|
||||
|
||||
// Foursquare type of the venue, if known. (For example,
|
||||
// "arts_entertainment/default", "arts_entertainment/aquarium" or
|
||||
// "food/icecream".)
|
||||
FoursquareType string `json:"foursquare_type,omitempty"`
|
||||
|
||||
// Url of the thumbnail for the result
|
||||
ThumbURL string `json:"thumb_url,omitempty"`
|
||||
|
||||
// Latitude of the venue location in degrees
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Longitude of the venue location in degrees
|
||||
Longitude float32 `json:"longitude"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the venue
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
|
||||
// Thumbnail width
|
||||
ThumbWidth int `json:"thumb_width,omitempty"`
|
||||
|
||||
// Thumbnail height
|
||||
ThumbHeight int `json:"thumb_height,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultContact represents a contact with a phone number. By
|
||||
// default, this contact will be sent by the user. Alternatively, you can
|
||||
// use input_message_content to send a message with the specified content
|
||||
// instead of the contact.
|
||||
InlineQueryResultContact struct {
|
||||
// Type of the result, must be contact
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 Bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// Contact's phone number
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
|
||||
// Contact's first name
|
||||
FirstName string `json:"first_name"`
|
||||
|
||||
// Contact's last name
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
|
||||
// Additional data about the contact in the form of a vCard, 0-2048 bytes
|
||||
VCard string `json:"vcard,omitempty"`
|
||||
|
||||
// Url of the thumbnail for the result
|
||||
ThumbURL string `json:"thumb_url,omitempty"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the contact
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
|
||||
// Thumbnail width
|
||||
ThumbWidth int `json:"thumb_width,omitempty"`
|
||||
|
||||
// Thumbnail height
|
||||
ThumbHeight int `json:"thumb_height,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultGame represents a Game.
|
||||
InlineQueryResultGame struct {
|
||||
// Type of the result, must be game
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// Short name of the game
|
||||
GameShortName string `json:"game_short_name"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultCachedPhoto represents a link to a photo stored on the
|
||||
// Telegram servers. By default, this photo will be sent by the user with an
|
||||
// optional caption. Alternatively, you can use input_message_content to
|
||||
// send a message with the specified content instead of the photo.
|
||||
InlineQueryResultCachedPhoto struct {
|
||||
// Type of the result, must be photo
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid file identifier of the photo
|
||||
PhotoFileID string `json:"photo_file_id"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title,omitempty"`
|
||||
|
||||
// Short description of the result
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// Caption of the photo to be sent, 0-200 characters
|
||||
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
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the photo
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultCachedGif represents a link to an animated GIF file
|
||||
// stored on the Telegram servers. By default, this animated GIF file will
|
||||
// be sent by the user with an optional caption. Alternatively, you can use
|
||||
// input_message_content to send a message with specified content instead of
|
||||
// the animation.
|
||||
InlineQueryResultCachedGif struct {
|
||||
// Type of the result, must be gif
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid file identifier for the GIF file
|
||||
GifFileID string `json:"gif_file_id"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title,omitempty"`
|
||||
|
||||
// Caption of the GIF file to be sent, 0-200 characters
|
||||
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
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the GIF animation
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultCachedMpeg4Gif represents a link to a video animation
|
||||
// (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By
|
||||
// default, this animated MPEG-4 file will be sent by the user with an
|
||||
// optional caption. Alternatively, you can use input_message_content to
|
||||
// send a message with the specified content instead of the animation.
|
||||
InlineQueryResultCachedMpeg4Gif struct {
|
||||
// Type of the result, must be mpeg4_gif
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid file identifier for the MP4 file
|
||||
Mpeg4FileID string `json:"mpeg4_file_id"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title,omitempty"`
|
||||
|
||||
// Caption of the MPEG-4 file to be sent, 0-200 characters
|
||||
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
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the video animation
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultCachedSticker represents a link to a sticker stored on
|
||||
// the Telegram servers. By default, this sticker will be sent by the user.
|
||||
// Alternatively, you can use input_message_content to send a message with
|
||||
// the specified content instead of the sticker.
|
||||
InlineQueryResultCachedSticker struct {
|
||||
// Type of the result, must be sticker
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid file identifier of the sticker
|
||||
StickerFileID string `json:"sticker_file_id"`
|
||||
|
||||
// Inline keyboard attached to the message
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the sticker
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultCachedDocument represents a link to a file stored on the
|
||||
// Telegram servers. By default, this file will be sent by the user with an
|
||||
// optional caption. Alternatively, you can use input_message_content to
|
||||
// send a message with the specified content instead of the file.
|
||||
InlineQueryResultCachedDocument struct {
|
||||
// Type of the result, must be document
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title"`
|
||||
|
||||
// A valid file identifier for the file
|
||||
DocumentFileID string `json:"document_file_id"`
|
||||
|
||||
// Short description of the result
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// Caption of the document to be sent, 0-200 characters
|
||||
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
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the file
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultCachedVideo represents a link to a video file stored on
|
||||
// the Telegram servers. By default, this video file will be sent by the
|
||||
// user with an optional caption. Alternatively, you can use
|
||||
// input_message_content to send a message with the specified content
|
||||
// instead of the video.
|
||||
InlineQueryResultCachedVideo struct {
|
||||
// Type of the result, must be video
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid file identifier for the video file
|
||||
VideoFileID string `json:"video_file_id"`
|
||||
|
||||
// Title for the result
|
||||
Title string `json:"title"`
|
||||
|
||||
// Short description of the result
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// Caption of the video to be sent, 0-200 characters
|
||||
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
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the video
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultCachedVoice represents a link to a voice message stored
|
||||
// on the Telegram servers. By default, this voice message will be sent by
|
||||
// the user. Alternatively, you can use input_message_content to send a
|
||||
// message with the specified content instead of the voice message.
|
||||
InlineQueryResultCachedVoice struct {
|
||||
// Type of the result, must be voice
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid file identifier for the voice message
|
||||
VoiceFileID string `json:"voice_file_id"`
|
||||
|
||||
// Voice message title
|
||||
Title string `json:"title"`
|
||||
|
||||
// Caption, 0-200 characters
|
||||
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
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the voice message
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InlineQueryResultCachedAudio represents a link to an mp3 audio file
|
||||
// stored on the Telegram servers. By default, this audio file will be sent
|
||||
// by the user. Alternatively, you can use input_message_content to send a
|
||||
// message with the specified content instead of the audio.
|
||||
InlineQueryResultCachedAudio struct {
|
||||
// Type of the result, must be audio
|
||||
Type string `json:"type"`
|
||||
|
||||
// Unique identifier for this result, 1-64 bytes
|
||||
ID string `json:"id"`
|
||||
|
||||
// A valid file identifier for the audio file
|
||||
AudioFileID string `json:"audio_file_id"`
|
||||
|
||||
// Caption, 0-200 characters
|
||||
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
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
|
||||
// Content of the message to be sent instead of the audio
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
}
|
||||
|
||||
// InputMessageContent represents the content of a message to be sent as a result
|
||||
// of an inline query.
|
||||
InputMessageContent interface {
|
||||
IsInputMessageContent() bool
|
||||
}
|
||||
|
||||
// InputTextMessageContent represents the content of a text message to be
|
||||
// sent as the result of an inline query.
|
||||
InputTextMessageContent struct {
|
||||
// Text of the message to be sent, 1-4096 characters
|
||||
MessageText string `json:"message_text"`
|
||||
|
||||
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||
// fixed-width text or inline URLs in your bot's message.
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
|
||||
// Disables link previews for links in the sent message
|
||||
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
|
||||
}
|
||||
|
||||
// InputLocationMessageContent represents the content of a location message
|
||||
// to be sent as the result of an inline query.
|
||||
InputLocationMessageContent struct {
|
||||
// Latitude of the location in degrees
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Longitude of the location in degrees
|
||||
Longitude float32 `json:"longitude"`
|
||||
}
|
||||
|
||||
// InputVenueMessageContent represents the content of a venue message to be
|
||||
// sent as the result of an inline query.
|
||||
InputVenueMessageContent struct {
|
||||
// Latitude of the venue in degrees
|
||||
Latitude float32 `json:"latitude"`
|
||||
|
||||
// Longitude of the venue in degrees
|
||||
Longitude float32 `json:"longitude"`
|
||||
|
||||
// Name of the venue
|
||||
Title string `json:"title"`
|
||||
|
||||
// Address of the venue
|
||||
Address string `json:"address"`
|
||||
|
||||
// Foursquare identifier of the venue, if known
|
||||
FoursquareID string `json:"foursquare_id,omitempty"`
|
||||
|
||||
// Foursquare type of the venue, if known. (For example,
|
||||
// "arts_entertainment/default", "arts_entertainment/aquarium" or
|
||||
// "food/icecream".)
|
||||
FoursquareType string `json:"foursquare_type,omitempty"`
|
||||
}
|
||||
|
||||
// InputContactMessageContent represents the content of a contact message to
|
||||
// be sent as the result of an inline query.
|
||||
InputContactMessageContent struct {
|
||||
// Contact's phone number
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
|
||||
// Contact's first name
|
||||
FirstName string `json:"first_name"`
|
||||
|
||||
// Contact's last name
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
|
||||
// Additional data about the contact in the form of a vCard, 0-2048 bytes
|
||||
VCard string `json:"vcard,omitempty"`
|
||||
}
|
||||
|
||||
// ChosenInlineResult represents a result of an inline query that was chosen
|
||||
// by the user and sent to their chat partner.
|
||||
ChosenInlineResult struct {
|
||||
// The unique identifier for the result that was chosen
|
||||
ResultID string `json:"result_id"`
|
||||
|
||||
// Identifier of the sent inline message. Available only if there is an
|
||||
// inline keyboard attached to the message. Will be also received in
|
||||
// callback queries and can be used to edit the message.
|
||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||
|
||||
// The query that was used to obtain the result
|
||||
Query string `json:"query"`
|
||||
|
||||
// The user that chose the result
|
||||
From *User `json:"from"`
|
||||
|
||||
// Sender location, only for bots that require user location
|
||||
Location *Location `json:"location,omitempty"`
|
||||
}
|
||||
)
|
|
@ -1,591 +0,0 @@
|
|||
package telegram
|
||||
|
||||
type (
|
||||
// AuthParameters represent a Telegram Passport auth parameters for SDK.
|
||||
AuthParameters struct {
|
||||
// Unique identifier for the bot. You can get it from bot token.
|
||||
// For example, for the bot token
|
||||
// 1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy, the bot id is
|
||||
// 1234567.
|
||||
BotID int `json:"bot_id"`
|
||||
|
||||
// A JSON-serialized object describing the data you want to
|
||||
// request
|
||||
Scope PassportScope `json:"scope"`
|
||||
|
||||
// Public key of the bot
|
||||
PublicKey string `json:"public_key"`
|
||||
|
||||
// Bot-specified nonce.
|
||||
//
|
||||
// Important: For security purposes it should be a
|
||||
// cryptographically secure unique identifier of the request. In
|
||||
// particular, it should be long enough and it should be
|
||||
// generated using a cryptographically secure pseudorandom number
|
||||
// generator. You should never accept credentials with the same
|
||||
// nonce twice.
|
||||
Nonce string `json:"nonce"`
|
||||
}
|
||||
|
||||
// PassportScope represents the data to be requested.
|
||||
PassportScope struct {
|
||||
// List of requested elements, each type may be used only once
|
||||
// in the entire array of PassportScopeElement objects
|
||||
Data []PassportScopeElement `json:"data"`
|
||||
|
||||
// Scope version, must be 1
|
||||
V int `json:"v"`
|
||||
}
|
||||
|
||||
// PassportScopeElement represents a requested element.
|
||||
PassportScopeElement interface {
|
||||
PassportScopeElementTranslation() bool
|
||||
PassportScopeElementSelfie() bool
|
||||
}
|
||||
|
||||
//PassportScopeElementOneOfSeveral represents several elements one of which must be provided.
|
||||
PassportScopeElementOneOfSeveral struct {
|
||||
// List of elements one of which must be provided;
|
||||
OneOf []PassportScopeElementOne `json:"one_of"`
|
||||
|
||||
// Use this parameter if you want to request a selfie with the
|
||||
// document from this list that the user chooses to upload.
|
||||
Selfie bool `json:"selfie,omitempty"`
|
||||
|
||||
// Use this parameter if you want to request a translation of
|
||||
// the document from this list that the user chooses to upload.
|
||||
// Note: We suggest to only request translations after you have
|
||||
// received a valid document that requires one.
|
||||
Translation bool `json:"translation,omitempty"`
|
||||
}
|
||||
|
||||
// PassportScopeElementOne represents one particular element that must
|
||||
// be provided. If no options are needed, String can be used instead of
|
||||
// this object to specify the type of the element.
|
||||
PassportScopeElementOne struct {
|
||||
// Element type.
|
||||
Type string `json:"type"`
|
||||
|
||||
// Use this parameter if you want to request a selfie with the
|
||||
// document as well.
|
||||
Selfie bool `json:"selfie,omitempty"`
|
||||
|
||||
// Use this parameter if you want to request a translation of
|
||||
// the document as well.
|
||||
Translation bool `json:"translation,omitempty"`
|
||||
|
||||
// Use this parameter to request the first, last and middle name
|
||||
// of the user in the language of the user's country of residence.
|
||||
NativeNames bool `json:"native_names,omitempty"`
|
||||
}
|
||||
|
||||
Passport struct {
|
||||
// Personal Details
|
||||
PersonalDetails struct {
|
||||
Data *PersonalDetails `json:"data"`
|
||||
} `json:"personal_details"`
|
||||
|
||||
// Passport
|
||||
Passport struct {
|
||||
Data *IdDocumentData `json:"data"`
|
||||
FrontSide *PassportFile `json:"front_side"`
|
||||
Selfie *PassportFile `json:"selfie,omitempty"`
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
} `json:"passport"`
|
||||
|
||||
// Internal Passport
|
||||
InternalPassport struct {
|
||||
Data *IdDocumentData `json:"data"`
|
||||
FrontSide *PassportFile `json:"front_side"`
|
||||
Selfie *PassportFile `json:"selfie,omitempty"`
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
} `json:"internal_passport"`
|
||||
|
||||
// Driver License
|
||||
DriverLicense struct {
|
||||
Data *IdDocumentData `json:"data"`
|
||||
FrontSide *PassportFile `json:"front_side"`
|
||||
ReverseSide *PassportFile `json:"reverse_side"`
|
||||
Selfie *PassportFile `json:"selfie,omitempty"`
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
} `json:"driver_license"`
|
||||
|
||||
// Identity Card
|
||||
IdentityCard struct {
|
||||
Data *IdDocumentData `json:"data"`
|
||||
FrontSide *PassportFile `json:"front_side"`
|
||||
ReverseSide *PassportFile `json:"reverse_side"`
|
||||
Selfie *PassportFile `json:"selfie,omitempty"`
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
} `json:"identity_card"`
|
||||
|
||||
// Address
|
||||
Address struct {
|
||||
Data *ResidentialAddress `json:"data"`
|
||||
} `json:"address"`
|
||||
|
||||
// Utility Bill
|
||||
UtilityBill struct {
|
||||
Files []PassportFile `json:"files"`
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
} `json:"utility_bill"`
|
||||
|
||||
// Bank Statement
|
||||
BankStatement struct {
|
||||
Files []PassportFile `json:"files"`
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
} `json:"bank_statement"`
|
||||
|
||||
// Rental Agreement
|
||||
RentalAgreement struct {
|
||||
Files []PassportFile `json:"files"`
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
} `json:"rental_agreement"`
|
||||
|
||||
// Registration Page in the Internal Passport
|
||||
PassportRegistration struct {
|
||||
Files []PassportFile `json:"files"`
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
} `json:"passport_registration"`
|
||||
|
||||
// Temporary Registration
|
||||
TemporaryRegistration struct {
|
||||
Files []PassportFile `json:"files"`
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
} `json:"temporary_registration"`
|
||||
|
||||
// Phone number
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
|
||||
// Email
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
// PersonalDetails represents personal details.
|
||||
PersonalDetails struct {
|
||||
// First Name
|
||||
FirstName string `json:"first_name"`
|
||||
|
||||
// Last Name
|
||||
LastName string `json:"last_name"`
|
||||
|
||||
// Middle Name
|
||||
MiddleName string `json:"middle_name,omitempty"`
|
||||
|
||||
// Date of birth in DD.MM.YYYY format
|
||||
BirthDate string `json:"birth_date"`
|
||||
|
||||
// Gender, male or female
|
||||
Gender string `json:"gender"`
|
||||
|
||||
// Citizenship (ISO 3166-1 alpha-2 country code)
|
||||
CountryCode string `json:"country_code"`
|
||||
|
||||
// Country of residence (ISO 3166-1 alpha-2 country code)
|
||||
ResidenceCountryCode string `json:"residence_country_code"`
|
||||
|
||||
// First Name in the language of the user's country of residence
|
||||
FirstNameNative string `json:"first_name_native"`
|
||||
|
||||
// Last Name in the language of the user's country of residence
|
||||
LastNameNative string `json:"last_name_native"`
|
||||
|
||||
// Middle Name in the language of the user's country of residence
|
||||
MiddleNameNative string `json:"middle_name_native,omitempty"`
|
||||
}
|
||||
|
||||
// ResidentialAddress represents a residential address.
|
||||
ResidentialAddress struct {
|
||||
// First line for the address
|
||||
StreetLine1 string `json:"street_line1"`
|
||||
|
||||
// Second line for the address
|
||||
StreetLine2 string `json:"street_line2,omitempty"`
|
||||
|
||||
// City
|
||||
City string `json:"city"`
|
||||
|
||||
// State
|
||||
State string `json:"state,omitempty"`
|
||||
|
||||
// ISO 3166-1 alpha-2 country code
|
||||
CountryCode string `json:"country_code"`
|
||||
|
||||
// Address post code
|
||||
PostCode string `json:"post_code"`
|
||||
}
|
||||
|
||||
// IdDocumentData represents the data of an identity document.
|
||||
IdDocumentData struct {
|
||||
// Document number
|
||||
DocumentNo string `json:"document_no"`
|
||||
|
||||
// Date of expiry, in DD.MM.YYYY format
|
||||
ExpiryDate string `json:"expiry_date,omitempty"`
|
||||
}
|
||||
|
||||
// PassportData contains information about Telegram Passport data shared with
|
||||
// the bot by the user.
|
||||
PassportData struct {
|
||||
// Array with information about documents and other Telegram Passport
|
||||
// elements that was shared with the bot
|
||||
Data []EncryptedPassportElement `json:"data"`
|
||||
|
||||
// Encrypted credentials required to decrypt the data
|
||||
Credentials *EncryptedCredentials `json:"credentials"`
|
||||
}
|
||||
|
||||
// PassportFile represents a file uploaded to Telegram Passport. Currently all
|
||||
// Telegram Passport files are in JPEG format when decrypted and don't exceed
|
||||
// 10MB.
|
||||
PassportFile struct {
|
||||
// Unique identifier for this file
|
||||
FileID string `json:"file_id"`
|
||||
|
||||
// File size
|
||||
FileSize int `json:"file_size"`
|
||||
|
||||
// Unix time when the file was uploaded
|
||||
FileDate int64 `json:"file_date"`
|
||||
}
|
||||
|
||||
// Credentials is a JSON-serialized object.
|
||||
Credentials struct {
|
||||
// Credentials for encrypted data
|
||||
SecureData *SecureData `json:"secure_data"`
|
||||
|
||||
// Bot-specified nonce
|
||||
Nonce string `json:"nonce"`
|
||||
}
|
||||
|
||||
// SecureData represents the credentials required to decrypt encrypted
|
||||
// data. All fields are optional and depend on fields that were requested.
|
||||
SecureData struct {
|
||||
// Credentials for encrypted personal details
|
||||
PersonalDetails *SecureValue `json:"personal_details,omitempty"`
|
||||
|
||||
// Credentials for encrypted passport
|
||||
Passport *SecureValue `json:"passport,omitempty"`
|
||||
|
||||
// Credentials for encrypted internal passport
|
||||
InternalPassport *SecureValue `json:"internal_passport,omitempty"`
|
||||
|
||||
// Credentials for encrypted driver license
|
||||
DriverLicense *SecureValue `json:"driver_license,omitempty"`
|
||||
|
||||
// Credentials for encrypted ID card
|
||||
IdentityCard *SecureValue `json:"identity_card,omitempty"`
|
||||
|
||||
// Credentials for encrypted residential address
|
||||
Address *SecureValue `json:"address,omitempty"`
|
||||
|
||||
// Credentials for encrypted utility bill
|
||||
UtilityBill *SecureValue `json:"utility_bill,omitempty"`
|
||||
|
||||
// Credentials for encrypted bank statement
|
||||
BankStatement *SecureValue `json:"bank_statement,omitempty"`
|
||||
|
||||
// Credentials for encrypted rental agreement
|
||||
RentalAgreement *SecureValue `json:"rental_agreement,omitempty"`
|
||||
|
||||
// Credentials for encrypted registration from internal passport
|
||||
PassportRegistration *SecureValue `json:"passport_registration,omitempty"`
|
||||
|
||||
// Credentials for encrypted temporary registration
|
||||
TemporaryRegistration *SecureValue `json:"temporary_registration,omitempty"`
|
||||
}
|
||||
|
||||
// SecureValue represents the credentials required to decrypt encrypted
|
||||
// values. All fields are optional and depend on the type of fields that
|
||||
// were requested.
|
||||
SecureValue struct {
|
||||
// Credentials for encrypted Telegram Passport data.
|
||||
Data *DataCredentials `json:"data,omitempty"`
|
||||
|
||||
// Credentials for an encrypted document's front side.
|
||||
FrontSide *FileCredentials `json:"front_side,omitempty"`
|
||||
|
||||
// Credentials for an encrypted document's reverse side.
|
||||
ReverseSide *FileCredentials `json:"reverse_side,omitempty"`
|
||||
|
||||
// Credentials for an encrypted selfie of the user with a document.
|
||||
Selfie *FileCredentials `json:"selfie,omitempty"`
|
||||
|
||||
// Credentials for an encrypted translation of the document.
|
||||
Translation []FileCredentials `json:"translation,omitempty"`
|
||||
|
||||
// Credentials for encrypted files.
|
||||
Files []FileCredentials `json:"files,omitempty"`
|
||||
}
|
||||
|
||||
// DataCredentials can be used to decrypt encrypted data from the data
|
||||
// field in EncryptedPassportElement.
|
||||
DataCredentials struct {
|
||||
// Checksum of encrypted data
|
||||
DataHash string `json:"data_hash"`
|
||||
|
||||
// Secret of encrypted data
|
||||
Secret string `json:"secret"`
|
||||
}
|
||||
|
||||
// FileCredentials can be used to decrypt encrypted files from the
|
||||
// front_side, reverse_side, selfie, files and translation fields in
|
||||
// EncryptedPassportElement.
|
||||
FileCredentials struct {
|
||||
// Checksum of encrypted file
|
||||
FileHash string `json:"file_hash"`
|
||||
|
||||
// Secret of encrypted file
|
||||
Secret string `json:"secret"`
|
||||
}
|
||||
|
||||
// EncryptedPassportElement contains information about documents or other
|
||||
// Telegram Passport elements shared with the bot by the user.
|
||||
EncryptedPassportElement struct {
|
||||
// Element type.
|
||||
Type string `json:"type"`
|
||||
|
||||
// Base64-encoded encrypted Telegram Passport element data provided by
|
||||
// the user, available for "personal_details", "passport",
|
||||
// "driver_license", "identity_card", "identity_passport" and "address"
|
||||
// types. Can be decrypted and verified using the accompanying
|
||||
// EncryptedCredentials.
|
||||
Data string `json:"data,omitempty"`
|
||||
|
||||
// User's verified phone number, available only for "phone_number" type
|
||||
PhoneNumber string `json:"phone_number,omitempty"`
|
||||
|
||||
// User's verified email address, available only for "email" type
|
||||
Email string `json:"email,omitempty"`
|
||||
|
||||
// Array of encrypted files with documents provided by the user,
|
||||
// available for "utility_bill", "bank_statement", "rental_agreement",
|
||||
// "passport_registration" and "temporary_registration" types. Files can
|
||||
// be decrypted and verified using the accompanying EncryptedCredentials.
|
||||
Files []PassportFile `json:"files,omitempty"`
|
||||
|
||||
// Encrypted file with the front side of the document, provided by the
|
||||
// user. Available for "passport", "driver_license", "identity_card" and
|
||||
// "internal_passport". The file can be decrypted and verified using the
|
||||
// accompanying EncryptedCredentials.
|
||||
FrontSide *PassportFile `json:"front_side,omitempty"`
|
||||
|
||||
// Encrypted file with the reverse side of the document, provided by the
|
||||
// user. Available for "driver_license" and "identity_card". The file can
|
||||
// be decrypted and verified using the accompanying EncryptedCredentials.
|
||||
ReverseSide *PassportFile `json:"reverse_side,omitempty"`
|
||||
|
||||
// Encrypted file with the selfie of the user holding a document,
|
||||
// provided by the user; available for "passport", "driver_license",
|
||||
// "identity_card" and "internal_passport". The file can be decrypted
|
||||
// and verified using the accompanying EncryptedCredentials.
|
||||
Selfie *PassportFile `json:"selfie,omitempty"`
|
||||
|
||||
// Array of encrypted files with translated versions of documents
|
||||
// provided by the user. Available if requested for “passport”,
|
||||
// “driver_license”, “identity_card”, “internal_passport”,
|
||||
// “utility_bill”, “bank_statement”, “rental_agreement”,
|
||||
// “passport_registration” and “temporary_registration” types.
|
||||
// Files can be decrypted and verified using the accompanying
|
||||
// EncryptedCredentials.
|
||||
Translation []PassportFile `json:"translation,omitempty"`
|
||||
|
||||
// Base64-encoded element hash for using in PassportElementErrorUnspecified
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
// EncryptedCredentials contains data required for decrypting and
|
||||
// authenticating EncryptedPassportElement. See the Telegram Passport
|
||||
// Documentation for a complete description of the data decryption and
|
||||
// authentication processes.
|
||||
EncryptedCredentials struct {
|
||||
// Base64-encoded encrypted JSON-serialized data with unique user's
|
||||
// payload, data hashes and secrets required for EncryptedPassportElement
|
||||
// decryption and authentication
|
||||
Data string `json:"data"`
|
||||
|
||||
// Base64-encoded data hash for data authentication
|
||||
Hash string `json:"hash"`
|
||||
|
||||
// Base64-encoded secret, encrypted with the bot's public RSA key,
|
||||
// required for data decryption
|
||||
Secret string `json:"secret"`
|
||||
}
|
||||
|
||||
// PassportElementError represents an error in the Telegram Passport element
|
||||
// which was submitted that should be resolved by the user.
|
||||
PassportElementError interface {
|
||||
PassportElementErrorMessage() string
|
||||
PassportElementErrorSource() string
|
||||
PassportElementErrorType() string
|
||||
}
|
||||
|
||||
// PassportElementErrorDataField represents an issue in one of the data
|
||||
// fields that was provided by the user. The error is considered resolved
|
||||
// when the field's value changes.
|
||||
PassportElementErrorDataField struct {
|
||||
// Error source, must be data
|
||||
Source string `json:"source"`
|
||||
|
||||
// The section of the user's Telegram Passport which has the error, one
|
||||
// of "personal_details", "passport", "driver_license", "identity_card",
|
||||
// "internal_passport", "address"
|
||||
Type string `json:"type"`
|
||||
|
||||
// Name of the data field which has the error
|
||||
FieldName string `json:"field_name"`
|
||||
|
||||
// Base64-encoded data hash
|
||||
DataHash string `json:"data_hash"`
|
||||
|
||||
// Error message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// PassportElementErrorFrontSide represents an issue with the front side of
|
||||
// a document. The error is considered resolved when the file with the front
|
||||
// side of the document changes.
|
||||
PassportElementErrorFrontSide struct {
|
||||
// Error source, must be front_side
|
||||
Source string `json:"source"`
|
||||
|
||||
// The section of the user's Telegram Passport which has the issue, one
|
||||
// of "passport", "driver_license", "identity_card", "internal_passport"
|
||||
Type string `json:"type"`
|
||||
|
||||
// Base64-encoded hash of the file with the front side of the document
|
||||
FileHash string `json:"file_hash"`
|
||||
|
||||
// Error message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// PassportElementErrorReverseSide represents an issue with the reverse side
|
||||
// of a document. The error is considered resolved when the file with reverse
|
||||
// side of the document changes.
|
||||
PassportElementErrorReverseSide struct {
|
||||
// Error source, must be reverse_side
|
||||
Source string `json:"source"`
|
||||
|
||||
// The section of the user's Telegram Passport which has the issue, one
|
||||
// of "driver_license", "identity_card"
|
||||
Type string `json:"type"`
|
||||
|
||||
// Base64-encoded hash of the file with the reverse side of the document
|
||||
FileHash string `json:"file_hash"`
|
||||
|
||||
// Error message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// PassportElementErrorSelfie represents an issue with the selfie with a
|
||||
// document. The error is considered resolved when the file with the selfie
|
||||
// changes.
|
||||
PassportElementErrorSelfie struct {
|
||||
// Error source, must be selfie
|
||||
Source string `json:"source"`
|
||||
|
||||
// The section of the user's Telegram Passport which has the issue, one
|
||||
// of "passport", "driver_license", "identity_card", "internal_passport"
|
||||
Type string `json:"type"`
|
||||
|
||||
// Base64-encoded hash of the file with the selfie
|
||||
FileHash string `json:"file_hash"`
|
||||
|
||||
// Error message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// PassportElementErrorFile represents an issue with a document scan. The
|
||||
// error is considered resolved when the file with the document scan changes.
|
||||
PassportElementErrorFile struct {
|
||||
// Error source, must be file
|
||||
Source string `json:"source"`
|
||||
|
||||
// The section of the user's Telegram Passport which has the issue, one
|
||||
// of "utility_bill", "bank_statement", "rental_agreement",
|
||||
// "passport_registration", "temporary_registration"
|
||||
Type string `json:"type"`
|
||||
|
||||
// Base64-encoded file hash
|
||||
FileHash string `json:"file_hash"`
|
||||
|
||||
// Error message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// PassportElementErrorFiles represents an issue with a list of scans. The
|
||||
// error is considered resolved when the list of files containing the scans
|
||||
// changes.
|
||||
PassportElementErrorFiles struct {
|
||||
// Error source, must be files
|
||||
Source string `json:"source"`
|
||||
|
||||
// The section of the user's Telegram Passport which has the issue, one
|
||||
// of "utility_bill", "bank_statement", "rental_agreement",
|
||||
// "passport_registration", "temporary_registration"
|
||||
Type string `json:"type"`
|
||||
|
||||
// List of base64-encoded file hashes
|
||||
FileHashes []string `json:"file_hashes"`
|
||||
|
||||
// Error message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// PassportElementErrorTranslationFile represents an issue with one of the
|
||||
// files that constitute the translation of a document. The error is
|
||||
// considered resolved when the file changes.
|
||||
PassportElementErrorTranslationFile struct {
|
||||
// Error source, must be translation_file
|
||||
Source string `json:"source"`
|
||||
|
||||
// Type of element of the user's Telegram Passport which has the issue,
|
||||
// one of “passport”, “driver_license”, “identity_card”,
|
||||
// “internal_passport”, “utility_bill”, “bank_statement”,
|
||||
// “rental_agreement”, “passport_registration”, “temporary_registration”
|
||||
Type string `json:"type"`
|
||||
|
||||
// Base64-encoded file hash
|
||||
FileHash string `json:"file_hash"`
|
||||
|
||||
// Error message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// PassportElementErrorTranslationFiles represents an issue with the translated
|
||||
// version of a document. The error is considered resolved when a file with the
|
||||
// document translation change.
|
||||
PassportElementErrorTranslationFiles struct {
|
||||
// Error source, must be translation_files
|
||||
Source string `json:"source"`
|
||||
|
||||
// Type of element of the user's Telegram Passport which has the issue,
|
||||
// one of “passport”, “driver_license”, “identity_card”,
|
||||
// “internal_passport”, “utility_bill”, “bank_statement”,
|
||||
// “rental_agreement”, “passport_registration”, “temporary_registration”
|
||||
Type string `json:"type"`
|
||||
|
||||
// List of base64-encoded file hashes
|
||||
FileHashes []string `json:"file_hashes"`
|
||||
|
||||
// Error message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// PassportElementErrorUnspecified represents an issue in an unspecified place.
|
||||
// The error is considered resolved when new data is added.
|
||||
PassportElementErrorUnspecified struct {
|
||||
// Error source, must be unspecified
|
||||
Source string `json:"source"`
|
||||
|
||||
// Type of element of the user's Telegram Passport which has the issue
|
||||
Type string `json:"type"`
|
||||
|
||||
// Base64-encoded element hash
|
||||
ElementHash string `json:"element_hash"`
|
||||
|
||||
// Error message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
)
|
|
@ -1,158 +0,0 @@
|
|||
package telegram
|
||||
|
||||
type (
|
||||
// LabeledPrice represents a portion of the price for goods or services.
|
||||
LabeledPrice struct {
|
||||
// Portion label
|
||||
Label string `json:"label"`
|
||||
|
||||
// Price of the product in the smallest units of the currency (integer,
|
||||
// not float/double). For example, for a price of US$ 1.45 pass amount =
|
||||
// 145. See the exp parameter in currencies.json, it shows the number of
|
||||
// digits past the decimal point for each currency (2 for the majority
|
||||
// of currencies).
|
||||
Amount int `json:"amount"`
|
||||
}
|
||||
|
||||
// Invoice contains basic information about an invoice.
|
||||
Invoice struct {
|
||||
// Product name
|
||||
Title string `json:"title"`
|
||||
|
||||
// Product description
|
||||
Description string `json:"description"`
|
||||
|
||||
// Unique bot deep-linking parameter that can be used to generate this
|
||||
// invoice
|
||||
StartParameter string `json:"start_parameter"`
|
||||
|
||||
// Three-letter ISO 4217 currency code
|
||||
Currency string `json:"currency"`
|
||||
|
||||
// Total price in the smallest units of the currency (integer, not
|
||||
// float/double). For example, for a price of US$ 1.45 pass amount = 145.
|
||||
// See the exp parameter in currencies.json, it shows the number of
|
||||
// digits past the decimal point for each currency (2 for the majority
|
||||
// of currencies).
|
||||
TotalAmount int `json:"total_amount"`
|
||||
}
|
||||
|
||||
// ShippingAddress represents a shipping address.
|
||||
ShippingAddress struct {
|
||||
// ISO 3166-1 alpha-2 country code
|
||||
CountryCode string `json:"country_code"`
|
||||
|
||||
// State, if applicable
|
||||
State string `json:"state"`
|
||||
|
||||
// City
|
||||
City string `json:"city"`
|
||||
|
||||
// First line for the address
|
||||
StreetLine1 string `json:"street_line1"`
|
||||
|
||||
// Second line for the address
|
||||
StreetLine2 string `json:"street_line2"`
|
||||
|
||||
// Address post code
|
||||
PostCode string `json:"post_code"`
|
||||
}
|
||||
|
||||
// OrderInfo represents information about an order.
|
||||
OrderInfo struct {
|
||||
// User name
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// User's phone number
|
||||
PhoneNumber string `json:"phone_number,omitempty"`
|
||||
|
||||
// User email
|
||||
Email string `json:"email,omitempty"`
|
||||
|
||||
// User shipping address
|
||||
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
|
||||
}
|
||||
|
||||
// ShippingOption represents one shipping option.
|
||||
ShippingOption struct {
|
||||
// Shipping option identifier
|
||||
ID string `json:"id"`
|
||||
|
||||
// Option title
|
||||
Title string `json:"title"`
|
||||
|
||||
// List of price portions
|
||||
Prices []LabeledPrice `json:"prices"`
|
||||
}
|
||||
|
||||
// SuccessfulPayment contains basic information about a successful payment.
|
||||
SuccessfulPayment struct {
|
||||
// Three-letter ISO 4217 currency code
|
||||
Currency string `json:"currency"`
|
||||
|
||||
// Bot specified invoice payload
|
||||
InvoicePayload string `json:"invoice_payload"`
|
||||
|
||||
// Identifier of the shipping option chosen by the user
|
||||
ShippingOptionID string `json:"shipping_option_id,omitempty"`
|
||||
|
||||
// Telegram payment identifier
|
||||
TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
|
||||
|
||||
// Provider payment identifier
|
||||
ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
|
||||
|
||||
// Total price in the smallest units of the currency (integer, not
|
||||
// float/double). For example, for a price of US$ 1.45 pass amount = 145.
|
||||
// See the exp parameter in currencies.json, it shows the number of
|
||||
// digits past the decimal point for each currency (2 for the majority
|
||||
// of currencies).
|
||||
TotalAmount int `json:"total_amount"`
|
||||
|
||||
// Order info provided by the user
|
||||
OrderInfo *OrderInfo `json:"order_info,omitempty"`
|
||||
}
|
||||
|
||||
// ShippingQuery contains information about an incoming shipping query.
|
||||
ShippingQuery struct {
|
||||
// Unique query identifier
|
||||
ID string `json:"id"`
|
||||
|
||||
// Bot specified invoice payload
|
||||
InvoicePayload string `json:"invoice_payload"`
|
||||
|
||||
// User who sent the query
|
||||
From *User `json:"from"`
|
||||
|
||||
// User specified shipping address
|
||||
ShippingAddress *ShippingAddress `json:"shipping_address"`
|
||||
}
|
||||
|
||||
// PreCheckoutQuery contains information about an incoming pre-checkout query.
|
||||
PreCheckoutQuery struct {
|
||||
// Unique query identifier
|
||||
ID string `json:"id"`
|
||||
|
||||
// Three-letter ISO 4217 currency code
|
||||
Currency string `json:"currency"`
|
||||
|
||||
// Bot specified invoice payload
|
||||
InvoicePayload string `json:"invoice_payload"`
|
||||
|
||||
// Identifier of the shipping option chosen by the user
|
||||
ShippingOptionID string `json:"shipping_option_id,omitempty"`
|
||||
|
||||
// User who sent the query
|
||||
From *User `json:"from"`
|
||||
|
||||
// Total price in the smallest units of the currency (integer, not
|
||||
// float/double). For example, for a price of US$ 1.45 pass amount = 145.
|
||||
// See the exp parameter in currencies.json, it shows the number of
|
||||
// digits past the decimal point for each currency (2 for the majority of
|
||||
// currencies).
|
||||
TotalAmount int `json:"total_amount"`
|
||||
|
||||
// Order info provided by the user
|
||||
OrderInfo *OrderInfo `json:"order_info,omitempty"`
|
||||
}
|
||||
)
|
|
@ -1,66 +0,0 @@
|
|||
package telegram
|
||||
|
||||
type (
|
||||
// Sticker represents a sticker.
|
||||
Sticker struct {
|
||||
// Unique identifier for this file
|
||||
FileID string `json:"file_id"`
|
||||
|
||||
// Emoji associated with the sticker
|
||||
Emoji string `json:"emoji,omitempty"`
|
||||
|
||||
// Name of the sticker set to which the sticker belongs
|
||||
SetName string `json:"set_name,omitempty"`
|
||||
|
||||
// Sticker width
|
||||
Width int `json:"width"`
|
||||
|
||||
// Sticker height
|
||||
Height int `json:"height"`
|
||||
|
||||
// File size
|
||||
FileSize int `json:"file_size,omitempty"`
|
||||
|
||||
// Sticker thumbnail in the .webp or .jpg format
|
||||
Thumb *PhotoSize `json:"thumb,omitempty"`
|
||||
|
||||
// For mask stickers, the position where the mask should be placed
|
||||
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
|
||||
}
|
||||
|
||||
// StickerSet represents a sticker set.
|
||||
StickerSet struct {
|
||||
// Sticker set name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Sticker set title
|
||||
Title string `json:"title"`
|
||||
|
||||
// True, if the sticker set contains masks
|
||||
ContainsMasks bool `json:"contains_masks"`
|
||||
|
||||
// List of all set stickers
|
||||
Stickers []Sticker `json:"stickers"`
|
||||
}
|
||||
|
||||
// MaskPosition describes the position on faces where a mask should be placed
|
||||
// by default.
|
||||
MaskPosition struct {
|
||||
// The part of the face relative to which the mask should be placed. One
|
||||
// of "forehead", "eyes", "mouth", or "chin".
|
||||
Point string `json:"point"`
|
||||
|
||||
// Shift by X-axis measured in widths of the mask scaled to the face
|
||||
// size, from left to right. For example, choosing -1.0 will place mask
|
||||
// just to the left of the default mask position.
|
||||
XShift float32 `json:"x_shift"`
|
||||
|
||||
// Shift by Y-axis measured in heights of the mask scaled to the face
|
||||
// size, from top to bottom. For example, 1.0 will place the mask just
|
||||
// below the default mask position.
|
||||
YShift float32 `json:"y_shift"`
|
||||
|
||||
// Mask scaling coefficient. For example, 2.0 means double size.
|
||||
Scale float32 `json:"scale"`
|
||||
}
|
||||
)
|
|
@ -1,3 +1,4 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
@ -15,10 +16,11 @@ type UnbanChatMemberParameters struct {
|
|||
// to join via link, etc. The bot must be an administrator for this to work.
|
||||
// Returns True on success.
|
||||
func (bot *Bot) UnbanChatMember(chatID int64, userID int) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&UnbanChatMemberParameters{
|
||||
params := UnbanChatMemberParameters{
|
||||
ChatID: chatID,
|
||||
UserID: userID,
|
||||
})
|
||||
}
|
||||
dst, err := json.MarshalFast(¶ms)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -28,6 +30,6 @@ func (bot *Bot) UnbanChatMember(chatID int64, userID int) (ok bool, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,261 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: unban.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *UnbanChatMemberParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *UnbanChatMemberParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteString(`,"user_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.UserID), 10, j.UserID < 0)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtUnbanChatMemberParametersbase = iota
|
||||
ffjtUnbanChatMemberParametersnosuchkey
|
||||
|
||||
ffjtUnbanChatMemberParametersChatID
|
||||
|
||||
ffjtUnbanChatMemberParametersUserID
|
||||
)
|
||||
|
||||
var ffjKeyUnbanChatMemberParametersChatID = []byte("chat_id")
|
||||
|
||||
var ffjKeyUnbanChatMemberParametersUserID = []byte("user_id")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *UnbanChatMemberParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *UnbanChatMemberParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtUnbanChatMemberParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtUnbanChatMemberParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyUnbanChatMemberParametersChatID, kn) {
|
||||
currentKey = ffjtUnbanChatMemberParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'u':
|
||||
|
||||
if bytes.Equal(ffjKeyUnbanChatMemberParametersUserID, kn) {
|
||||
currentKey = ffjtUnbanChatMemberParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyUnbanChatMemberParametersUserID, kn) {
|
||||
currentKey = ffjtUnbanChatMemberParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyUnbanChatMemberParametersChatID, kn) {
|
||||
currentKey = ffjtUnbanChatMemberParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtUnbanChatMemberParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtUnbanChatMemberParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtUnbanChatMemberParametersUserID:
|
||||
goto handle_UserID
|
||||
|
||||
case ffjtUnbanChatMemberParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_UserID:
|
||||
|
||||
/* handler: j.UserID type=int kind=int quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.UserID = int(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
|
@ -12,7 +13,7 @@ type UnpinChatMessageParameters struct {
|
|||
// administrator in the chat for this to work and must have the appropriate admin
|
||||
// rights. Returns True on success.
|
||||
func (bot *Bot) UnpinChatMessage(chatID int64) (ok bool, err error) {
|
||||
dst, err := json.Marshal(&UnpinChatMessageParameters{ChatID: chatID})
|
||||
dst, err := json.MarshalFast(&UnpinChatMessageParameters{ChatID: chatID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -22,6 +23,6 @@ func (bot *Bot) UnpinChatMessage(chatID int64) (ok bool, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(*resp.Result, &ok)
|
||||
err = json.UnmarshalFast(*resp.Result, &ok)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: unpin.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *UnpinChatMessageParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *UnpinChatMessageParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"chat_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.ChatID), 10, j.ChatID < 0)
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtUnpinChatMessageParametersbase = iota
|
||||
ffjtUnpinChatMessageParametersnosuchkey
|
||||
|
||||
ffjtUnpinChatMessageParametersChatID
|
||||
)
|
||||
|
||||
var ffjKeyUnpinChatMessageParametersChatID = []byte("chat_id")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *UnpinChatMessageParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *UnpinChatMessageParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtUnpinChatMessageParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtUnpinChatMessageParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'c':
|
||||
|
||||
if bytes.Equal(ffjKeyUnpinChatMessageParametersChatID, kn) {
|
||||
currentKey = ffjtUnpinChatMessageParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.AsciiEqualFold(ffjKeyUnpinChatMessageParametersChatID, kn) {
|
||||
currentKey = ffjtUnpinChatMessageParametersChatID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtUnpinChatMessageParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtUnpinChatMessageParametersChatID:
|
||||
goto handle_ChatID
|
||||
|
||||
case ffjtUnpinChatMessageParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_ChatID:
|
||||
|
||||
/* handler: j.ChatID type=int64 kind=int64 quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.ChatID = int64(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
31
upload.go
31
upload.go
|
@ -1,3 +1,4 @@
|
|||
//go:generate ffjson $GOFILE
|
||||
package telegram
|
||||
|
||||
import (
|
||||
|
@ -14,6 +15,16 @@ import (
|
|||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
type UploadStickerFileParameters struct {
|
||||
// User identifier of sticker file owner
|
||||
UserID int `json:"user_id"`
|
||||
|
||||
// Png image with the sticker, must be up to 512 kilobytes in size,
|
||||
// dimensions must not exceed 512px, and either width or height
|
||||
// must be exactly 512px.
|
||||
PNGSticker interface{} `json:"png_sticker"`
|
||||
}
|
||||
|
||||
// ErrBadFileType describes error of the unsupported file data type for uploading
|
||||
var ErrBadFileType = errors.New("bad file type")
|
||||
|
||||
|
@ -98,7 +109,7 @@ func (b *Bot) Upload(method, key, name string, file InputFile, args *http.Args)
|
|||
}
|
||||
|
||||
response = new(Response)
|
||||
if err = json.Unmarshal(resp.Body(), response); err != nil {
|
||||
if err = json.UnmarshalFast(resp.Body(), response); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -167,3 +178,21 @@ func createFileFieldRaw(w *multipart.Writer, key, value string, src io.Reader) e
|
|||
_, err = io.Copy(field, src)
|
||||
return err
|
||||
}
|
||||
|
||||
// UploadStickerFile upload a .png file with a sticker for later use in
|
||||
// createNewStickerSet and addStickerToSet methods (can be used multiple times).
|
||||
// Returns the uploaded File on success.
|
||||
func (b *Bot) UploadStickerFile(userID int, pngSticker interface{}) (*File, error) {
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.SetUint("user_id", userID)
|
||||
|
||||
resp, err := b.Upload(MethodUploadStickerFile, TypeSticker, "sticker", pngSticker, args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var f File
|
||||
err = json.UnmarshalFast(*resp.Result, &f)
|
||||
return &f, err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,256 @@
|
|||
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
|
||||
// source: upload.go
|
||||
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
fflib "github.com/pquerna/ffjson/fflib/v1"
|
||||
)
|
||||
|
||||
// MarshalJSON marshal bytes to json - template
|
||||
func (j *UploadStickerFileParameters) MarshalJSON() ([]byte, error) {
|
||||
var buf fflib.Buffer
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
err := j.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalJSONBuf marshal buff to json - template
|
||||
func (j *UploadStickerFileParameters) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
|
||||
if j == nil {
|
||||
buf.WriteString("null")
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
var obj []byte
|
||||
_ = obj
|
||||
_ = err
|
||||
buf.WriteString(`{"user_id":`)
|
||||
fflib.FormatBits2(buf, uint64(j.UserID), 10, j.UserID < 0)
|
||||
buf.WriteString(`,"png_sticker":`)
|
||||
/* Interface types must use runtime reflection. type=interface {} kind=interface */
|
||||
err = buf.Encode(j.PNGSticker)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
ffjtUploadStickerFileParametersbase = iota
|
||||
ffjtUploadStickerFileParametersnosuchkey
|
||||
|
||||
ffjtUploadStickerFileParametersUserID
|
||||
|
||||
ffjtUploadStickerFileParametersPNGSticker
|
||||
)
|
||||
|
||||
var ffjKeyUploadStickerFileParametersUserID = []byte("user_id")
|
||||
|
||||
var ffjKeyUploadStickerFileParametersPNGSticker = []byte("png_sticker")
|
||||
|
||||
// UnmarshalJSON umarshall json - template of ffjson
|
||||
func (j *UploadStickerFileParameters) UnmarshalJSON(input []byte) error {
|
||||
fs := fflib.NewFFLexer(input)
|
||||
return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
|
||||
}
|
||||
|
||||
// UnmarshalJSONFFLexer fast json unmarshall - template ffjson
|
||||
func (j *UploadStickerFileParameters) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
|
||||
var err error
|
||||
currentKey := ffjtUploadStickerFileParametersbase
|
||||
_ = currentKey
|
||||
tok := fflib.FFTok_init
|
||||
wantedTok := fflib.FFTok_init
|
||||
|
||||
mainparse:
|
||||
for {
|
||||
tok = fs.Scan()
|
||||
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
|
||||
if tok == fflib.FFTok_error {
|
||||
goto tokerror
|
||||
}
|
||||
|
||||
switch state {
|
||||
|
||||
case fflib.FFParse_map_start:
|
||||
if tok != fflib.FFTok_left_bracket {
|
||||
wantedTok = fflib.FFTok_left_bracket
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_key
|
||||
continue
|
||||
|
||||
case fflib.FFParse_after_value:
|
||||
if tok == fflib.FFTok_comma {
|
||||
state = fflib.FFParse_want_key
|
||||
} else if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
} else {
|
||||
wantedTok = fflib.FFTok_comma
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_key:
|
||||
// json {} ended. goto exit. woo.
|
||||
if tok == fflib.FFTok_right_bracket {
|
||||
goto done
|
||||
}
|
||||
if tok != fflib.FFTok_string {
|
||||
wantedTok = fflib.FFTok_string
|
||||
goto wrongtokenerror
|
||||
}
|
||||
|
||||
kn := fs.Output.Bytes()
|
||||
if len(kn) <= 0 {
|
||||
// "" case. hrm.
|
||||
currentKey = ffjtUploadStickerFileParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
} else {
|
||||
switch kn[0] {
|
||||
|
||||
case 'p':
|
||||
|
||||
if bytes.Equal(ffjKeyUploadStickerFileParametersPNGSticker, kn) {
|
||||
currentKey = ffjtUploadStickerFileParametersPNGSticker
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case 'u':
|
||||
|
||||
if bytes.Equal(ffjKeyUploadStickerFileParametersUserID, kn) {
|
||||
currentKey = ffjtUploadStickerFileParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyUploadStickerFileParametersPNGSticker, kn) {
|
||||
currentKey = ffjtUploadStickerFileParametersPNGSticker
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
if fflib.EqualFoldRight(ffjKeyUploadStickerFileParametersUserID, kn) {
|
||||
currentKey = ffjtUploadStickerFileParametersUserID
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
currentKey = ffjtUploadStickerFileParametersnosuchkey
|
||||
state = fflib.FFParse_want_colon
|
||||
goto mainparse
|
||||
}
|
||||
|
||||
case fflib.FFParse_want_colon:
|
||||
if tok != fflib.FFTok_colon {
|
||||
wantedTok = fflib.FFTok_colon
|
||||
goto wrongtokenerror
|
||||
}
|
||||
state = fflib.FFParse_want_value
|
||||
continue
|
||||
case fflib.FFParse_want_value:
|
||||
|
||||
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
|
||||
switch currentKey {
|
||||
|
||||
case ffjtUploadStickerFileParametersUserID:
|
||||
goto handle_UserID
|
||||
|
||||
case ffjtUploadStickerFileParametersPNGSticker:
|
||||
goto handle_PNGSticker
|
||||
|
||||
case ffjtUploadStickerFileParametersnosuchkey:
|
||||
err = fs.SkipField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
}
|
||||
} else {
|
||||
goto wantedvalue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_UserID:
|
||||
|
||||
/* handler: j.UserID type=int kind=int quoted=false*/
|
||||
|
||||
{
|
||||
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
|
||||
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if tok == fflib.FFTok_null {
|
||||
|
||||
} else {
|
||||
|
||||
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
j.UserID = int(tval)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
handle_PNGSticker:
|
||||
|
||||
/* handler: j.PNGSticker type=interface {} kind=interface quoted=false*/
|
||||
|
||||
{
|
||||
/* Falling back. type=interface {} kind=interface */
|
||||
tbuf, err := fs.CaptureField(tok)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(tbuf, &j.PNGSticker)
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
state = fflib.FFParse_after_value
|
||||
goto mainparse
|
||||
|
||||
wantedvalue:
|
||||
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
|
||||
wrongtokenerror:
|
||||
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
|
||||
tokerror:
|
||||
if fs.BigError != nil {
|
||||
return fs.WrapErr(fs.BigError)
|
||||
}
|
||||
err = fs.Error.ToError()
|
||||
if err != nil {
|
||||
return fs.WrapErr(err)
|
||||
}
|
||||
panic("ffjson-generated: unreachable, please report bug.")
|
||||
done:
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package telegram
|
||||
|
||||
func (a *Animation) HasThumb() bool {
|
||||
return a != nil && a.Thumb != nil
|
||||
}
|
||||
|
||||
func (a *Animation) File() *File {
|
||||
if a == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &File{
|
||||
FileID: a.FileID,
|
||||
FileSize: a.FileSize,
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package telegram
|
||||
|
||||
func (a *Audio) FullName(sep string) (name string) {
|
||||
if !a.HasTitle() {
|
||||
return
|
||||
}
|
||||
|
||||
if a.HasPerformer() {
|
||||
name += a.Performer + sep
|
||||
}
|
||||
|
||||
name += a.Title
|
||||
return
|
||||
}
|
||||
|
||||
func (a *Audio) HasPerformer() bool {
|
||||
return a != nil && a.Performer != ""
|
||||
}
|
||||
|
||||
func (a *Audio) HasTitle() bool {
|
||||
return a != nil && a.Title != ""
|
||||
}
|
||||
|
||||
func (a *Audio) HasThumb() bool {
|
||||
return a != nil && a.Thumb != nil
|
||||
}
|
||||
|
||||
func (a *Audio) File() *File {
|
||||
if a == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &File{
|
||||
FileID: a.FileID,
|
||||
FileSize: a.FileSize,
|
||||
}
|
||||
}
|
205
utils_bot.go
205
utils_bot.go
|
@ -1,205 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// Bot represents a bot user with access token getted from @BotFather and
|
||||
// fasthttp.Client for requests.
|
||||
type Bot struct {
|
||||
*User
|
||||
AccessToken string
|
||||
Client *http.Client
|
||||
}
|
||||
|
||||
// SetClient allow set custom fasthttp.Client (for proxy traffic, for example).
|
||||
func (b *Bot) SetClient(newClient *http.Client) {
|
||||
if b == nil {
|
||||
b = new(Bot)
|
||||
}
|
||||
|
||||
b.Client = newClient
|
||||
}
|
||||
|
||||
// New creates a new default Bot structure based on the input access token.
|
||||
func New(accessToken string) (*Bot, error) {
|
||||
var err error
|
||||
b := new(Bot)
|
||||
b.SetClient(defaultClient)
|
||||
b.AccessToken = accessToken
|
||||
|
||||
b.User, err = b.GetMe()
|
||||
return b, err
|
||||
}
|
||||
|
||||
// IsMessageFromMe checks that the input message is a message from the current
|
||||
// bot.
|
||||
func (b *Bot) IsMessageFromMe(m *Message) bool {
|
||||
return b != nil && b.User != nil &&
|
||||
m != nil && m.From != nil && m.From.ID == b.ID
|
||||
}
|
||||
|
||||
// IsForwardFromMe checks that the input message is a forwarded message from the
|
||||
// current bot.
|
||||
func (b *Bot) IsForwardFromMe(m *Message) bool {
|
||||
return b != nil && b.User != nil &&
|
||||
m.IsForward() && m.ForwardFrom.ID == b.ID
|
||||
}
|
||||
|
||||
// IsReplyToMe checks that the input message is a reply to the current bot.
|
||||
func (b *Bot) IsReplyToMe(m *Message) bool {
|
||||
return m.Chat.IsPrivate() ||
|
||||
(m.IsReply() && b.IsMessageFromMe(m.ReplyToMessage))
|
||||
}
|
||||
|
||||
// IsCommandToMe checks that the input message is a command for the current bot.
|
||||
func (b *Bot) IsCommandToMe(m *Message) bool {
|
||||
if !m.IsCommand() {
|
||||
return false
|
||||
}
|
||||
|
||||
if m.Chat.IsPrivate() {
|
||||
return true
|
||||
}
|
||||
|
||||
parts := strings.Split(m.RawCommand(), "@")
|
||||
if len(parts) <= 1 {
|
||||
return false
|
||||
}
|
||||
|
||||
return strings.EqualFold(parts[1], b.User.Username)
|
||||
}
|
||||
|
||||
// IsMessageMentionsMe checks that the input message mentions the current bot.
|
||||
func (b *Bot) IsMessageMentionsMe(m *Message) bool {
|
||||
if b == nil || b.User == nil ||
|
||||
m == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if b.IsCommandToMe(m) {
|
||||
return true
|
||||
}
|
||||
|
||||
var entities []MessageEntity
|
||||
switch {
|
||||
case m.HasMentions():
|
||||
entities = m.Entities
|
||||
case m.HasCaptionMentions():
|
||||
entities = m.CaptionEntities
|
||||
}
|
||||
|
||||
for _, entity := range entities {
|
||||
if entity.IsMention() && entity.User.ID == b.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsForwardMentionsMe checks that the input forwarded message mentions the
|
||||
// current bot.
|
||||
func (b *Bot) IsForwardMentionsMe(m *Message) bool {
|
||||
return m.IsForward() && b.IsMessageMentionsMe(m)
|
||||
}
|
||||
|
||||
// IsReplyMentionsMe checks that the input message mentions the current bot.
|
||||
func (b *Bot) IsReplyMentionsMe(m *Message) bool {
|
||||
return m.IsReply() && b.IsMessageMentionsMe(m.ReplyToMessage)
|
||||
}
|
||||
|
||||
// IsMessageToMe checks that the input message is addressed to the current bot.
|
||||
func (b *Bot) IsMessageToMe(m *Message) bool {
|
||||
if m == nil || m.Chat == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if m.Chat.IsPrivate() ||
|
||||
b.IsCommandToMe(m) ||
|
||||
b.IsReplyToMe(m) ||
|
||||
b.IsMessageMentionsMe(m) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// NewFileURL creates a url.URL to file with path getted from GetFile method.
|
||||
func (b *Bot) NewFileURL(filePath string) *http.URI {
|
||||
if b == nil || b.AccessToken == "" ||
|
||||
filePath == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := http.AcquireURI()
|
||||
result.SetScheme("https")
|
||||
result.SetHost("api.telegram.org")
|
||||
result.SetPath(path.Join("file", "bot"+b.AccessToken, filePath))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// NewRedirectURL creates new url.URL for redirecting from one chat to another.
|
||||
func (b *Bot) NewRedirectURL(param string, group bool) *http.URI {
|
||||
if b == nil || b.User == nil || b.User.Username == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
link := http.AcquireURI()
|
||||
link.SetScheme("https")
|
||||
link.SetHost("t.me")
|
||||
link.SetPath(b.User.Username)
|
||||
|
||||
q := link.QueryArgs()
|
||||
key := "start"
|
||||
if group {
|
||||
key += "group"
|
||||
}
|
||||
q.Set(key, param)
|
||||
|
||||
link.SetQueryStringBytes(q.QueryString())
|
||||
|
||||
return link
|
||||
}
|
||||
|
||||
func (b *Bot) DecryptFile(pf *PassportFile, fc *FileCredentials) (data []byte, err error) {
|
||||
secret, err := decodeField(fc.Secret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hash, err := decodeField(fc.FileHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
key, iv := decryptSecretHash(secret, hash)
|
||||
file, err := b.GetFile(pf.FileID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, data, err = b.Client.Get(nil, b.NewFileURL(file.FilePath).String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err = decryptData(key, iv, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !match(hash, data) {
|
||||
err = ErrNotEqual
|
||||
return nil, err
|
||||
}
|
||||
|
||||
offset := int(data[0])
|
||||
data = data[offset:]
|
||||
|
||||
return nil, err
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import "strings"
|
||||
|
||||
// IsPrivate checks that the current chat is a private chat with single user.
|
||||
func (c *Chat) IsPrivate() bool {
|
||||
return c != nil && strings.EqualFold(c.Type, ChatPrivate)
|
||||
}
|
||||
|
||||
// IsGroup checks that the current chat is a group.
|
||||
func (c *Chat) IsGroup() bool {
|
||||
return c != nil && strings.EqualFold(c.Type, ChatGroup)
|
||||
}
|
||||
|
||||
// IsSuperGroup checks that the current chat is a supergroup.
|
||||
func (c *Chat) IsSuperGroup() bool {
|
||||
return c != nil && strings.EqualFold(c.Type, ChatSuperGroup)
|
||||
}
|
||||
|
||||
// IsChannel checks that the current chat is a channel.
|
||||
func (c *Chat) IsChannel() bool {
|
||||
return c != nil && strings.EqualFold(c.Type, ChatChannel)
|
||||
}
|
||||
|
||||
// HasPinnedMessage checks that the current chat has a pinned message.
|
||||
func (c *Chat) HasPinnedMessage() bool {
|
||||
return c != nil && c.PinnedMessage != nil
|
||||
}
|
||||
|
||||
// HasStickerSet checks that the current chat has a sticker set.
|
||||
func (c *Chat) HasStickerSet() bool {
|
||||
return c != nil && c.StickerSetName != ""
|
||||
}
|
||||
|
||||
// StickerSet return StickerSet structure if StickerSetName is available.
|
||||
func (c *Chat) StickerSet(bot *Bot) *StickerSet {
|
||||
if !c.HasStickerSet() || bot == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
set, err := bot.GetStickerSet(c.StickerSetName)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
// FullName returns the full name of chat or FirstName if LastName is not available.
|
||||
func (c *Chat) FullName() string {
|
||||
if c == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if c.HasLastName() {
|
||||
return c.FirstName + " " + c.LastName
|
||||
}
|
||||
|
||||
return c.FirstName
|
||||
}
|
||||
|
||||
// HaveLastName checks what the current user has a LastName.
|
||||
func (c *Chat) HasLastName() bool {
|
||||
return c != nil && c.LastName != ""
|
||||
}
|
||||
|
||||
// HaveUsername checks what the current user has a username.
|
||||
func (c *Chat) HasUsername() bool {
|
||||
return c != nil && c.Username != ""
|
||||
}
|
||||
|
||||
func (c *Chat) HasDescription() bool {
|
||||
return c != nil && c.Description != ""
|
||||
}
|
||||
|
||||
func (c *Chat) HasInviteLink() bool {
|
||||
return c != nil && c.InviteLink != ""
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package telegram
|
||||
|
||||
func (cir *ChosenInlineResult) HasLocation() bool {
|
||||
return cir != nil && cir.Location != nil
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package telegram
|
||||
|
||||
// FullName returns the full name of contact or FirstName if LastName is not
|
||||
// available.
|
||||
func (c *Contact) FullName() string {
|
||||
if c == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if c.HasLastName() {
|
||||
return c.FirstName + " " + c.LastName
|
||||
}
|
||||
|
||||
return c.FirstName
|
||||
}
|
||||
|
||||
// HaveLastName checks what the current contact has a LastName.
|
||||
func (c *Contact) HasLastName() bool {
|
||||
return c != nil && c.LastName != ""
|
||||
}
|
||||
|
||||
func (c *Contact) HasTelegram() bool {
|
||||
return c != nil && c.UserID != 0
|
||||
}
|
||||
|
||||
func (c *Contact) HasVCard() bool {
|
||||
return c != nil && c.VCard != ""
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import "errors"
|
||||
|
||||
var ErrNotEqual = errors.New("credentials hash and credentials data hash is not equal")
|
||||
|
||||
func (dc *DataCredentials) decrypt(d string) (data []byte, err error) {
|
||||
secret, err := decodeField(dc.Secret)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
hash, err := decodeField(dc.DataHash)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
key, iv := decryptSecretHash(secret, hash)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data, err = decodeField(d)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data, err = decryptData(key, iv, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !match(hash, data) {
|
||||
err = ErrNotEqual
|
||||
}
|
||||
|
||||
offset := int(data[0])
|
||||
data = data[offset:]
|
||||
|
||||
return
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package telegram
|
||||
|
||||
func (d *Document) HasThumb() bool {
|
||||
return d != nil && d.Thumb != nil
|
||||
}
|
||||
|
||||
func (d *Document) File() *File {
|
||||
return &File{
|
||||
FileID: d.FileID,
|
||||
FileSize: d.FileSize,
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
)
|
||||
|
||||
func (ec *EncryptedCredentials) Decrypt(pk *rsa.PrivateKey) (*Credentials, error) {
|
||||
if ec == nil || pk == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
data, err := decrypt(pk, ec.Secret, ec.Hash, ec.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var c Credentials
|
||||
err = json.Unmarshal(data, &c)
|
||||
return &c, err
|
||||
}
|
|
@ -1,196 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
)
|
||||
|
||||
func (epe *EncryptedPassportElement) DecryptPersonalDetails(sv *SecureValue) (*PersonalDetails, error) {
|
||||
if !epe.IsPersonalDetails() || !sv.HasData() {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
body, err := sv.Data.decrypt(epe.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pd PersonalDetails
|
||||
err = json.Unmarshal(body, &pd)
|
||||
return &pd, err
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) DecryptPassport(sv *SecureValue, b *Bot) (*IdDocumentData, []byte, []byte, [][]byte, error) {
|
||||
if !epe.IsPassport() || !sv.HasData() || !sv.HasFrontSide() {
|
||||
return nil, nil, nil, nil, nil
|
||||
}
|
||||
|
||||
body, err := sv.Data.decrypt(epe.Data)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
var idd IdDocumentData
|
||||
if err = json.Unmarshal(body, &idd); err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
fs, err := b.DecryptFile(epe.FrontSide, sv.FrontSide)
|
||||
if err != nil {
|
||||
return &idd, nil, nil, nil, err
|
||||
}
|
||||
|
||||
var s []byte
|
||||
if sv.HasSelfie() {
|
||||
if s, err = b.DecryptFile(epe.Selfie, sv.Selfie); err != nil {
|
||||
return &idd, fs, nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
t := make([][]byte, len(sv.Translation))
|
||||
if sv.HasTranslation() {
|
||||
for i := range t {
|
||||
if t[i], err = b.DecryptFile(&epe.Translation[i], &sv.Translation[i]); err != nil {
|
||||
return &idd, fs, s, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &idd, fs, s, t, nil
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) DecryptInternalPassport(sv *SecureValue, b *Bot) (*IdDocumentData, []byte, []byte, [][]byte, error) {
|
||||
if !epe.IsInternalPassport() || !sv.HasData() || !sv.HasFrontSide() {
|
||||
return nil, nil, nil, nil, nil
|
||||
}
|
||||
|
||||
body, err := sv.Data.decrypt(epe.Data)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
var idd IdDocumentData
|
||||
if err = json.Unmarshal(body, &idd); err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
fs, err := b.DecryptFile(epe.FrontSide, sv.FrontSide)
|
||||
if err != nil {
|
||||
return &idd, nil, nil, nil, err
|
||||
}
|
||||
|
||||
var s []byte
|
||||
if sv.HasSelfie() {
|
||||
if s, err = b.DecryptFile(epe.Selfie, sv.Selfie); err != nil {
|
||||
return &idd, fs, nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
t := make([][]byte, len(sv.Translation))
|
||||
if sv.HasTranslation() {
|
||||
for i := range t {
|
||||
if t[i], err = b.DecryptFile(&epe.Translation[i], &sv.Translation[i]); err != nil {
|
||||
return &idd, fs, s, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &idd, fs, s, t, nil
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) DecryptDriverLicense(sv *SecureValue, b *Bot) (*IdDocumentData, []byte, []byte, []byte, [][]byte, error) {
|
||||
if !epe.IsDriverLicense() || !sv.HasData() || !sv.HasFrontSide() || !sv.HasReverseSide() {
|
||||
return nil, nil, nil, nil, nil, nil
|
||||
}
|
||||
|
||||
body, err := sv.Data.decrypt(epe.Data)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
var idd IdDocumentData
|
||||
if err = json.Unmarshal(body, &idd); err != nil {
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
fs, err := b.DecryptFile(epe.FrontSide, sv.FrontSide)
|
||||
if err != nil {
|
||||
return &idd, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
rs, err := b.DecryptFile(epe.ReverseSide, sv.ReverseSide)
|
||||
if err != nil {
|
||||
return &idd, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
var s []byte
|
||||
if sv.HasSelfie() {
|
||||
if s, err = b.DecryptFile(epe.Selfie, sv.Selfie); err != nil {
|
||||
return &idd, fs, rs, nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
t := make([][]byte, len(sv.Translation))
|
||||
if sv.HasTranslation() {
|
||||
for i := range t {
|
||||
if t[i], err = b.DecryptFile(&epe.Translation[i], &sv.Translation[i]); err != nil {
|
||||
return &idd, fs, rs, s, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &idd, fs, rs, s, t, nil
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsAddress() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypeAddress)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsBankStatement() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypeBankStatement)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsDriverLicense() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypeDriverLicense)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsEmail() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypeEmail)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsIdentityCard() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypeIdentityCard)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsInternalPassport() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypeInternalPassport)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsPassport() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypePassport)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsPassportRegistration() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypePassportRegistration)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsPersonalDetails() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypePersonalDetails)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsPhoneNumber() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypePhoneNumber)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsRentalAgreement() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypeRentalAgreement)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsTemporaryRegistration() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypeTemporaryRegistration)
|
||||
}
|
||||
|
||||
func (epe *EncryptedPassportElement) IsUtilityBill() bool {
|
||||
return epe != nil && strings.EqualFold(epe.Type, TypeUtilityBill)
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// ParseURL selects URL from entered text of message and parse it as fasthttp.URI.
|
||||
func (e *MessageEntity) ParseURL(messageText string) *http.URI {
|
||||
if e == nil || !e.IsURL() || messageText == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
from := e.Offset
|
||||
to := from + e.Length
|
||||
text := []rune(messageText)
|
||||
if len(text) < to {
|
||||
return nil
|
||||
}
|
||||
|
||||
link := http.AcquireURI()
|
||||
link.Update(string(text[from:to]))
|
||||
|
||||
return link
|
||||
}
|
||||
|
||||
// IsBold checks that the current entity is a bold tag.
|
||||
func (e *MessageEntity) IsBold() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityBold)
|
||||
}
|
||||
|
||||
// IsBotCommand checks that the current entity is a bot command.
|
||||
func (e *MessageEntity) IsBotCommand() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityBotCommand)
|
||||
}
|
||||
|
||||
// IsCode checks that the current entity is a code tag.
|
||||
func (e *MessageEntity) IsCode() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityCode)
|
||||
}
|
||||
|
||||
// IsEmail checks that the current entity is a email.
|
||||
func (e *MessageEntity) IsEmail() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityEmail)
|
||||
}
|
||||
|
||||
// IsHashtag checks that the current entity is a hashtag.
|
||||
func (e *MessageEntity) IsHashtag() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityHashtag)
|
||||
}
|
||||
|
||||
// IsItalic checks that the current entity is a italic tag.
|
||||
func (e *MessageEntity) IsItalic() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityItalic)
|
||||
}
|
||||
|
||||
// IsMention checks that the current entity is a username mention.
|
||||
func (e *MessageEntity) IsMention() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityMention)
|
||||
}
|
||||
|
||||
// IsPre checks that the current entity is a pre tag.
|
||||
func (e *MessageEntity) IsPre() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityPre)
|
||||
}
|
||||
|
||||
// IsTextLink checks that the current entity is a text link.
|
||||
func (e *MessageEntity) IsTextLink() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityTextLink)
|
||||
}
|
||||
|
||||
// IsTextMention checks that the current entity is a mention without username.
|
||||
func (e *MessageEntity) IsTextMention() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityTextMention)
|
||||
}
|
||||
|
||||
// IsURL checks that the current entity is a URL
|
||||
func (e *MessageEntity) IsURL() bool {
|
||||
return e != nil && strings.EqualFold(e.Type, EntityURL)
|
||||
}
|
||||
|
||||
// TextLink parse current text link entity as fasthttp.URI.
|
||||
func (e *MessageEntity) TextLink() *http.URI {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
link := http.AcquireURI()
|
||||
link.Update(e.URL)
|
||||
|
||||
return link
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue