telego

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

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

Go to latest
Published: Dec 1, 2015 License: MIT Imports: 3 Imported by: 0

README

Telego

A simple wrapper for create telegram bot

Install

$ go get github.com/reinventer/telego

Make Bot

You need to talk with BotFather and follow a few simple steps. When you've created a bot, you received your authorization token. Save it.

Write a simple code:

package main

import "github.com/reinventer/telego"

func main() {
	b, err := telego.NewBot("token")
	if err != nil {
		panic(err)
	}

	b.SetHandlerWithHelp("/test", "show test message", TestHandler)
	b.SetDefaultHandler(DefaultHandler)
	b.Run()
}

func TestHandler(update *telego.Update) {
	update.Reply("It's a test message, " + update.Message.From.UserName)
	update.Reply("Parameter: '" + update.Params + "'")
}

func DefaultHandler(update *telego.Update) {
	update.Reply("Unknown command")
	update.Reply("Try to use /help")
}

Compile and run it (don't forget to replace token).

Now talk with your bot, try commands /test, /test params, /help

License

See the LICENSE file for license rights and limitations (MIT).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	sync.RWMutex
	Api *tgbotapi.BotAPI
	// contains filtered or unexported fields
}

func NewBot

func NewBot(token string) (*Bot, error)

func (*Bot) Run

func (b *Bot) Run() error

func (*Bot) SendTextMessage

func (b *Bot) SendTextMessage(chat_id int, text string) error

func (*Bot) SetDefaultHandler

func (b *Bot) SetDefaultHandler(handler HandlerFunc)

func (*Bot) SetHandler

func (b *Bot) SetHandler(command string, handler HandlerFunc)

func (*Bot) SetHandlerWithHelp

func (b *Bot) SetHandlerWithHelp(command string, description string, handler HandlerFunc)

type HandlerFunc

type HandlerFunc func(*Update)

type Update

type Update struct {
	tgbotapi.Update
	Bot    *Bot
	Params string
}

func (*Update) Reply

func (u *Update) Reply(text string) error

Jump to

Keyboard shortcuts

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