Skip to content

Your first module ​

A Goroku module is a Go struct. It declares its name and the commands it handles; everything else — the Telegram client, storage, translations, the load/unload lifecycle — comes from goroku.Base.

Generate the skeleton ​

Send this to your own Saved Messages:

.newmod Weather

Goroku replies with Weather.go: a working module with the handler stubbed out and the helpers you can use documented inline. You never start from an empty file.

TIP

.newmod is owner-only, and the name must be a valid Go type name — start it with a capital letter (Weather, not weather).

What you get ​

go
package modules

import "goroku/goroku"

type Weather struct {
	goroku.Base
}

func (m *Weather) Name() string { return "Weather" }

func (m *Weather) Strings() map[string]string {
	return map[string]string{
		"name":             "Weather",
		"_cls_doc":         "What Weather does",
		"_cmd_doc_weather": "What .weather does",
		"no_args":          "❌ <b>Send some text or reply to a message</b>",
	}
}

func (m *Weather) Commands() map[string]goroku.CommandHandler {
	return map[string]goroku.CommandHandler{
		"weather": m.WeatherCmd,
	}
}

func (m *Weather) WeatherCmd(msg *goroku.Message) error {
	input := msg.ArgsOrReply()
	if input == "" {
		return msg.Answer(m.T("no_args", "❌ <b>Send some text or reply to a message</b>"))
	}
	return msg.Answer("<b>Weather got:</b> <code>" + input + "</code>")
}

Only Name and Commands are required. Strings is there because you almost always want it, but you can delete it.

Install it ​

Send the file to any chat, reply to it, and send:

.loadmod

Goroku compiles it as a native Go plugin and registers the command. .weather hi now answers.

Native plugins run in your process

A module runs as ordinary Go code inside the userbot with your Telegram session. Only install modules whose source you have read. See Installing a module.

Change it ​

Edit the handler and .loadmod the new file. Same struct name replaces the running module.

go
func (m *Weather) WeatherCmd(msg *goroku.Message) error {
	city := msg.Args()
	if city == "" {
		return msg.Answer(m.T("no_city", "❌ <b>Which city?</b>"))
	}
	return msg.Answer("🌤 <b>" + city + "</b>: sunny, 22°C")
}

Next ​

Released under the GNU AGPL v3 License.