Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.
/ tgah Public archive

telegram authorization in telegram without using a widget

License

Notifications You must be signed in to change notification settings

tioffs/tgah

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TGAH - telegram Authorization

License: MIT

Example of authorization in telegram without using a widget

Installation

Easy to use

example http.Server: example

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/tioffs/tgah"
)

func main() {
	// phone number no +
	phone := "79000000000"
	// you bot ID
	botID := 1234567899
	// you bot domain
	domain := "yousite.com"
	// set setting
	tgah.Setting(int32(botID), domain)
	// send push notify user (Auth)
	if confirm := tgah.SendPhoneTelegram(context.Background(), phone, nil);
		confirm.Error != nil || confirm.Status != tgah.Success {
		panic(confirm.Error)
	}
	// check accept user is auth you bot
	for {
		<-time.After(3 * time.Second)
		confirm := tgah.ChecksIsAcceptUserAuth(context.Background(), phone, nil)
		if confirm.Error != nil {
			panic(confirm.Error)
		}
		switch confirm.Status {
		case tgah.Success:
			fmt.Println(confirm.User)
			break
		case tgah.Cancel:
			panic(confirm.Error)
		case tgah.Pending:
			println(tgah.Pending)
		}
	}
}