telegrambot

package module
v0.0.0-...-ea297ad Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2016 License: MIT Imports: 6 Imported by: 9

README

Overview

Twitter GoDoc

TelegramBot helps you to easily access the Telegram Bot API

License

Slugify is licensed under a MIT license.

Warning

This package has no tests yet, so use at your own risk. This was quickly hacked together!

Installation

A simple go get github.com/Machiel/telegrambot should suffice.

Usage

Example

package main

import (
	"math/rand"
	"time"

	"github.com/Machiel/telegrambot"
)

var answers = []string{
	"Hodor!",
	"Hodor, hodor... hodor!",
	"Hodor?",
	"Hodor...",
	"Hodor...! Hodor...!",
	"Hooodorrrr!!!",
	"Hodor",
	"Hodor?!",
}

func main() {

	telegram := telegrambot.New("api-key")

	offset := new(int64)
	for {

		updates, _ := telegram.GetUpdates(*offset)

		for _, update := range updates.Result {

			if update.ID >= *offset {
				*offset = (update.ID + 1)
			}

			message := update.Message
			answer := answers[rand.Intn(len(answers))]

			telegram.SendMessage(message.Chat.ID, answer, telegrambot.SendMessageOptions{})
		}

		time.Sleep(500)
	}

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Audio

type Audio struct {
	Duration int    `json:"duration"`
	FileID   string `json:"file_id"`
	FileSize int    `json:"file_size"`
	MimeType string `json:"mime_type"`
}

type Chat

type Chat struct {
	FirstName string `json:"first_name"`
	ID        int64  `json:"id"`
	Username  string `json:"username"`
}

type Contact

type Contact struct {
	FirstName   string `json:"first_name"`
	PhoneNumber string `json:"phone_number"`
}

type Document

type Document struct {
	FileID   string    `json:"file_id"`
	FileName string    `json:"file_name"`
	FileSize int       `json:"file_size"`
	MimeType string    `json:"mime_type"`
	Thumb    PhotoSize `json:"thumb"`
}

type Keyboard

type Keyboard struct {
	Layout     [][]string `json:"keyboard"`
	Consumable bool       `json:"one_time_keyboard"`
}

Keyboard allows you to specify a specific keyboard layout to respond with

type Location

type Location struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

type Message

type Message struct {
	Chat     Chat        `json:"chat"`
	Date     int64       `json:"date"`
	From     User        `json:"from"`
	ID       int64       `json:"message_id"`
	Text     string      `json:"text"`
	Sticker  Sticker     `json:"sticker"`
	Location Location    `json:"location"`
	Document Document    `json:"document"`
	Photo    []PhotoSize `json:"photo"`
	Video    Video       `json:"video"`
	Contact  Contact     `json:"contact"`
	Audio    Audio       `json:"audio"`
}

type PhotoSize

type PhotoSize struct {
	FileID   string `json:"file_id"`
	FileSize int    `json:"file_size"`
	Height   int    `json:"height"`
	Width    int    `json:"width"`
}

type SendMessageOptions

type SendMessageOptions struct {
	ReplyMarkup *Keyboard
}

SendMessageOptions allows you to define optional parameters

type Sticker

type Sticker struct {
	FileID   string    `json:"file_id"`
	FileSize int       `json:"file_size"`
	Height   int       `json:"height"`
	Thumb    PhotoSize `json:"thumb"`
	Width    int       `json:"width"`
}

type TelegramBot

type TelegramBot struct {
	APIKey string
}

func New

func New(key string) TelegramBot

func (TelegramBot) ForwardMessage

func (b TelegramBot) ForwardMessage(chatID int64, fromChatID int64, messageID int64) (string, error)

ForwardMessage allows you to forward a message from one conversation to another

func (TelegramBot) GetUpdates

func (b TelegramBot) GetUpdates(offset int64, timeout int64) (Update, error)

GetUpdates retrieves the latest updates from the Telegram servers

func (TelegramBot) SendAudio

func (b TelegramBot) SendAudio(id int64, fileID string, options SendMessageOptions) (string, error)

SendAudio allows you to send audio to a specific target

func (TelegramBot) SendDocument

func (b TelegramBot) SendDocument(id int64, fileID string, options SendMessageOptions) (string, error)

SendDocument allows you to send a document to a specific target

func (TelegramBot) SendLocation

func (b TelegramBot) SendLocation(id int64, latitude float64, longitude float64, options SendMessageOptions) (string, error)

SendLocation allows you to send a location to a chat

func (TelegramBot) SendMessage

func (b TelegramBot) SendMessage(id int64, text string, options SendMessageOptions) (string, error)

SendMessage allows you to send a message to a specific target

func (TelegramBot) SendPhoto

func (b TelegramBot) SendPhoto(id int64, fileID string, options SendMessageOptions) (string, error)

SendPhoto allows you to send a photo to a specific target

func (TelegramBot) SendSticker

func (b TelegramBot) SendSticker(id int64, fileID string, options SendMessageOptions) (string, error)

SendSticker allows you to send a sticker to a specific target

func (TelegramBot) SendVideo

func (b TelegramBot) SendVideo(id int64, fileID string, options SendMessageOptions) (string, error)

SendVideo allows you to send a video to a specific target

func (TelegramBot) SendVoice

func (b TelegramBot) SendVoice(id int64, fileID string, options SendMessageOptions) (string, error)

SendVoice allows you to send a voicemessage to a specific target

type Update

type Update struct {
	Ok     bool         `json:"ok"`
	Result []UpdateItem `json:"result"`
}

type UpdateItem

type UpdateItem struct {
	Message Message `json:"message"`
	ID      int64   `json:"update_id"`
}

type User

type User struct {
	FirstName string `json:"first_name"`
	ID        int64  `json:"id"`
	Username  string `json:"username"`
}

type Video

type Video struct {
	Caption  string    `json:"caption"`
	Duration int       `json:"duration"`
	FileID   string    `json:"file_id"`
	FileSize int       `json:"file_size"`
	Height   int       `json:"height"`
	Thumb    PhotoSize `json:"thumb"`
	Width    int       `json:"width"`
}

Jump to

Keyboard shortcuts

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