Skip to content
forked from NicoNex/echotron

Library for telegram bots written in pure go.

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
LICENSE
Notifications You must be signed in to change notification settings

Jhoscy/echotron

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
LICENSE

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%