tgbotapi

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 7 Imported by: 0

README

tgbotapi

Telegram bot API

Prerequisites
  • Go 1.17
Example

examples can be found in cmd folder

package main

import (
	"fmt"
	"log"
	"os"
	"strconv"

	"github.com/A1esandr/tgbotapi"
)

func main() {
	chatID := os.Getenv("CHAT_ID")    // ID of chat
	token := os.Getenv("TOKEN")       // Token for Telegram bot
	if token == "" {
		log.Fatal("token is empty!")
	}
	bot, err := tgbotapi.New(token)
	if err != nil {
		log.Fatal(err)
	}
	response, err := bot.SendPoll(&tgbotapi.SendPoll{
		ChatID:          chatID,
		Question:        "How are you?",
		Options:         []string{"Fine", "Double Fine"},
		Type:            "quiz",
		CorrectOptionID: 1,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(response))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot interface {
	GetMe() (*GetMeResponse, error)
	RawGetRequest(request string) ([]byte, error)
	RawPostRequest(request string, body []byte) ([]byte, error)
	SendMessage(request *SendMessage) ([]byte, error)
	SendPoll(request *SendPoll) ([]byte, error)
	GetUpdates(request *GetUpdates) (*GetUpdatesResponse, error)
}

func New

func New(token string) (Bot, error)

type Chat added in v0.2.0

type Chat struct {
	ID    int64  `json:"id"`
	Title string `json:"title"`
}

type GetMeResponse

type GetMeResponse struct {
	OK     bool        `json:"ok"`
	Result GetMeResult `json:"result"`
}

type GetMeResult

type GetMeResult struct {
	ID                      interface{} `json:"id"`
	IsBot                   bool        `json:"is_bot"`
	FirstName               string      `json:"first_name"`
	Username                string      `json:"username"`
	CanJoinGroups           bool        `json:"can_join_groups"`
	CanReadAllGroupMessages bool        `json:"can_read_all_group_messages"`
	SupportInlineQueries    bool        `json:"support_inline_queries"`
}

type GetUpdates added in v0.1.2

type GetUpdates struct {
	Offset  int64 `json:"offset"`
	Limit   int   `json:"limit"`
	Timeout int   `json:"timeout"`
}

type GetUpdatesResponse added in v0.2.0

type GetUpdatesResponse struct {
	OK     bool     `json:"ok"`
	Result []Update `json:"result"`
}

type Message

type Message struct {
	MessageID int64 `json:"message_id"`
	Chat      Chat  `json:"chat"`
	Date      int64 `json:"date"`
}

type SendMessage

type SendMessage struct {
	ChatID interface{} `json:"chat_id"`
	Text   string      `json:"text"`
}

type SendMessageResponse

type SendMessageResponse struct {
	OK bool `json:"ok"`
}

type SendPoll

type SendPoll struct {
	ChatID          interface{} `json:"chat_id"`
	Question        string      `json:"question"` // Poll question, 1-300 characters
	Options         []string    `json:"options"`  // list of answer options, 2-10 strings 1-100 characters each
	Type            string      `json:"type"`     // “quiz” or “regular”
	CorrectOptionID int         `json:"correct_option_id"`
}

type SendPollResponse

type SendPollResponse struct {
	OK     bool    `json:"ok"`
	Result Message `json:"result"`
}

type Update added in v0.2.0

type Update struct {
	UpdateID    int64   `json:"update_id"`
	ChannelPost Message `json:"channel_post"`
	Message     Message `json:"message"`
}

type Updates added in v0.2.1

type Updates interface {
	Get() <-chan Update
	Close()
}

func NewUpdates added in v0.2.1

func NewUpdates(params UpdatesParams) Updates

type UpdatesParams added in v0.2.1

type UpdatesParams struct {
	Limit   int `json:"limit"`
	Timeout int `json:"timeout"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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