Documentation

Overview

    Package tgbot provides some simple wrapping around telegram bot api.

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type AnswerCallbackQuery

    type AnswerCallbackQuery struct {
    	ID   string `json:"callback_query_id,omitempty"`
    	Text string `json:"text,omitempty"`
    }

      AnswerCallbackQuery is the answer to CallbackQuery.

      type Bot

      type Bot struct {
      	Token string
      
      	GlobalURLPrefix string
      	WebhookPrefix   string
      
      	Logger logger.Logger
      	// contains filtered or unexported fields
      }

        Bot defines a telegram b with token.

        func (*Bot) PostRequest

        func (b *Bot) PostRequest(
        	ctx context.Context,
        	endpoint string,
        	params url.Values,
        ) (code int, err error)

          PostRequest use POST method to send a request to telegram

          func (*Bot) ReplyCallback

          func (b *Bot) ReplyCallback(ctx context.Context, id string, msg string) (code int, err error)

            ReplyCallback sents an answerCallbackQuery request.

            func (*Bot) SendMessage

            func (b *Bot) SendMessage(
            	ctx context.Context,
            	id int64,
            	msg string,
            	replyTo *int64,
            	markup *InlineKeyboardMarkup,
            ) (code int, err error)

              SendMessage sents a telegram messsage.

              func (*Bot) SetWebhook

              func (b *Bot) SetWebhook(ctx context.Context, webhookMaxConn int) (code int, err error)

                SetWebhook sets webhook with telegram.

                func (*Bot) String

                func (b *Bot) String() string

                func (*Bot) ValidateWebhookURL

                func (b *Bot) ValidateWebhookURL(r *http.Request) bool

                  ValidateWebhookURL validates whether requested URI in request matches hash path.

                  type CallbackQuery

                  type CallbackQuery struct {
                  	ID      string   `json:"id,omitempty"`
                  	Data    string   `json:"data,omitempty"`
                  	Message *Message `json:"message,omitempty"`
                  }

                    CallbackQuery is the callback from InlineKeyboardButton.

                    type Chat

                    type Chat struct {
                    	ID        int64  `json:"id,omitempty"`
                    	FirstName string `json:"first_name,omitempty"`
                    	LastName  string `json:"last_name,omitempty"`
                    	Username  string `json:"username,omitempty"`
                    	Type      string `json:"type,omitempty"`
                    }

                      Chat is a telegram chat.

                      type InlineKeyboardButton

                      type InlineKeyboardButton struct {
                      	Text string `json:"text,omitempty"`
                      	Data string `json:"callback_data,omitempty"`
                      }

                        InlineKeyboardButton represents a single choice inside InlineKeyboardMarkup.

                        type InlineKeyboardMarkup

                        type InlineKeyboardMarkup struct {
                        	InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard,omitempty"`
                        }

                          InlineKeyboardMarkup is used to provide single choice replies.

                          type Message

                          type Message struct {
                          	ID   int64  `json:"message_id,omitempty"`
                          	From User   `json:"from,omitempty"`
                          	Chat Chat   `json:"chat,omitempty"`
                          	Date int64  `json:"date,omitempty"`
                          	Text string `json:"text,omitempty"`
                          
                          	Entities []MessageEntity `json:"entities,omitempty"`
                          }

                            Message is a telegram message.

                            type MessageEntity

                            type MessageEntity struct {
                            	Type   string `json:"type,omitempty"`
                            	URL    string `json:"url,omitempty"`
                            	Offset int64  `json:"offset,omitempty"`
                            	Length int64  `json:"length,omitempty"`
                            }

                              MessageEntity represents one special entity in a message (e.g. url)

                              type ReplyMessage

                              type ReplyMessage struct {
                              	Method  string `json:"method,omitempty"`
                              	ChatID  int64  `json:"chat_id,omitempty"`
                              	ReplyTo int64  `json:"reply_to_message_id,omitempty"`
                              	Text    string `json:"text,omitempty"`
                              
                              	ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
                              }

                                ReplyMessage is a message sent on webhook requests.

                                type Update

                                type Update struct {
                                	ID       int64          `json:"update_id,omitempty"`
                                	Message  *Message       `json:"message,omitempty"`
                                	Callback *CallbackQuery `json:"callback_query,omitempty"`
                                }

                                  Update is a update from telegram webhook.

                                  type User

                                  type User struct {
                                  	ID        int64  `json:"id,omitempty"`
                                  	FirstName string `json:"first_name,omitempty"`
                                  	LastName  string `json:"last_name,omitempty"`
                                  	Username  string `json:"username,omitempty"`
                                  	Langueage string `json:"language_code,omitempty"`
                                  }

                                    User is a telegram user.