telegram_bot

package module
v0.0.0-...-4c426f0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2015 License: MIT Imports: 8 Imported by: 0

README

license Build Status

Bot

Telegram bot API library written in golang

Example

package main

import (
	"encoding/json"
	tb "github.com/TelegramApi/bot"
)

func main() {
	bot := tb.Create("API_TOKEN")
	bot.Listen()

	for update := range bot.Updates {

		var outputMessage string

		switch update.Message.Text {
		case "/start":
			outputMessage = "I am your new Bot.\n\n"
		case "Hi, Bot!":
			outputMessage = "Hello, " + update.Message.From.FirstName
		default:
			outputMessage = ""
		}

		var chat tb.User
		json.Unmarshal(update.Message.Chat, &chat)

		var keyboard = tb.ReplyKeyboardMarkup{Keyboard: [][]string{[]string{"Hi, Bot!"}}}
		bot.SendMessage(chat.Id, outputMessage, false, 0, keyboard)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BaseURL string = "https://api.telegram.org/bot%s/%s?%s"

Functions

This section is empty.

Types

type Audio

type Audio struct {
	FileId   string `json:"file_id"`   //Unique identifier for this file
	Duration int    `json:"duration"`  //Duration of the audio in seconds as defined by sender
	MimeType string `json:"mime_type"` //Optional. MIME type of the file as defined by sender
	FileSize int    `json:"file_size"` //Optional. File size
}

type Bot

type Bot struct {
	Updates chan Update
	// contains filtered or unexported fields
}

func Create

func Create(token string) *Bot

func (*Bot) ForwardMessage

func (b *Bot) ForwardMessage(chat_id, from_chat_id, message_id int) (Message, error)

func (*Bot) GetMe

func (b *Bot) GetMe() User

func (*Bot) GetUpdates

func (b *Bot) GetUpdates(offset int, limit int, timeout int) []Update

func (*Bot) Listen

func (b *Bot) Listen()

func (*Bot) SendMessage

func (b *Bot) SendMessage(chat_id int, text string, disable_web_page_preview bool, reply_to_message_id int, reply_markup interface{}) (Message, error)

func (*Bot) SendPhoto

func (b *Bot) SendPhoto(chat_id int, photo []byte, caption string) (Message, error)

func (*Bot) SetWebhook

func (b *Bot) SetWebhook(webhookUrl string)

type Contact

type Contact struct {
	PhoneNumber string `json:"phone_number"` //Contact's phone number
	FirstName   string `json:"first_name"`   //Contact's first name
	LastName    string `json:"last_name"`    //Optional. Contact's last name
	UserId      int    `json:"user_id"`      //Optional. Contact's user identifier in Telegram
}

type Document

type Document struct {
	FileId   string    `json:"file_id"`   //Unique file identifier
	Thumb    PhotoSize `json:"thumb"`     //Optional. Document thumbnail as defined by sender
	FileName int       `json:"file_name"` //Optional. Original filename as defined by sender
	MimeType string    `json:"mime_type"` //Optional. MIME type of the file as defined by sender
	FileSize int       `json:"file_size"` //Optional. File size
}

type ForceReply

type ForceReply struct {
	ForceReply bool `json:"force_reply"` //Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply'
	Selective  bool `json:"selective"`   //Optional. Use this parameter if you want to force reply from specific users only.
}

type GroupChat

type GroupChat struct {
	Id    int    `json:"id"`    //Unique identifier for this group chat
	Title string `json:"title"` //Group name
}

type InputFile

type InputFile []byte

type Location

type Location struct {
	Longitude float32 `json:"longitude"` //Longitude as defined by sender
	Latitude  float32 `json:"latitude"`  //Latitude as defined by sender
}

type Message

type Message struct {
	MessageID           int             `json:"message_id"`            //Unique message identifier
	From                User            `json:"from"`                  //Sender
	Date                int             `json:"date"`                  //Date the message was sent in Unix time
	Chat                json.RawMessage `json:"chat"`                  //Conversation the message belongs to — user in case of a private message, GroupChat in case of a group
	ForwardFrom         User            `json:"forward_from"`          //Optional. For forwarded messages, sender of the original message
	ForwardDate         int             `json:"forward_date"`          //Optional. For forwarded messages, date the original message was sent in Unix time
	ReplyToMessage      *Message        `json:"reply_to_message"`      //Optional. For replies, the original message.
	Text                string          `json:"text"`                  //Optional. For text messages, the actual UTF-8 text of the message
	Audio               Audio           `json:"audio"`                 //Optional. Message is an audio file, information about the file
	Document            Document        `json:"document"`              //Optional. Message is a general file, information about the file
	Photo               []PhotoSize     `json:"photo"`                 //Optional. Message is a photo, available sizes of the photo
	Sticker             Sticker         `json:"sticker"`               //Optional. Message is a sticker, information about the sticker
	Video               Video           `json:"video"`                 //Optional. Message is a video, information about the video
	Caption             string          `json:"caption"`               //Optional. Caption for the photo or video
	Contact             Contact         `json:"contact"`               //Optional. Message is a shared contact, information about the contact
	Location            Location        `json:"location"`              //Optional. Message is a shared location, information about the location
	NewChatParticipant  User            `json:"new_chat_participant"`  //Optional. A new member was added to the group, information about them (this member may be bot itself)
	LeftChatParticipant User            `json:"left_chat_participant"` //Optional. A member was removed from the group, information about them (this member may be bot itself)
	NewChatTitle        string          `json:"new_chat_title"`        //Optional. A group title was changed to this value
	NewChatPhoto        []PhotoSize     `json:"new_chat_photo"`        //Optional. A group photo was change to this value
	DeleteChatPhoto     bool            `json:"delete_chat_photo"`     //Optional. Informs that the group photo was deleted
	GroupChatCreated    bool            `json:"group_chat_created"`    //Optional. Informs that the group has been created
}

type PhotoSize

type PhotoSize struct {
	FileId   string `json:"file_id"`   //Unique identifier for this file
	Width    int    `json:"width"`     //Photo width
	Height   int    `json:"height"`    //Photo height
	FileSize int    `json:"file_size"` //Optional. File size
}

type ReplyKeyboardHide

type ReplyKeyboardHide struct {
	HideKeyboard bool `json:"hide_keyboard"` //Requests clients to hide the custom keyboard
	Selective    bool `json:"selective"`     //Optional. Use this parameter if you want to hide keyboard for specific users only.
}

type ReplyKeyboardMarkup

type ReplyKeyboardMarkup struct {
	Keyboard       [][]string `json:"keyboard"`        //Array of button rows, each represented by an Array of Strings
	ResizeKeyboard bool       `json:"resize_keyboard"` //Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). 	OneTimeKeyboard bool       `json:"one_time_keyboard"` //Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false.
	Selective      bool       `json:"selective"`       //Optional. Use this parameter if you want to show the keyboard to specific users only.
}

type Response

type Response struct {
	Ok          bool            `json:"ok"`
	Description string          `json:"description"`
	Result      json.RawMessage `json:"result"`
	ErrorCode   int             `json:"error_code"`
}

type Sticker

type Sticker struct {
	FileId   string    `json:"file_id"`   //Unique identifier for this file
	Width    int       `json:"width"`     //Sticker width
	Height   int       `json:"height"`    //Sticker height
	Thumb    PhotoSize `json:"thumb"`     //Optional. Sticker thumbnail in .webp or .jpg format
	FileSize int       `json:"file_size"` //Optional. File size
}

type Update

type Update struct {
	UpdateId int     `json:"update_id"` //The update‘s unique identifier
	Message  Message `json:"message"`   //Optional. New incoming message of any kind — text, photo, sticker, etc.
}

type User

type User struct {
	Id        int    `json:"id"`         //Unique identifier for this user or bot
	FirstName string `json:"first_name"` //User‘s or bot’s first name
	LastName  string `json:"last_name"`  //Optional. User‘s or bot’s last name
	Username  string `json:"username"`   //Optional. User‘s or bot’s username
}

type UserProfilePhotos

type UserProfilePhotos struct {
	TotalCount int           `json:"total_count"` //Total number of profile pictures the target user has
	Photos     [][]PhotoSize `json:"photos"`      //Requested profile pictures (in up to 4 sizes each)
}

type Video

type Video struct {
	FileId   string    `json:"file_id"`   //Unique identifier for this file
	Width    int       `json:"width"`     //Video width as defined by sender
	Height   int       `json:"height"`    //Video height as defined by sender
	Duration int       `json:"duration"`  //Duration of the video in seconds as defined by sender
	Thumb    PhotoSize `json:"thumb"`     //Optional. Video thumbnail
	MimeType string    `json:"mime_type"` //Optional. Mime type of a file as defined by sender
	FileSize int       `json:"file_size"` //Optional. File size
}

Jump to

Keyboard shortcuts

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