Skip to content

skewb1k/tg-gateway-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

217e832 · Mar 17, 2025

History

15 Commits
Mar 15, 2025
Mar 17, 2025
Mar 17, 2025
Mar 15, 2025
Oct 13, 2024
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025

Repository files navigation

Telegram Gateway API Client for Go

This Go package provides a full-featured client for interacting with the Telegram Gateway API.

Key features:

  • Full support of Telegram Gateway API
  • Simple API
  • 100% documented
  • Context package support
  • Type-safe error handling
  • No external dependencies

Installation

go get github.com/skewb1k/tg-gateway-go/v2

Usage

Basic example of sending and verifying code:

package main

import (
	"context"
	"errors"
	"log"
	"os"

	tggateway "github.com/skewb1k/tg-gateway-go/v2"
)

func main() {
	token := os.Getenv("TGGW_API_TOKEN")

	client := tggateway.NewClient(token)

	ctx := context.Background()

	sendVerificationMessageResp, err := client.SendVerificationMessage(ctx, &tggateway.SendVerificationMessageParams{
		PhoneNumber: "11111111111",
		CodeLength:  4,
		// or set your generated code
		// Code: "1234",
	})
	if err != nil {
		// check error type if necessary
		if errors.Is(err, tggateway.ErrPhoneNumberInvalid) {
			// ...handle error
		}

		log.Fatalf("failed to send verification message: %s", err.Error())
	}

	// store recieved request id
	requestId := sendVerificationMessageResp.RequestID

	// get code from some user input.
	enteredCode := userInput.Code

	checkVerificationStatusResp, err := client.CheckVerificationStatus(ctx, &tggateway.CheckVerificationStatusParams{
		RequestID: requestId,
		Code:      enteredCode,
	})
	if err != nil {
		log.Fatalf("failed to check verification status error: %s", err.Error())
	}

	if checkVerificationStatusResp.VerificationStatus.Status.IsValid() {
		// ...grant user accesses
	}
}

Docs

For detailed documentation, method signatures, and examples, visit the package page on pkg.go.dev.

Supported go versions

This library requires Go 1.24+.

Contributing

Feel free to submit issues, fork the repository and send pull requests!

License

This project is licensed under the MIT License.