celestix / gotgproto Goto Github PK
View Code? Open in Web Editor NEWA wrapper for Go Telegram Client, i.e. gotd/td.
License: GNU General Public License v3.0
A wrapper for Go Telegram Client, i.e. gotd/td.
License: GNU General Public License v3.0
ext.Context
uses random.Int63
in its generateRandomID
method which causes race conditions on parallel request sending.
i use this to get participants in group but report error 400: CHANNEL_INVALID
_, ok := client.API().ChannelsGetParticipants(context.Background(), &tg.ChannelsGetParticipantsRequest{Channel: &tg.InputChannel{ChannelID: -1001933086941}, Filter: &tg.ChannelParticipantsRecent{}})
fmt.Println("Ok: ", ok)
Please help me to fix!
TdataSession Error reporting method does not exist
The example code has already expired
Now you can't easily access takeout session, so I think adding this feature would be pretty cool.
How to log in without entering a code from your mobile phone? And why then use the pyrogram / tdata session at all if phone verification is still required?
Even when i pass in a string of a session it still tries to send a code and get a code from me. Additionally it creates the session storage files. you see i need to store the session in the mongodb and how do i properly extract it so that when i create a new client next time the server restarts it wont ask me the code that comes to telegram.
P.S i extract the session with client.ExportStringSession() maybe there is a better way
Dear team,
First of all i wanted to thank you for such great library, awesome job!
I have an question: i need to fetch all channels, even if its private, where i am an admin. For public channels, i m using channels.getAdminedPublicChannels and it works fine.
for example, web telegram is able to show me all channels, even if it is private and i am an admin there. Any idea how it could be done with hekp of MTProto?
thanks
Add Args()
method for ext.Update
and Plain()
method for entity-root
This can greatly reduce the difficulty of use and increase the number of people using it.
I'm trying to add contextual logging using zerolog and context.Context.
I'm adding handler to dispatcher:
dispatcher.AddHandler(
handlers.Message{
Callback: injectContext,
Filters: nil,
UpdateFilters: nil,
Outgoing: true,
},
)
injectContext:
func injectContext(ctx *ext.Context, update *ext.Update) error {
ctx.Context = log.
With().
Int("update_effective_message_id", update.EffectiveMessage.ID).
Logger().
WithContext(ctx)
_, _ = ctx.Reply(update, update.EffectiveMessage.Message.Message, nil) // for debug purposes
return nil
}
If you are not familiar with zerolog, this code just creates new logger with injected field and uses context.WithValue to store it in ctx.
But this function always panics with large traceback:
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020740398 stack=[0xc020740000, 0xc040740000]
fatal error: stack overflow
runtime stack:
runtime.throw({0x1010f0601?, 0x101cdf180?})
/usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x31e4f4d88 sp=0x31e4f4d58 pc=0x10003853d
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1105 +0x5bd fp=0x31e4f4f38 sp=0x31e4f4d88 pc=0x1000526bd
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:574 +0x8b fp=0x31e4f4f40 sp=0x31e4f4f38 pc=0x100069eab
goroutine 41 [running]:
github.com/anonyindian/gotgproto/ext.(*Context).Done(0xc000694400?)
<autogenerated>:1 +0x3f fp=0xc0207403a8 sp=0xc0207403a0 pc=0x100b3895f
context.(*valueCtx).Done(0x0?)
<autogenerated>:1 +0x2a fp=0xc0207403c0 sp=0xc0207403a8 pc=0x1000b590a
github.com/anonyindian/gotgproto/ext.(*Context).Done(0x0?)
<autogenerated>:1 +0x2b fp=0xc0207403d8 sp=0xc0207403c0 pc=0x100b3894b
context.(*valueCtx).Done(0x0?)
<autogenerated>:1 +0x2a fp=0xc0207403f0 sp=0xc0207403d8 pc=0x1000b590a
github.com/anonyindian/gotgproto/ext.(*Context).Done(0x0?)
<autogenerated>:1 +0x2b fp=0xc020740408 sp=0xc0207403f0 pc=0x100b3894b
context.(*valueCtx).Done(0x0?)
...
Am I doing something wrong? Are there any ways to use WithValue with ext.Context?
Used dependencies:
github.com/anonyindian/gotgproto v1.0.0-beta11
github.com/gotd/td v0.82.0
github.com/rs/zerolog v1.30.0
(I've deleted unrelated)
Allways stuck at Rec [phone|code|...]
. Works fine with make
of channels:
func GetWebAuth() *webAuth {
return &webAuth{
phoneChan: make(chan string),
codeChan: make(chan string),
passwdChan: make(chan string),
}
}
When I run:go run main.go
GoTGProto v1.0.0-beta17, Copyright (C) 2024 Anony <github.com/celestix>
Licensed under the terms of GNU General Public License v3
The terminal keeps showing this, why is this problem stuck?
Is it related to the certificate?
Another issue is that when running on a brand new computer, it runs very slowly for the first time. Is it a problem downloading certificates? Where is the certificate stored? Can I directly call the local certificate
Add Download* methods to download various available media, use td/telegram/downloader
for the purpose.
because, in somewhere like cn, can't not connect to tg server directly.
If use memery session,Frequent reacquisition of sessions will be restricted by the server
But use Sqlite Session will Compilation failed when cross compiling
Because gorm default sql drivers is github.com/mattn/go-sqlite3,It is cgo package
So can replace it to https://github.com/glebarez/sqlite
After verifying the authorization, I found that I need to revalidate the code verification permissions the next day
Can the expiration time be set in the files saved during the session? For example, the number of valid days: 30 days or 365 days, permanently valid, etc
Tonight I will describe it in more detail.
I'm trying to log in, it looks like it's a session error.
(I accidentally closed the post)
Restoring stored sessions doesn't work in linux while they work properly with windows.
Describe the bug
When using html.String with ctx.Reply, html text is not parsed, but message sends and TG return MESSAGE_EMPTY error:
_, err := ctx.Reply(
update,
[]styling.StyledTextOption{html.String(nil, "<code>Hi!</code>")},
nil,
)
returns err: send styled text: rpcDoRequest: rpc error code 400: MESSAGE_EMPTY
Almost the same code, using pure gotg works just fine.
To Reproduce
Steps to reproduce the behavior:
ctx.Reply
[]styling.StyledTextOption{html.String(nil, htmlMessage)}
, where htmlMessage
- any text with htmlExpected behavior
Sends HTML parsed message
Environment
MAC OS, M1, github.com/anonyindian/gotgproto v1.0.0-beta10, User bots.
Hi everyone! So I need to get invitation links of created chats, but I can't figure out how to do so. This is my code:
ppackage client
import (
"log"
"tclient/internal/config"
"github.com/anonyindian/gotgproto"
"github.com/anonyindian/gotgproto/sessionMaker"
)
func Create(c *config.AppConfig) (*gotgproto.Client, error) {
clientType := gotgproto.ClientType{
Phone: c.Phone,
}
client, err := gotgproto.NewClient(
c.AppId,
c.ApiHash,
clientType,
&gotgproto.ClientOpts{
Session: sessionMaker.NewSession("tclient", sessionMaker.Session),
},
)
if err != nil {
log.Fatalln("failed to start client:", err)
}
chat, err := client.CreateContext().CreateChat("test", []int64{})
if err != nil {
panic(err)
}
res := map[string]string{
"chatID": chat.GetID(),
"title": chat.GetTitle(),
"joinLink": ????
}
}
Please help me! Thanks!
HI.
Have "Compilation finished with exit code 2"
just tried running the example echo-bot
# github.com/anonyindian/gotgproto/ext
../../go/pkg/mod/github.com/anonyindian/[email protected]/ext/context.go:174:14: cannot use request.Reaction (variable of type []tg.ReactionClass) as type string in assignment
How can i create session string using dc id and auth key pare?
Add helpers in entityhelpers and stylinghelpers from the parsemode package to mention users with their usernames or user ids using telegram's deeplinks.
To Mention With User ID: tg://user?id=
To Mention With User ID: tg://resolve?domain=
It has not been implemented yet but was left in codes by mistake.
How to get paticipaint in channel/group? please help me!
Code: https://pastebin.com/xMsVvqw4 < api and hash just examples.
\context.go:174:14: cannot use request.Reaction
How can i fix it ?
Here the value should be false
since it is a chat in line 142. https://github.com/anonyindian/gotgproto/blob/191c68cf73cf1e0c4317b3e4d8c252907d6ea6cb/types/chat.go#L141-L143
Here the value should be true
since it is a chat in line 147. https://github.com/anonyindian/gotgproto/blob/191c68cf73cf1e0c4317b3e4d8c252907d6ea6cb/types/chat.go#L146-L148
Is really needed for Dispatcher
I want to create many clients, and they are in one program, for example I want to create /login then I want to create one more client, and allow for multiple clients.
I don't know how to forward a message.
func echo(ctx *ext.Context, update *ext.Update) error {
ctx.ForwardMessage(Chat,
ToChatID,
&tg.MessagesForwardMessagesRequest{})
}
Hello,
thank you for this wonderful library, but I was looking for a way to retrieve the latest messages in a specific chat by its ID only, and I could not figure out how.
&gotgproto.ClientOpts{
Session: sessionMaker.StringSession("test").
// Sqlite session name (if you're not using memory session)
// i.e. InMemory in ClientOpts is set to false
// It will be saved as my_session.session as per this example.
Name("my_session"),
I want to set the session, but the following error occurs. Using SimpleSession() is normal
failed to start client: invalid character 'µ' looking for beginning of value
I have an error trying to run go script in Ubuntu and Amazon Linux2, in mac OS works rightly but in these SO i tested i have this error:
# github.com/anonyindian/gotgproto/ext
../go/pkg/mod/github.com/anonyindian/[email protected]/ext/context.go:174:14: cannot use request.Reaction (variable of type []tg.ReactionClass) as type string in assignment
For reproduce i only do ->
go run tg_bot.go
Few month ago was working , but not atm..
Hi there
I'm wondering if its possible to init the client as user without the need to provide the 2FA code? My Telegram account does not have 2FA enabled.
tgClient, err := gotgproto.NewClient(
cfg.AppId,
cfg.AppHash,
gotgproto.ClientTypePhone("REDACTED"),
&gotgproto.ClientOpts{
Session: sessionMaker.SqlSession(sqlite.Open("echobot")),
},
)
I'm aware of other libs, tdl in JS for example that do not require the 2FA code, just appId and appHash.
Thanks!
I tried to run this example, but no 2FA code is being sent to me at all. I tried on different systems.
System Info
OS: Linux artixlinux 6.8.2-artix1-1
Golang Version: go version go1.22.1 linux/amd64
gotgproto Version: v1.0.0-beta17
go.mod
gbin.me/5a7
main.go file
gbin.me/5a6
I have a problem, when i create a new client it starts handling the authentication itself asking me the code in the terminal, and though it is good, it does it in the terminal is what is bad.
You see in my platform people will be sending the data through rest and then i have to pass it in manually through the functions it canе the handled through terminal. Is there a way to either cancel the option of terminal auth, or switching it to a different approach. Cuz because it tries to manually handle the authentication i cannot use regular client.Auth().SignIn() with it. Thanks in advance
Automatically fetch the dialog list and save its peers in peer storage whenever a new session is created.
As discussed in #19, text is a raw unbounded interface currently which can cause problems in many ways. To avoid it, we should add a bounded interface with at least one private method to prevent people breaking the library from external manipulation.
type InputText interface{
isAPrivateMethodYetToBeNamed()
}
Hi everyone, I tried your app on a newly created telegram account and immediately after authorization I got a ban from telegram. I'm not sure if it's a bug, but somehow telegram knows how to distinguish between real login and login through this library.
I have the following problem. I would like to fetch the whole chat history of a chat (
m, err := ctx.GetMessages(chatId, []tg.InputMessageClass{ &tg.InputMessageID{ID: offsetId}, }))
and then switch to live listen mode with (
clientDispatcher := client.Dispatcher clientDispatcher.AddHandlerToGroup(handlers.NewMessage(filters.Message.Chat(chatId), printMessage), 1)
).
Unfortunately I always get the error peers not found. But if I use this line
clientDispatcher.AddHandlerToGroup(handlers.NewMessage(filters.Message.Chat(chatId), printMessage), 1)
alone and then run my programm again with the fetch history, the peer is found because handlers.NewMessage
adds the correct peer to the cache. Is there a possibility how I can execute the peers function which is called in handlers.NewMessage
before I execute both operations?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.