Skip to content
JhoscyPublic
forked from NicoNex/echotron

About

Library for telegram bots written in pure go.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

82 Commits

Folders and files

Repository files navigation

echotron Language GoDoc Go Report Card License

Library for telegram bots written in pure go

Fetch with

go get -u github.com/NicoNex/echotron

Usage

A very simple implementation:

package main

import "github.com/NicoNex/echotron"

type bot struct {
    chatId int64
    echotron.Api
}

func newBot(api echotron.Api, chatId int64) echotron.Bot {
    return &bot{
        chatId,
        api,
    }
}

func (b *bot) Update(update *echotron.Update) {
    if update.Message.Text == "/start" {
        b.SendMessage("Hello world", b.chatId)
    }
}

func main() {
    dsp := echotron.NewDispatcher("TELEGRAM TOKEN", newBot)
    dsp.Run()
}

Also proof of concept with self destruction for low ram usage

package main

import "github.com/NicoNex/echotron"

type bot struct {
    chatId int64
    echotron.Api
}

var dsp echotron.Dispatcher

func newBot(api echotron.Api, chatId int64) echotron.Bot {
    var bot = &bot{
        chatId,
        api,
    }
    echotron.AddTimer(bot.chatId, "selfDestruct", bot.selfDestruct, 60)
    return bot
}

func (b *bot) selfDestruct() {
    b.SendMessage("goodbye", b.chatId)
    echotron.DelTimer(b.chatId, "selfDestruct")
    dsp.DelSession(b.chatId)
}

func (b *bot) Update(update *echotron.Update) {
    if update.Message.Text == "/start" {
        b.SendMessage("Hello world", b.chatId)
    }
}

func main() {
    dsp = echotron.NewDispatcher("TELEGRAM TOKEN", newBot)
    dsp.Run()
}

About

Library for telegram bots written in pure go.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages