-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
invalid memory address or nil pointer dereference - Test with example echo_bot/main.go #19
Comments
Hi @DiMiTriFrog, thanks for reporting the issue. |
Sure, thanks!
|
Hey @DiMiTriFrog! Can you check its behaviour in a group chat and does it work fine for non contacts? Please also send a screenshot of what you exactly did when this panic occurred in telegram. |
Sure. When these logs was when I sent some directly, but same error when I send message to group that contains the TG ID using like a bot. 2022/11/17 22:51:28 runtime error: invalid memory address or nil pointer dereference |
Hey @DiMiTriFrog, sorry for the late reply! I tried to reproduce this panic but couldn't, example worked very fine in my case. Looks like something went wrong at your side while writing the session to the file. Please delete the |
Same... What SO are you using? I will try with server with same SO than you to try if works, maybe my mac is down. |
Sorry, but what do you mean by "SO"? |
Oh, It seems like the problem is associated with the modifications you're making to echobot example. It's working fine for me for all cases including replying to a message. |
No... This issue post was copying the echo bot, but i'm using the api of telegram not botfather, so I removed the handles of callback buttons from code let just the echo function and handle (I tried without removing it and same issue). |
Do you mean, you were trying to use that example for a user account instead of a telegram bot? |
Right |
Oh, You should have told this before, I was assuming that you're trying it over a bot all the way because that example was written in view of bots. Please give me some time to test echobot example on a user account, I'll notify you once done. |
for fix issue:
|
Sorry, but what's the difference in it and the original example? |
original:
fix:
|
I still don't understand what you mean, please elaborate a bit. |
I had the same problem. I put a comma - that's the only difference. After that I ran the code without errors |
Eh, doesn't seem like that comma was the culprit, probably something goes wrong conditionally during the runtime handling. But the comma, nah I don't think so. |
Hello @DiMiTriFrog, Please tell if you're still facing this problem. |
I face the same issue. type Presentation struct {
telegramClient *telegram.Client
telegramSender *message.Sender
telegramApi *tg.Client
telegramManager *peers.Manager
protoClient *gotgproto.Client
storage storage.Interface
clientService *client.Service
}
func MustNewTelegramPresentation(
clientService *client.Service,
telegramAppID int,
telegramAppHash string,
telegramPhoneNumber string,
telegramSessionStorageFullPath string,
storage storage.Interface,
) Presentation {
protoClient, err := gotgproto.NewClient(telegramAppID, telegramAppHash, gotgproto.ClientType{
Phone: telegramPhoneNumber,
}, &gotgproto.ClientOpts{
DisableCopyright: true,
Session: sessionMaker.NewSession(telegramSessionStorageFullPath, sessionMaker.Session),
})
utils.Check(err)
protoClient.Dispatcher.AddHandler(handlers.NewCommand("echo", echo))
api := protoClient.API()
presentation := Presentation{
clientService: clientService,
storage: storage,
protoClient: protoClient,
telegramApi: api,
telegramSender: message.NewSender(api),
telegramManager: peers.Options{}.Build(api),
}
return presentation
}
func echo(ctx *ext.Context, update *ext.Update) error {
_, err := ctx.Reply(update, update.EffectiveMessage, nil)
return err
}
func (r *Presentation) Run() error {
ctx := r.protoClient.CreateContext()
_, err := ctx.SendMessage(ctx.Self.ID, &tg.MessagesSendMessageRequest{Message: "Fun telegram initialized!"})
if err != nil {
return err
}
err = r.protoClient.Idle()
return err
} Bot correctly sends 2023/07/09 00:02:52 runtime error: invalid memory address or nil pointer dereference
goroutine 65 [running]:
runtime/debug.Stack()
/usr/local/go/src/runtime/debug/stack.go:24 +0x65
github.com/anonyindian/gotgproto/dispatcher.(*NativeDispatcher).handleUpdate.func2()
/Users/teadove/go/pkg/mod/github.com/anonyindian/gotgproto@v1.0.0-beta10/dispatcher/dispatcher.go:139 +0x94
panic({0x100e63b20, 0x101c5da90})
/usr/local/go/src/runtime/panic.go:884 +0x213
github.com/anonyindian/gotgproto/dispatcher.(*NativeDispatcher).handleUpdate(0xc0001a0b40, {0x1012ca7c0?, 0xc000506000}, {0x0, 0xc0003bb620, 0xc0003bb680, 0xc0003bb6e0}, {0x1012da8f8, 0xc000402280})
/Users/teadove/go/pkg/mod/github.com/anonyindian/gotgproto@v1.0.0-beta10/dispatcher/dispatcher.go:160 +0x44e
github.com/anonyindian/gotgproto/dispatcher.(*NativeDispatcher).dispatch(...)
/Users/teadove/go/pkg/mod/github.com/anonyindian/gotgproto@v1.0.0-beta10/dispatcher/dispatcher.go:125
github.com/anonyindian/gotgproto/dispatcher.(*NativeDispatcher).Handle(0xc0000be7e0?, {0x1012ca7c0, 0xc000506000}, {0x1012dba98?, 0xc0000be7e0})
/Users/teadove/go/pkg/mod/github.com/anonyindian/gotgproto@v1.0.0-beta10/dispatcher/dispatcher.go:116 +0x333
github.com/gotd/td/telegram.(*Client).processUpdates(0xc0004b2400, {0x1012dba98?, 0xc0000be7e0?})
/Users/teadove/go/pkg/mod/github.com/gotd/td@v0.83.0/telegram/handle_updates.go:27 +0x5ba
github.com/gotd/td/telegram.(*Client).handleUpdates(0xc0001bbc80?, 0x1009cbdde?)
/Users/teadove/go/pkg/mod/github.com/gotd/td@v0.83.0/telegram/handle_updates.go:53 +0x5f
github.com/gotd/td/telegram.clientHandler.OnMessage({0x10108a061?}, 0xe?)
/Users/teadove/go/pkg/mod/github.com/gotd/td@v0.83.0/telegram/conn_builder.go:26 +0x19
github.com/gotd/td/telegram/internal/manager.(*Conn).OnMessage(0x10001092a?, 0x10108a061?)
/Users/teadove/go/pkg/mod/github.com/gotd/td@v0.83.0/telegram/internal/manager/conn.go:169 +0x28
github.com/gotd/td/internal/mtproto.(*Conn).handleMessage(0xc0005382c0, 0x64a9cefceb664401, 0xc0001ac498)
/Users/teadove/go/pkg/mod/github.com/gotd/td@v0.83.0/internal/mtproto/handle_message.go:41 +0x306
github.com/gotd/td/internal/mtproto.(*Conn).consumeMessage(0xc0005382c0, {0x1012ca7c0, 0xc000498d70}, 0x0?)
/Users/teadove/go/pkg/mod/github.com/gotd/td@v0.83.0/internal/mtproto/read.go:83 +0x293
github.com/gotd/td/internal/mtproto.(*Conn).readLoop.func2()
/Users/teadove/go/pkg/mod/github.com/gotd/td@v0.83.0/internal/mtproto/read.go:207 +0x8e
created by github.com/gotd/td/internal/mtproto.(*Conn).readLoop
/Users/teadove/go/pkg/mod/github.com/gotd/td@v0.83.0/internal/mtproto/read.go:198 +0x2d8 Full code locates here: https://github.com/TeaDove/fun-telegram/blob/feature/persistent-storage/internal/presentation/telegram/telegram.go Ty in advance for any help! |
bloody The problem was with |
Agreed! I should handle it some other way, a raw interface is really very error-prone. |
I'm having this output trying to run the example of echo_bot.
macOs 13.0
go version go1.19.3 darwin/amd64
First time bot asked for code, I logged in and receive that user start, but when I type some and send from a contact to the tg user i'm using as bot i'm receiving this output...
The text was updated successfully, but these errors were encountered: