Getting started

Installation

gogram is a pure-Go module. There is nothing to compile separately, no cgo, no system dependencies. Add the package and import it.

Requirements

  • Go 1.21 or newer. The library uses generics and the newer net/http context APIs.
  • An API id and hash. You will get this from Telegram in a minute; see below.
  • Outbound TCP on 443 to Telegram's DC IP ranges. If you are behind a firewall that blocks 443 to 149.154.x.x, set up a proxy — see Proxies.

That is it. No CGo, no native dependencies, builds on every platform Go targets including js/wasm.

Adding to your project

From an existing module:

go get github.com/amarnathcjd/gogram/telegram@latest
go get github.com/amarnathcjd/gogram/telegram@latest

Or from a clean directory, initialise a module first with go mod init your.thing/bot and then run go get. There is only one import path you ever need to remember:github.com/amarnathcjd/gogram/telegram. Everything else is internal.

Getting API credentials

Every Telegram client — bot or user — needs an api_id and api_hash. These identify the application, not the user. You get them once from my.telegram.org, paste them into your code, and never touch them again.

  1. Open my.telegram.org and log in with a phone number.
  2. Pick API development tools.
  3. Fill in any name and short name. Pick Other for platform. Submit.
  4. Copy the App api_id (an integer) and App api_hash (a 32-char hex string).

If you only need a bot, you also need a bot token from @BotFather. The api id/hash and the bot token are different things and you need both.

First compile

Throw this in a main.go and run it to make sure the module is wired correctly:

main.go
package main

import (
	"fmt"
	"github.com/amarnathcjd/gogram/telegram"
)

func main() {
	fmt.Println("gogram", telegram.Version)
}
package main

import (
	"fmt"
	"github.com/amarnathcjd/gogram/telegram"
)

func main() {
	fmt.Println("gogram", telegram.Version)
}

If it prints a version string, you are good. Next stop: Your first bot.