Example of authorization in telegram without using a widget
-
go get -d github.com/tioffs/tgah@master
- Setting up a bot
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)
}
}
}