Skip to content
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

Support forwarding messages with attachments #1

Open
dstdfx opened this issue Feb 19, 2022 · 10 comments
Open

Support forwarding messages with attachments #1

dstdfx opened this issue Feb 19, 2022 · 10 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dstdfx
Copy link
Owner

dstdfx commented Feb 19, 2022

For now, only text messages are supported but it's not a big deal to add other types.
See handler whatsapp implementation:
https://github.com/Rhymen/go-whatsapp/blob/v0.1.1/handler.go

@dstdfx dstdfx added enhancement New feature or request good first issue Good for newcomers labels Feb 19, 2022
@abalasky
Copy link

I'll go ahead and take this issue! New to this repo so any notes on how best to start?

@dstdfx
Copy link
Owner Author

dstdfx commented Feb 23, 2022

Hi, sure go for it! I'd recommend running it first and finding out how it works on top, then it would be easier to tackle the issue.

New messages support can be done by test message example:
https://github.com/dstdfx/twbridge/blob/main/internal/domain/domain.go#L78
https://github.com/dstdfx/twbridge/blob/main/internal/whatsapp/events_provider.go#L107
https://github.com/dstdfx/twbridge/blob/main/internal/handler/events_handler.go#L243
https://github.com/dstdfx/twbridge/blob/main/internal/manager/clients_manager.go#L132

I'm planning to add some schema of how these things work together but a bit short on time at the moment.

@abalasky
Copy link

abalasky commented Mar 1, 2022

Awesome! I think i've finally parsed the code and got a good grip on everything. Moving to implement this functionality over the next two days. Quick question. I see in some comments here in root.go you have a TODO for webhooks. Whats the reasoning to migrate this to webhooks and should that be an issue after this is completed as well?

@dstdfx
Copy link
Owner Author

dstdfx commented Mar 1, 2022

Good, glad to hear that! The webhook is just an alternative way to get updates from Telegram API, long story short - it avoids long polling from the client's side. It's not a blocker, just a way to improve the service.

@abalasky
Copy link

abalasky commented Mar 1, 2022

So i've gone ahead and written all the code for the forwarding but while testing can't even get past the QR code scan. I swithced back to the main branch (and even recloned) to see if it was something I did but it seems I must've never tested getting past the QR step.

Getting a panic: export TELEGRAM_API_TOKEN=<API_TOKEN>; ./twbridge
{"level":"info","timestamp":"2022-03-01T01:45:26.188152-08:00","caller":"app/root.go:43","short_message":"twbridge is running...","service":"twbridge","build_commit":"11244507f96859ff4927f8c37132dd802e40fbaa","build_tag":"v0.2.0","build_date":"20220301","go_version":"go1.17.5"}
{"level":"debug","timestamp":"2022-03-01T01:45:32.37526-08:00","caller":"handler/events_handler.go:90","short_message":"handle start","service":"twbridge","username":"","chat_id":1921574139}
{"level":"debug","timestamp":"2022-03-01T01:45:42.285684-08:00","caller":"handler/events_handler.go:103","short_message":"handle whatsapp login","service":"twbridge","username":"","chat_id":1921574139}
{"level":"debug","timestamp":"2022-03-01T01:45:43.029875-08:00","caller":"handler/events_handler.go:158","short_message":"QR-code has been sent","service":"twbridge"}
{"level":"error","timestamp":"2022-03-01T01:45:44.862776-08:00","caller":"whatsapp/events_provider.go:52","short_message":"got error","service":"twbridge","error":"server closed connection,code: 1000,text: "}
{"level":"debug","timestamp":"2022-03-01T01:45:44.862852-08:00","caller":"whatsapp/events_provider.go:77","short_message":"trying to restore whatsapp session...","service":"twbridge","chat_id":1921574139,"attempt":1}
panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 12 [running]:
github.com/Rhymen/go-whatsapp.newInfoFromReq(0xc00053a000)
/Users/alex/go/pkg/mod/github.com/!rhymen/[email protected]/session.go:63 +0x951
github.com/Rhymen/go-whatsapp.(*Conn).Login(0xc00012e800, 0x0)
/Users/alex/go/pkg/mod/github.com/!rhymen/[email protected]/session.go:268 +0xd36
github.com/dstdfx/twbridge/internal/handler.(*EventsHandler).HandleLoginEvent(0xc000482000, 0xc000115948)
/Users/alex/csci/opensource/testing/twbridge/internal/handler/events_handler.go:163 +0x508
github.com/dstdfx/twbridge/internal/manager.(*Manager).Run(0xc0003ba000, {0x147e118, 0xc000307140})
/Users/alex/csci/opensource/testing/twbridge/internal/manager/clients_manager.go:93 +0xb43
created by github.com/dstdfx/twbridge/cmd/twbridge/app.Start
/Users/alex/csci/opensource/testing/twbridge/cmd/twbridge/app/root.go:83 +0xa85

Looks like this is the current state of the repo. Will dig into this tomorrow myself but any ideas here? Does this happen on your machine?

@dstdfx
Copy link
Owner Author

dstdfx commented Mar 1, 2022

Just checked it on the main branch - works fine. The panic comes from the client library that is used to work with WhatsApp (https://github.com/Rhymen/go-whatsapp), it might not support all versions of WhatsApp Web API.
So make sure you have the "multi-device beta" feature turned off (whatsapp>settings>linked devices) when you scan a QR code.
There's a similar issue: Rhymen/go-whatsapp#644

I'm planning to switch to another library that works with WhatsApp Web API, the current is poorly designed, and looks like nobody maintains it.
I haven't tested this one https://github.com/tulir/whatsmeow yet but it claims multi-device API support.

@abalasky
Copy link

abalasky commented Mar 4, 2022

So unfortunately it looks like most recent build in IOS for USA is no longer multi-device beta. There is no way for me to disable it and I've tried a friends phone too. Recloned and tried on main branch and I'm getting the same error when attempting to test :(

@dstdfx
Copy link
Owner Author

dstdfx commented Mar 4, 2022

As a workaround before we switched to multi-device library, you can submit a PR and I'll test it. What do you think?

@abalasky
Copy link

abalasky commented Mar 4, 2022

Yes I will do but I'm not 100% sure about my implementation - I tried following similar approach to how QR code byte array was uploaded to Telegram with bytes for image coming from message.Download() on line 163 of events_provider.go.

@abalasky
Copy link

abalasky commented Mar 4, 2022

Just did! I dug into the whatsmeow and think I can make the refactor to that library. Will try to start testing tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants