Documentation ¶
Overview ¶
Package telegram is used to connect to a cloud-based mobile and desktop messaging app using the bot API defined in https://core.telegram.org/bots/api#recent-changes
Index ¶
- Variables
- type ChatType
- type GetUpdateResponse
- type Message
- type MessageEntityType
- type MessageType
- type Telegram
- func (t *Telegram) Connect() error
- func (t *Telegram) GetUpdates() (GetUpdateResponse, error)
- func (t *Telegram) HandleMessages(text string, chatID int64) error
- func (t *Telegram) InitialConnect() error
- func (t *Telegram) IsConnected() bool
- func (t *Telegram) PollerStart()
- func (t *Telegram) PushEvent(event base.Event) error
- func (t *Telegram) SendHTTPRequest(path string, data []byte, result interface{}) error
- func (t *Telegram) SendMessage(text string, chatID int64) error
- func (t *Telegram) Setup(cfg *base.CommunicationsConfig)
- func (t *Telegram) TestConnection() error
- type User
- type UserType
Constants ¶
This section is empty.
Variables ¶
var ( // ErrWaiter is the default timer to wait if an err occurs // before retrying after successfully connecting ErrWaiter = time.Second * 30 )
Functions ¶
This section is empty.
Types ¶
type ChatType ¶
type ChatType struct { ID int64 `json:"id"` Type string `json:"type"` Title string `json:"title"` UserName string `json:"username"` FirstName string `json:"first_name"` LastName string `json:"last_name"` AllAdmin bool `json:"all_members_are_administrators"` Description string `json:"description"` InviteLink string `json:"invite_link"` StickerSetName string `json:"sticker_set_name"` CanSetStickerSet bool `json:"can_set_sticker_set"` }
ChatType contains chat data
type GetUpdateResponse ¶
type GetUpdateResponse struct { Ok bool `json:"ok"` Description string `json:"description"` Result []struct { UpdateID int64 `json:"update_id"` Message MessageType `json:"message"` EditedMessage interface{} `json:"edited_message"` ChannelPost interface{} `json:"channel_post"` EditedChannelPost interface{} `json:"edited_channel_post"` InlineQuery interface{} `json:"inline_query"` ChosenInlineResult interface{} `json:"chosen_inline_result"` CallbackQuery interface{} `json:"callback_query"` ShippingQuery interface{} `json:"shipping_query"` PreCheckoutQuery interface{} `json:"pre_checkout_query"` } `json:"result"` }
GetUpdateResponse represents an incoming update
type Message ¶
type Message struct { Ok bool `json:"ok"` Description string `json:"description"` Result MessageType `json:"result"` }
Message holds the full message information
type MessageEntityType ¶
type MessageEntityType struct { Type string `json:"type"` Offset int64 `json:"offset"` Length int64 `json:"length"` URL string `json:"url"` User UserType `json:"user"` }
MessageEntityType contains message entity information
type MessageType ¶
type MessageType struct { MessageID int64 `json:"message_id"` From UserType `json:"from"` Date int64 `json:"date"` Chat ChatType `json:"chat"` ForwardFrom UserType `json:"forward_from"` ForwardFromChat ChatType `json:"forward_from_chat"` ForwardFromMessageID int64 `json:"forward_from_message_id"` ForwardSignature string `json:"forward_signature"` ForwardDate int64 `json:"forward_date"` ReplyToMessage interface{} `json:"reply_to_message"` EditDate int64 `json:"edit_date"` MediaGroupID string `json:"media_group_id"` AuthorSignature string `json:"author_signature"` Text string `json:"text"` Entities []MessageEntityType `json:"entities"` CaptionEntities []MessageEntityType `json:"caption_entities"` }
MessageType contains message data
type Telegram ¶
type Telegram struct { base.Base Token string Offset int64 AuthorisedClients []int64 // contains filtered or unexported fields }
Telegram is the overarching type across this package
func (*Telegram) GetUpdates ¶
func (t *Telegram) GetUpdates() (GetUpdateResponse, error)
GetUpdates gets new updates via a long poll connection
func (*Telegram) HandleMessages ¶
HandleMessages handles incoming message from the long polling routine
func (*Telegram) InitialConnect ¶
InitialConnect sets offset, and sends a welcome greeting to any associated IDs
func (*Telegram) IsConnected ¶
IsConnected returns whether or not the connection is connected
func (*Telegram) PollerStart ¶
func (t *Telegram) PollerStart()
PollerStart starts the long polling sequence
func (*Telegram) SendHTTPRequest ¶
SendHTTPRequest sends an authenticated HTTP request
func (*Telegram) SendMessage ¶
SendMessage sends a message to a user by their chatID
func (*Telegram) Setup ¶
func (t *Telegram) Setup(cfg *base.CommunicationsConfig)
Setup takes in a Telegram configuration and sets verification token
func (*Telegram) TestConnection ¶
TestConnection tests bot's supplied authentication token
type User ¶
type User struct { Ok bool `json:"ok"` Description string `json:"description"` Result struct { ID int64 `json:"id"` IsBot bool `json:"is_bot"` FirstName string `json:"first_name"` LastName string `json:"last_name"` UserName string `json:"username"` LanguageCode string `json:"language_code"` } `json:"result"` }
User holds user information