tgbotapi

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: MIT Imports: 7 Imported by: 1

README

tgbotapi

Telegram bot API

Prerequisites
  • Go 1.17
Example
package main

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

	"github.com/A1esandr/tgbotapi"
)

func main() {
	chatIDStr := 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)
	}
	chatID, err := strconv.ParseInt(chatIDStr, 10, 64)
	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) ([]byte, error)
}

func New

func New(token string) (Bot, error)

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 int `json:"offset"`
	Limit  int `json:"limit"`
}

type Message

type Message struct {
	MessageID int64 `json:"message_id"`
}

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

Directories

Path Synopsis
cmd
poll command
updates command

Jump to

Keyboard shortcuts

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