Last active
August 20, 2022 13:30
-
-
Save SU1199/4d6860a748ad7cd2f45e95f019727559 to your computer and use it in GitHub Desktop.
truestCaller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//run `go mod init truestCaller` and copy this file as main.go.... then run `go mod tidy` to install dependencies and `go run main.go` to run the bot | |
package main | |
import ( | |
"bytes" | |
"crypto/tls" | |
"encoding/json" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os" | |
"strconv" | |
"time" | |
"unicode" | |
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" | |
) | |
var sessionToken string = "your-session-token" | |
var botKey string = `your-botfather-key` | |
func Search(inp string) string { | |
tr := &http.Transport{ | |
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | |
} | |
client := &http.Client{Transport: tr} | |
req, err := http.NewRequest("GET", "https://search5-noneu.truecaller.com/v2/search?q="+inp+"&countryCode=IN&type=4&locAddr=&placement=SEARCHRESULTS%2CHISTORY%2CDETAILS&encoding=json", nil) | |
if err != nil { | |
log.Println(err) | |
} | |
req.Host = "search5-noneu.truecaller.com" | |
req.Header.Set("Authorization", "Bearer "+sessionToken) | |
// req.Header.Set("Accept-Encoding", "gzip, deflate") | |
req.Header.Set("User-Agent", "Truecaller/11.73.7 (Android;7.1.2)") | |
resp, err := client.Do(req) | |
if err != nil { | |
log.Println(err) | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
log.Fatal(err) | |
} | |
var prettyJSON bytes.Buffer | |
error := json.Indent(&prettyJSON, body, "", "\t") | |
if error != nil { | |
log.Println("JSON parse error: ", error) | |
} | |
return prettyJSON.String() | |
} | |
func IsLetter(s string) bool { | |
for _, r := range s { | |
if !unicode.IsLetter(r) { | |
return false | |
} | |
} | |
return true | |
} | |
func main() { | |
ts := strconv.FormatInt(time.Now().UTC().UnixMilli(), 10) | |
f, err := os.OpenFile(ts+".log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer f.Close() | |
log.SetOutput(f) | |
bot, err := tgbotapi.NewBotAPI(botKey) | |
if err != nil { | |
log.Println(err) | |
} | |
bot.Debug = false | |
u := tgbotapi.NewUpdate(0) | |
u.Timeout = 30 | |
updates := bot.GetUpdatesChan(u) | |
for update := range updates { | |
if update.Message == nil { | |
continue | |
} | |
if update.Message.IsCommand() { | |
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "") | |
switch update.Message.Command() { | |
case "start": | |
msg.Text = "enter the number(10 digits) you want to search without country codes, leading zeroes or separators.\nnot gonna do the cleaning for ya lazy fuck" | |
case "status": | |
msg.Text = "I'm ok. Kinda" | |
case "help": | |
msg.Text = "enter the number(10 digits) you want to search without country codes, leading zeroes or separators.\nnot gonna do the cleaning for ya lazy fuck" | |
default: | |
msg.Text = "I don't know that command" | |
} | |
if _, err := bot.Send(msg); err != nil { | |
log.Println(err) | |
} | |
continue | |
} | |
if update.Message != nil { | |
inp := update.Message.Text | |
log.Println(update.Message.From, " ", inp) | |
valid := len(inp) | |
if valid != 10 { | |
msg := tgbotapi.NewMessage(update.Message.Chat.ID, `invalid input enter \help for help`) | |
if _, err := bot.Send(msg); err != nil { | |
log.Println(err) | |
} | |
continue | |
} | |
if IsLetter(inp) { | |
msg := tgbotapi.NewMessage(update.Message.Chat.ID, `invalid input enter \help for help`) | |
if _, err := bot.Send(msg); err != nil { | |
log.Println(err) | |
} | |
continue | |
} | |
reply := Search(inp) | |
msg := tgbotapi.NewMessage(update.Message.Chat.ID, reply) | |
if _, err := bot.Send(msg); err != nil { | |
log.Println(err) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment