telegram

package
v0.0.0-...-d57bbc6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Quotes map[string][]*Quote

Functions

func Close

func Close(closer io.Closer)

Close invokes close method without handling error

func SetQuotes

func SetQuotes(quotes []*Quote)

Types

type APIRequest

type APIRequest struct {
	Method       string
	APIMethod    MethodType
	ExpectStatus int
	Body         io.Reader
	ContentType  string
}

APIRequest is a plain and simple structure to perform Gitlab DomainAPI requests.

type APIResponse

type APIResponse struct {
	Status  bool     `json:"status"`
	Message *Message `json:"result"`
}

type AnswerInline

type AnswerInline struct {
	ID      string                `json:"inline_query_id"`
	Results []*AnswerInlineResult `json:"results"`
}

func NewAnswerInline

func NewAnswerInline(update *Update) (result *AnswerInline)

type AnswerInlineResult

type AnswerInlineResult struct {
	Type        AnswerInlineType `json:"type"`
	ID          string           `json:"id"`
	VoiceFileId *string          `json:"voice_file_id,omitempty"`
	Title       string           `json:"title"`
	Caption     string           `json:"caption"`
}

func NewInlineQueryResultCachedVoice

func NewInlineQueryResultCachedVoice(update *Update) (results []*AnswerInlineResult)

type AnswerInlineType

type AnswerInlineType string
const (
	AnswerInlineTypeVoice AnswerInlineType = "voice"
)

type Client

type Client struct {

	// Services
	Inlines *InlineService
	Commons *CommonService
	// contains filtered or unexported fields
}

Client is a gitlab api client

func NewClient

func NewClient(token string) *Client

NewClient creates an DomainAPI client.

func (*Client) Call

func (api *Client) Call(request *APIRequest, in interface{}) (err error)

Call performs an generic http rest api calls.

func (*Client) Retrieve

func (api *Client) Retrieve(endpoint string, in interface{}) (err error)

Retrieve is a basic GET operation for getting object (or in some particular cases, the list of objects)

func (*Client) URL

func (api *Client) URL(format string, args ...interface{}) string

URL returns full REST api endpoint based on apiURL

func (*Client) Upload

func (api *Client) Upload(method MethodType, values map[string]io.Reader) (
	message *Message, err error)

Upload does a multipart/form-data call to the given URL.

func (*Client) WithURL

func (api *Client) WithURL(url string) *Client

WithURL sets url to send bot api requests to. It's helpful in testing.

type CommonService

type CommonService struct {
	// contains filtered or unexported fields
}

func (*CommonService) SendVoice

func (service *CommonService) SendVoice(message *VoiceMessage) (err error)

type From

type From struct {
	ID           int    `json:"id"`
	IsBot        bool   `json:"is_bot,omitempty"`
	FirstName    string `json:"first_name"`
	LastName     string `json:"last_name,omitempty"`
	Username     string `json:"username"`
	Type         string `json:"type,omitempty"`
	LanguageCode string `json:"language_code,omitempty"`
}

type InlineQuery

type InlineQuery struct {
	ID     string `json:"id"`
	From   *From  `json:"from"`
	Query  string `json:"query"`
	Offset string `json:"offset"`
}

type InlineService

type InlineService struct {
	// contains filtered or unexported fields
}

func (*InlineService) AnswerInlineQuery

func (service *InlineService) AnswerInlineQuery(update *Update) (err error)

type Message

type Message struct {
	ID   int   `json:"message_id"`
	From *From `json:"from"`
	Chat *From `json:"chat"`
	// todo: replace with serializable date (some other day :)
	Date int    `json:"date"`
	Text string `json:"text,omitempty"`

	// Optional fields
	Voice *Voice `json:"voice,omitempty"`
}

type MethodType

type MethodType string
const (
	BotAPIURL = "https://api.telegram.org/bot"

	// Methods
	SendVoice         MethodType = "sendVoice"
	AnswerInlineQuery MethodType = "answerInlineQuery"
)

type Quote

type Quote struct {
	ID      string   `json:"id"`
	Caption string   `json:"caption"`
	Matches []string `json:"matches"`
}

type Update

type Update struct {
	ID          int          `json:"update_id"`
	Message     *Message     `json:"message,omitempty"`
	InlineQuery *InlineQuery `json:"inline_query,omitempty"`
}

func ReadUpdate

func ReadUpdate(request *http.Request) (update *Update, err error)

ReadUpdate reads an update entry sent via Webhook by telegram see also: https://core.telegram.org/bots/api#setwebhook

func (*Update) Type

func (update *Update) Type() UpdateType

type UpdateType

type UpdateType int
const (
	UpdateTypeUnknown UpdateType = iota
	UpdateTypeInline
	UpdateTypeMessage
)

type Voice

type Voice struct {
	Duration     int    `json:"duration"`
	MimeType     string `json:"mime_type"`
	FileID       string `json:"file_id"`
	FileUniqueID string `json:"file_unique_id"`
	FileSize     int    `json:"file_size"`
}

type VoiceMessage

type VoiceMessage struct {
	ChatID              int     `json:"chat_id"`
	Voice               string  `json:"voice"`
	Caption             *string `json:"caption,omitempty"`
	ParseMode           *string `json:"parse_mode,omitempty"`
	Duration            *int    `json:"duration,omitempty"`
	DisableNotification *int    `json:"disable_notification,omitempty"`
	ReplyToMessageID    *int    `json:"reply_to_message_id,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL