telegram

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: MIT Imports: 11 Imported by: 0

README

GoCryptoTrader package Telegram

Build Status Software License GoDoc Coverage Status Go Report Card

This telegram package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Telegram Communications package

What is telegram?
  • Telegram is a cloud-based instant messaging and voice over IP service developed by Telegram Messenger LLP
  • Please visit: Telegram for more information
Current Features
  • Creation of bot that can retrieve

    • Bot status
    How to enable
    import (
    "github.com/idoall/gocryptotrader/communications/telegram"
    "github.com/idoall/gocryptotrader/config"
    )
    
    t := new(telegram.Telegram)
    
    // Define Telegram configuration
    commsConfig := config.CommunicationsConfig{TelegramConfig: config.TelegramConfig{
    Name: "Telegram",
    	Enabled: true,
    	Verbose: false,
    VerificationToken: "token",
    }}
    
    t.Setup(commsConfig)
    err := t.Connect
    // Handle error
    
  • Once the bot has started you can interact with the bot using these commands via Telegram:

/start			- Will authenticate your ID
/status			- Displays the status of the bot
/help			- Displays current command list
/settings		- Displays current bot settings
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

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

Constants

This section is empty.

Variables

View Source
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) Connect

func (t *Telegram) Connect() error

Connect starts an initial connection

func (*Telegram) GetUpdates

func (t *Telegram) GetUpdates() (GetUpdateResponse, error)

GetUpdates gets new updates via a long poll connection

func (*Telegram) HandleMessages

func (t *Telegram) HandleMessages(text string, chatID int64) error

HandleMessages handles incoming message from the long polling routine

func (*Telegram) InitialConnect

func (t *Telegram) InitialConnect() error

InitialConnect sets offset, and sends a welcome greeting to any associated IDs

func (*Telegram) IsConnected

func (t *Telegram) IsConnected() bool

IsConnected returns whether or not the connection is connected

func (*Telegram) PollerStart

func (t *Telegram) PollerStart()

PollerStart starts the long polling sequence

func (*Telegram) PushEvent

func (t *Telegram) PushEvent(event base.Event) error

PushEvent sends an event to a supplied recipient list via telegram

func (*Telegram) SendHTTPRequest

func (t *Telegram) SendHTTPRequest(path string, data []byte, result interface{}) error

SendHTTPRequest sends an authenticated HTTP request

func (*Telegram) SendMessage

func (t *Telegram) SendMessage(text string, chatID int64) error

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

func (t *Telegram) TestConnection() error

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

type UserType

type UserType 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"`
}

UserType contains user data

Jump to

Keyboard shortcuts

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