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

Improve compatibility with spectrum2 #5

Open
evgenyh opened this issue Mar 27, 2019 · 92 comments
Open

Improve compatibility with spectrum2 #5

evgenyh opened this issue Mar 27, 2019 · 92 comments
Labels
enhancement New feature or request help wanted Someone else is free to do this

Comments

@evgenyh
Copy link

evgenyh commented Mar 27, 2019

trying to get this plugin to work with spectrum2 libpurple backend

  1. I was able to compile it
  2. spectrum2 able to talk to this plugin.
  3. on attempt to add account I only getting following message in chat window and in logs :
    "error during login: qr code scan timed out"

P.S> maybe I'm doing something wrong.
thanks

piece from log :

8904: 2019-03-27 14:27:22,490 INFO  libpurple: account:Connecting to account [email protected].
8904: 2019-03-27 14:27:22,490 INFO  libpurple: connection:Connecting. gc = 0x23eb0c0
8904: 2019-03-27 14:27:23,751 INFO  libpurple: gowhatsapp:Recieved: at 0 id  remote [email protected] sender  (fromMe 0)
8904: 2019-03-27 14:27:23,752 INFO  backend: conv_write_im()
8904: 2019-03-27 14:27:23,752 INFO  backend: conv_write_im(): ignoring a system message
...
8953: 2019-03-27 14:28:25,752 INFO  libpurple: gowhatsapp:Recieved: at 0 id (null) remote (null) sender (null) (fromMe 0)
8953: 2019-03-27 14:28:25,752 INFO  libpurple: connection:Connection error on 0x181f0c0 (reason: 0 description: error during login: qr code scan timed out

thanks

@hoehermann
Copy link
Owner

hoehermann commented Mar 27, 2019

Nice.

The QR code is supposed to be shown as an image within an instant message flagged as a system message. It looks like system messages are ignored in your set-up. Can you configure spectrum2 to consider all messages? Alternatively, try to change libgowhatsapp.c, line 135 from

    flags |= PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG;

to

    flags |= PURPLE_MESSAGE_NO_LOG;

.

@evgenyh
Copy link
Author

evgenyh commented Mar 27, 2019

yep. that is what I thought .
according to spectrum code : https://github.com/SpectrumIM/spectrum2/blob/0076bda7b5040d69f7d8afaf5bdf3db596202f5a/backends/libpurple/main.cpp#L1506

//Ignore system messages as those are normally not true messages in the XMPP sense
		if (flags & PURPLE_MESSAGE_SYSTEM) {
			LOG4CXX_DEBUG(logger, "conv_write_im(): ignoring a system message");
			return;
}

this is not configurable, and changing it will have system wide effect.
I'll try to change purple-gowhatsapp code as you suggest

@evgenyh
Copy link
Author

evgenyh commented Mar 27, 2019

changed line you suggested

now i getting these messages :

20445: 2019-03-27 17:30:11,792 INFO  backend: Creating account with name '[email protected]' and protocol 'prpl-hehoe-gowhatsapp'
20445: 2019-03-27 17:30:11,792 INFO  libpurple: account:Connecting to account [email protected].
20445: 2019-03-27 17:30:11,792 INFO  libpurple: connection:Connecting. gc = 0x1a440c0
20445: 2019-03-27 17:30:12,752 INFO  libpurple: gowhatsapp:Recieved: at 0 id  remote [email protected] sender  (fromMe 0)
20445: 2019-03-27 17:30:12,752 INFO  backend: conv_write_im()
20445: 2019-03-27 17:30:12,752 ERROR backend: GLib g_string_free: assertion 'string != NULL' failed
20445: 2019-03-27 17:30:12,752 INFO  backend: Received message body='Scan this QR code within 20 seconds to log in.' xhtml='' name='[email protected]'

and still no qr shown.

getting these messages in client as follows :
image

@evgenyh
Copy link
Author

evgenyh commented Mar 27, 2019

just to ensure , that this is not due to some client side limitations of displaying messages, below is a dump of incoming traffic :

<message from="login\[email protected]/bot" type="chat" to="***masked***@im.domain">
<body>Scan this QR code within 20 seconds to log in.</body>
</message>

<r xmlns="urn:xmpp:sm:3"/>

<message from="login\[email protected]/bot" type="chat" to="***masked***@im.domain">
<body>Scan this QR code within 20 seconds to log in.</body>
</message>

<r xmlns="urn:xmpp:sm:3"/>

<a xmlns="urn:xmpp:sm:3" h="135"/>

<a xmlns="urn:xmpp:sm:3" h="75"/>

<message from="login\[email protected]/bot" type="chat" to="***masked***@im.domain">
<body>Scan this QR code within 20 seconds to log in.</body>
</message>

<r xmlns="urn:xmpp:sm:3"/>

<message from="whatsapp.im.domain" type="chat" to="***masked***@im.domain">
<body>error during login: qr code scan timed out
</body>
<spectrumerror xmlns="http://spectrum.im/error" error="0">CONNECTION_ERROR_NETWORK_ERROR</spectrumerror>
</message>

<presence from="whatsapp.im.domain" type="unavailable" to="***masked***@im.domain"/>

thanks

@EionRobb
Copy link

spectrum2 has.... issues with inline images.
Try adding the PURPLE_MESSAGE_IMAGE flag (might be plural). You'll also need to set up the setting for hosting images on a web server. See the spectrum2 docs for more details

@evgenyh
Copy link
Author

evgenyh commented Mar 27, 2019

tried.PURPLE_MESSAGE_IMAGES . no change
the suspected error in log is

28126: 2019-03-27 19:41:53,753 INFO  backend: conv_write_im()
28126: 2019-03-27 19:41:53,753 ERROR backend: GLib g_string_free: assertion 'string != NULL' failed

but this is more related to spectrum2 I assume.

@hoehermann
Copy link
Owner

@EionRobb Is there a different, more spectrum2-compatible way of handling images in libpurple? I used the first example I came across.

@evgenyh For a really dirty "solution", you can replace the body of the anonymous goroutine at purplegwa.go, line 297 with something like

err := qrcode.WriteFile(<-qr, qrcode.Medium, 256, "/tmp/whatsappqrcode.png")

. Instead of forwarding to the client, the server will store the image containing the QR code on its local filesystem. Assuming you have access and can open the image quickly enough, you should be able to login. I probably do not need to point out that this will lead to confusion if used with multiple connections at the same time.

@evgenyh
Copy link
Author

evgenyh commented Mar 27, 2019

@hoehermann thanks for reply, I'll try that. At least for confirming if it working.
And btw, libpurple-hangouts have similar functionality of inline images and afaik, it works with spectrum.
pls see this discussion spectrum2 closed issue

https://bitbucket.org/EionRobb/purple-hangouts/src/5e769791d282a6e5ae4d94dc66a1ff9d6904ec9c/hangouts_events.c?at=default&fileviewer=file-view-default#hangouts_events.c-531

@EionRobb
Copy link

@hoehermann the "most compatible" way is to use the libpurple request api. This has been used by other prpls for showing captcha images and getting the user to fill in the letters or whatever. Oh, maybe the notify api would be better since there's no human input required. Unfortunately, the way spectrum2 has been written, it has protocol-specific code to handle each of these request/notify api calls

Using the inline image system with the http image server, spectrum will save the qrcode to disk for its web server to provide, which is similar as what you're suggesting. Unfortunately again, getting the web server to work is finnicky, and I've only heard of one person who got it working.

@hoehermann
Copy link
Owner

Thank you both for your input. As far as I understood, the alternatives offer some, but no vast improvement over the current implementation. Consequently, I leave this as enhancement for later / maybe.

@hoehermann hoehermann changed the title error during login: qr code scan timed out, but no qr code shown Improve compatibility with spectrum2 Mar 27, 2019
@hoehermann hoehermann added the enhancement New feature or request label Mar 27, 2019
@evgenyh
Copy link
Author

evgenyh commented Mar 27, 2019

err := qrcode.WriteFile(<-qr, qrcode.Medium, 256, "/tmp/whatsappqrcode.png")

this works. a bit unusable though

@hoehermann
Copy link
Owner

a bit unusable though

I did not expect it to be any better.

I do not use spectrum2, so… Pull requests are welcome. ;)

@evgenyh
Copy link
Author

evgenyh commented Mar 27, 2019

golang is not my area of expertise, but will try to do my best :)

@hoehermann
Copy link
Owner

hoehermann commented Mar 27, 2019

I never worked with go before, either. Takes a bit to get used to, but it seems solid.

This particular problem is probably tackled in the C part, though. It is just a hunch. The QR code is displayed with the same technique as a normal image message. Whatever solution is found – it should pave the road for both use-cases.

@rogora
Copy link

rogora commented Apr 29, 2019

I've been testing this, and image inlining works well for me, once the "http image server" is set up correctly. Modifying libgowhatsapp.c:135 as suggested, I can see the QR code in my chat (tested with gajim), and complete the login successfully.

The real problem that needs a fix is another one though. Apparently, for every image message received, both Spectrum 2 and this plugin try to free the memory containing image data, and this results in a crash of the Spectrum 2 component, and a loss of the whatsapp web session as a consequence.
I patched the Spectrum 2 libpurple backend to avoid freeing such memory when the protocol is prpl-hehoe-gowhatsapp, but I'm not sure this is the ideal thing to do.

Who should be responsible for freeing the memory containing the image data?

@EionRobb
Copy link

From https://developer.pidgin.im/doxygen/2.7.11/html/imgstore_8h.html#6e992b86c90965143d380c9454132749

data | Pointer to the image data, which the imgstore will take ownership of and free as appropriate. If you want a copy of the data, make it before calling this function.

@hoehermann
Copy link
Owner

My bad. Thanks for reporting @rogora and thank you for your help Eion.

@XP-Fan
Copy link

XP-Fan commented Jul 1, 2019

Hey, did anyone get this running with spectrum2 now and if so can he advice a friend of mine how to do it quickly? Actually I'm blind, so I can not really use the original whatsApp in an productive manner. However, since before 2 weeks I was using whapp-irc, which is now broken and I can not reach the maintainer. Thus, now, I'm pretty much fucked and desperately seeking a solution. A friend of mine is operating an XMPP-server, also for my domain, and he also has spectrum so if he gets adviced, he could implement this for me. Hoehermann do you have still interest in completing this? Actually I would at least also need the possibility to receive voice messages as audiofiles. I don't care whether as link or as XMPP Filetransfer. Even without that it would be a big help for the short run, and on the long run I could also pull out my paypal if everything finally works out.

@hoehermann
Copy link
Owner

hoehermann commented Jul 2, 2019

Hi @XP-Fan. I wanted to add support for media messages anyway. Due to your request, I figured I could do so today. Hand-tailored for you, there now is a new branch. I also uploaded a binary for your convenience. Files are downloaded into the "purple home directory" – whatever that means for spectrum2. It works for me in Pidgin. The downloaded files are displayed as local file links. Some kind of translation probably needs to be done for use with spectrum2. Report back in case you need adjustments. Please note that this version was quickly thrown together and not well tested.

@XP-Fan
Copy link

XP-Fan commented Jul 3, 2019 via email

@hoehermann
Copy link
Owner

Please note that I have no experience with spectrum2 whatsoever. I do not know if the path you are currently trying is the easiest – it sure sounds complicated to me. I do not know how your blindness affects your ability to use a computer, but you might want to check out Finch. It can be controlled by using only the keyboard, it natively supports purple-gowhatsapp and there even is a text-to-speech plug-in. Apart from that, I am not up for administering other people's systems. I am sorry.

@XP-Fan
Copy link

XP-Fan commented Jul 6, 2019 via email

@hoehermann
Copy link
Owner

I do not like the prospect of publishing this plug-in in that manner, but I'll put up with that, I guess. Who did you speak to? In case of a co-operation, I'd rather not play Chinese Whispers.

Indeed, Finch is only available for Linux-like systems.

@thundergreen
Copy link

126: 2019-07-16 20:56:12,817 INFO  libpurple: account:Destroying account 0x55ab69c2c6b0
126: 2019-07-16 20:56:12,858 INFO  backend: Creating account with name '+33781852856' and protocol 'prpl-hehoe-gowhatsapp'
126: 2019-07-16 20:56:12,858 INFO  libpurple: account:Connecting to account +33781852856.
126: 2019-07-16 20:56:12,858 INFO  libpurple: connection:Connecting. gc = 0x55ab69c1a900
126: 2019-07-16 20:56:13,816 INFO  libpurple: gowhatsapp:Recieved: at 0 id  remote [email protected] sender  (fromMe 0)
126: 2019-07-16 20:56:13,816 INFO  backend: conv_write_im()
126: 2019-07-16 20:56:13,816 INFO  backend: conv_write_im(): ignoring a system message
126: 2019-07-16 20:56:13,817 INFO  libpurple: gowhatsapp:Recieved: at 0 id  remote [email protected] sender  (fromMe 0)
126: 2019-07-16 20:56:13,817 INFO  backend: conv_write_im()
126: 2019-07-16 20:56:13,817 INFO  backend: conv_write_im(): ignoring a system message
126: 2019-07-16 20:56:17,815 INFO  libpurple: util:Writing file accounts.xml to directory /var/lib/spectrum2/whatsapp.emevth.no-ip.biz
126: 2019-07-16 20:56:17,816 INFO  libpurple: util:Writing file /var/lib/spectrum2/whatsapp.emevth.no-ip.biz/accounts.xml
126: 2019-07-16 20:56:33,816 INFO  libpurple: gowhatsapp:Recieved: at 0 id (null) remote (null) sender (null) (fromMe 0)
126: 2019-07-16 20:56:33,816 INFO  libpurple: connection:Connection error on 0x55ab69c1a900 (reason: 0 description: error during login: qr code scan timed out
)
126: 2019-07-16 20:56:33,816 INFO  libpurple: account:Disconnecting account +33xxxxxxxxx (0x55ab69c1ab30)
126: 2019-07-16 20:56:33,816 INFO  libpurple: connection:Disconnecting connection 0x55ab69c1a900
126: 2019-07-16 20:56:33,816 INFO  libpurple: connection:Destroying connection 0x55ab69c1a900
126: 2019-07-16 20:56:33,835 ERROR backend: g_log purple_account_disconnect: assertion '!purple_account_is_disconnected(account)' failed
126: 2019-07-16 20:56:33,835 INFO  libpurple: account:Destroying account 0x55ab69c1ab30
126: 2019-07-16 20:56:37,624 INFO  backend: Exiting.

@hoehermann
Copy link
Owner

hoehermann commented Jul 16, 2019

@thundergreen There is an option for spectrum compatibility. Please set "system-messages-are-ordinary-messages" to true. I want to add that to the readme.

The plug-in will then generate an image containing the QR for log-in and saves it into a file. With spectrum, the file location is /var/lib/spectrum2/whatsapp.emevth.no-ip.biz/whatsapp/login, I guess. In the front-end, a link is displayed. Right now, it is a local file link file:///var/lib/spectrum2/whatsapp.emevth.no-ip.biz/whatsapp/login. As far as I understand, spectrum comes with a HTTP server for exactly that scenario. I have no idea how to adjust the URL, though. It could be as easy as http://whatsapp.emevth.no-ip.biz/whatsapp/login, but I am totally guessing right now. I would gladly take your advice.

@thundergreen
Copy link

@hoehermann sorry for dumb question but where ? in the whatsapp.cfg?

@yourealwaysbe
Copy link

Aha, could be it. In the previous version the room list would be populated when the contact list was refreshed and/or when messages are received.

During list refresh, it would check if the contact was a group chat JID and add it if needed. Code here. If whatsmeow doesn't deliver group chats as part of the main contact list, this could be a reason they're not showing up.

I checked again. The group chat that is showing for me is the one i'm using with myself to test. I guess it gets added when the messages come through. Code here (the gowhatsapp_find_group_chat function ultimately adds the group chat if it's not there already). Still, the topic doesn't seem to be set right.

@thundergreen
Copy link

Hello I'm following this discussion a bit and was wondering how to set it up on spectrum2 but docker .. I've the feeling the docker image has not the right branch / repo? @vitalyster are you sure U added the right repo/branch/ commit to the docker file? And would you or someone mind sharing the config for that? My spectrum2 won't start the transport somehow. I've also Facebook configured and it shows up in gajim but for WhatsApp transport it shows NO underneath. I'm running prosody nightly builds (without docker) and use standard port for components .is there something I have to take care of in addition? Like discovery or something?

Thanks for your help

@vitalyster
Copy link
Contributor

@thundergreen please don't discuss unrelated issues there :) Use chatroom or create a new discussion on spectrum repo - https://github.com/SpectrumIM/spectrum2/discussions

@yourealwaysbe
Copy link

On BitlBee, my feeling on group chats is that it's basically fine except that the whatsmeow version isn't getting an initial contact list for some reason (even with fetch-contacts set to true). None of my personal contacts or group chats are pre-populated. The group chat name used to come from this list.

@hoehermann
Copy link
Owner

@vitalyster I have been working on the group chats / room list features. Since many compatibility options are the same for spectrum and bitlbee, I renamed the setting name "spectrum-compatibility" to "bridge-compatibility".

@hoehermann
Copy link
Owner

In the past two weeks, I have not received any reports about severe defects. Is there any issue I forgot about? Especially in regard to spectrum? The section about known issues lists the issues I know of but do not want to tackle right now.

If there are no critical show-stoppers, I want to make the whatsmeow branch the main branch and officially deprecate the old gowhatsapp branch.

@vitalyster
Copy link
Contributor

There are a lot of questionable decisions under "bridge-compatibility" and other options, I'm pretty sure options are not needed at all, but it can be discussed later, right now there is no reason to keep old version and need to move forward

@thundergreen
Copy link

@vitalyster can you please pm me to troubleshoot my issue getting started with spectrum2? Also via xmpp if you want ;) I'm really interested to use and test

@vitalyster
Copy link
Contributor

@hoehermann
Copy link
Owner

hoehermann commented Feb 18, 2022

Thank you for the feedback, it is very constructive. :)

There are a lot of questionable decisions under "bridge-compatibility" and other options

Please elaborate which decisions are sub-optimal in the spectrum context. Would more finely grained options be better?

@petermolnar
Copy link

Sorry for the necromancy but those looking for a message transport / bridge that seems to be working with whatsapp to some extend: https://sr.ht/~nicoco/slidge/

@hoehermann
Copy link
Owner

hoehermann commented Feb 8, 2023

@petermolnar First of all, I do not consider this necromancy since the issue is still open. Some work needs to be done, but most features including group chats and file transfer are good to go (most of the time). ;)

Thank you for the suggestion. I noticed slidge and its WhatsApp support. In 2023, it did not support group chats. A feature crucial to many users. But it has matured very well over the past months.

For the record, there is also https://maunium.net/go/mautrix-whatsapp/ with mautrix offering feature-complete bridges to many other protocols, too.

@hoehermann
Copy link
Owner

hoehermann commented Feb 11, 2023

User reports indicate that Spectrum currently does not properly forward the message containing the QR-code. This is a show-stopper, but I am booked. I hope I can look into this in March.

Update: This turned out to be a usage issue. The user had blocked unsolicited messages – including Spectrum's "Logon QR Code" user.

@heeplr
Copy link

heeplr commented Apr 15, 2023

I just setup gowhatsapp successfully. I had the webserver for images set up, so receiving images via other protocols works already.

I'm sharing what I did in case others are stuck (maybe add a spectrum2 section to the README?). Replace "yourdomain.com" with your XMPP server's domain:

  1. Setup Spectrum + http webserver
  2. Compile & install purple-gowhatsapp like in the README
  3. add transport to your XMPP server (in my case /etc/prosody/prosody.cfg.lua):
[...]

VirtualHost "yourdomain.com"

    Component "whatsapp.yourdomain.com"
        component_secret = "choose-a-secure-password-here"

    Component "upload.yourdomain.com" "http_upload"
        modules_enabled = {
                  "http_upload";
                  "http_files";
        }
        http_host = "upload.yourdomain.com"
        http_external_url = "https://upload.yourdomain.com:443/"
        http_upload_path = "/var/www/hosts/upload.yourdomain.com/htdocs"
        http_files_dir = "/var/www/hosts/upload.yourdomain.com/htdocs"
    
  1. Create a spectrum transport config /etc/spectrum2/transports/purple-gowhatsapp.cfg
[service]
user=spectrum
jid = whatsapp.yourdomain.com
password = choose-a-secure-password-here
port = 5347
host = 127.0.0.1
users_per_backend = 10
backend = /usr/bin/spectrum2_libpurple_backend
protocol = prpl-hehoe-whatsmeow
mark_seen_on_delivery = true
admin_jid = [email protected]
web_directory = /var/www/hosts/upload.yourdomain.com/htdocs
web_url = https://upload.yourdomain.com/upload
enable_remove_buddy=true

[identity]
name = WhatsApp IM Transport
type = whatsmeow

[logging]
config = /etc/spectrum2/logging.cfg
backend_config = /etc/spectrum2/backend-logging.cfg

[database]
type = sqlite3

[registration]
auto_register=0
enable_public_registration=1
username_label=Phone number:
instructions=Register to whatsapp transport (e.g. [email protected])

[purple]
send-receipt=on-answer
bridge-compatibility=true
autojoin-chats=true
embed-max-file-size=100
group-is-file-origin=false
get-icons=true
  1. restart your XMPP server and spectrum, check logs for errors, check if the new whatsapp.yourdomain.com shows up in service discovery.
  2. Launch official whatsapp client, go to Settings, click on the QR-Code icon on the top right next to your username
  3. Change to tab "Scan code"
  4. Register to transport using your XMPP client
  1. You will receive a QR code from "logon\20qr\[email protected]" as image and as ASCII-Art. (The ASCII/unicode version seems to be missing newlines but the image works)
  2. Use the official whatsapp client to scan the received QR Code and follow instructions
  3. Now you can add new contacts in your XMPP client: [email protected]
  4. Done

@theassemblerguy
Copy link

theassemblerguy commented Apr 15, 2023 via email

@heeplr
Copy link

heeplr commented Apr 15, 2023

@theassemblerguy

I'd recommend you keep the read receipts set to"on-answer", otherwise it will render the WhatsApp client on your phone useless

In my case that's intentional. I use a XMMP client on my phone to aggregate all messaging apps.

Also you might want to set "group-is-file-origin" to false or else voice messages you receive in groups will end up showing as local paths whose you cannot open if your XMPP client isn't on the same computer where you run the rest.

I edited both changes in my original comment. Thanks for mentioning it.

@msebald
Copy link

msebald commented Apr 15, 2023

We run the transport on the latest Spectrum docker image on our server (jabber.hot-chilli.net) with the following purple options:

[purple]
qrcode-size=256
plain-text-login=0
bridge-compatibility=1
send-receipt=on-answer
embed-max-file-size=16
autojoin-chats=1
group-is-file-origin=0
echo-sent-messages=internal

My guess is that some of these options are default now. We (including @hoehermann and @theassemblerguy) are doctoring on the service for quite a while now. :-)

@vitalyster
Copy link
Contributor

vitalyster commented Apr 15, 2023

@hoehermann

send-receipt=on-answer

I think this option (now default?) should also include "on-interact" behavior. Some XMPP clients are able to send "interaction" events (which is mapped to "conversation-updated" signal on libpurple side). So - when we receive "conversation-updated" event we mark as read and also mark as read on answer, that should make happy both great and non-great XMPP clients. Does it work?

@hoehermann
Copy link
Owner

@heeplr Thank you for posting the instructions and sharing your configuration. This makes me more open to setting up Spectrum for testing purposes. Up to now, I failed to build the dependencies since I never worked with scons. vitalyster kindly has prepared a build for us. I want to check it out next.

@msebald It is good having you on board.

@hoehermann
Copy link
Owner

"interaction" events

That is a very nice feature. Thank you for pointing that out. Unfortunately, the "conversation-updated" is a bit weird on Pidgin: It is also fired upon arrival of new messages. I guess this is due to "appending a new message" means the "conversation has been updated". A reasonable interpretation, but also ambiguous. And – for our goals – detrimental. Currently, I check Pidgin-specific values in particular: https://github.com/hoehermann/purple-gowhatsapp/blob/60b7398/src/c/receipt.c#L16 Once I managed to set-up a local Spectrum instance for testing purposes, I want to investigate possibilities to make this work. @vitalyster Which XMPP client does sent "interaction" events? That would be useful for debugging. The Pidgin code does not mention "interaction" as a string.

@vitalyster
Copy link
Contributor

@hoehermann spectrum uses "unseen_count" not "unseen-count": https://github.com/SpectrumIM/spectrum2/blob/86fb98344fe6780afcbf5d4514caa6792be5c9fc/backends/libpurple/main.cpp#L710
Maybe this is the problem and we need to send "unseen-count"?

@vitalyster
Copy link
Contributor

Checked the Pidgin code and it seems the bug on our side, will fix it shortly

@heeplr
Copy link

heeplr commented Apr 18, 2023

@hoehermann

This makes me more open to setting up Spectrum for testing purposes

I really recommend using it if there is even a remote chance to have some box running 24/7 (raspberry pi or something).
Setting up prosody + spectrum2 is only a one-time hassle (and not a big one) and after that it's practically zero maintenance besides regular updates.

Having only one IM App for everything on mobile (Conversations in my case) really is a breeze.

@hoehermann
Copy link
Owner

hoehermann commented May 28, 2023

I hope you folks do not mind me turning this into a "help hoehermann to get spectrum2 running" discussion. @heeplr I would be glad if you could help me out. It is a public holiday so I used the time to try again, but got stuck on step 5. 🙁

I set-up a clean install of Debian 12 (bookworm). I successfully (I think) set-up prosody. I had prosodyctl cert generate <hostname> create a self-signed certificate for each hostname /var/log/prosody/prosody.log complained about. I created an account via prosodyctl adduser hermann@localhost. I can connect to the prosody instance via swift.

I tried following the instructions, but allegedly using apt-key this way is deprecated. I downloaded the public key and put it in a key-ring like this:

wget https://packages.spectrum.im/packages.key -O /tmp/spectrum-im.key
gpg --no-default-keyring --keyring /etc/apt/keyrings/spectrum-im.gpg --import /tmp/spectrum-im.key

And I adjusted /etc/apt/sources.list.d/spectrum.list:

deb [signed-by=/etc/apt/keyrings/spectrum-im.gpg] https://packages.spectrum.im/spectrum2/ bullseye main

I created a user manually:

addgroup --gid 900 spectrum
adduser --uid 900 --gid 900 spectrum

I tried to install spectrum2:

apt-get install spectrum2 spectrum2-backend-libpurple

In 2023, that failed in the configuration step because spectrum_manager was missing configuration files. I found it quite odd I need to prepare the configuration before even installing the software. From the documentation I could infer I need a file at /etc/spectrum2/spectrum_manager.cfg. I manually created the directory /etc/spectrum2/. I found a sample here. Now apt-get succeeded. Update: This is fixed in 2024.

Spectrum2 still would not start because there seemed some disagreement on which user should be used. The documentation said "spectrum", however the systemd unit installed at /usr/lib/systemd/system/spectrum2.service is starting spectrum2 as root. I adjusted the systemd unit and also ran chown -R spectrum:spectrum /var/{lib,run,log}/spectrum2/ so spectrum could write to its directories.

I then proceeded and added the /etc/spectrum2/transports/purple-gowhatsapp.cfg you kindly provided. I chose to use localhost in all places. So the prosody configuration becomes Component "whatsapp.localhost" and purple-gowhatsapp.cfg reads jid = whatsapp.localhost.

Unfortunately, started with systemctl restart spectrum2.service, spectrum2_manager would only output Can't connect to database. Check the log to find out the reason. However, in /var/log/spectrum2/whatsapp.localhost/spectrum2.log there was no error message. The information Opening database /var/lib/spectrum2/whatsapp.localhost/database.sql looks fine to me. Though I think it is odd to use .sql for an sqlite3 database instead of the usual .db.

Reading through the code, I found out that this output is not acutally produced by spectrum_manager, but by spectrum. Then I noticed your /etc/spectrum2/transports/purple-gowhatsapp.cfg mentiones a database type, but lacks a "database" key. I added database=/var/lib/spectrum2/whatsapp.localhost/whatsmeow.db to the configuration. Update: ``database=none` may work, too.

Now systemctl restart spectrum2 succeeds and I have two processes running:

/usr/bin/spectrum2 -j whatsapp.localhost /etc/spectrum2/transports/purple-gowhatsapp.cfg
/usr/bin/spectrum2_libpurple_backend --host 127.0.0.1 --port 30400 --service.backend_id=1 -j whatsapp.localhost /etc/spectrum2/transports/purple-gowhatsapp.cfg

So… what do I now? How do I actually use Spectrum? What is the "service discovery"?

@heeplr
Copy link

heeplr commented May 28, 2023

I created an account via prosodyctl adduser hermann@localhost. I can connect to the prosody instance via swift.

I'm not 100% sure, but I could imagine that "localhost" could impose problems. It might work for testing but I doubt you can use prosody for real XMPP use cases without a VirtualHost with a FQDN.

However, that failed in the configuration step because spectrum_manager was missing configuration files. I find it quite odd I need to prepare the configuration before even installing the software.

That's very odd. I don't use debian so I'm not of much help here. I suggest you join [email protected] MUC to get help (and moan about the suboptimal spectrum2 docs, which I also experienced).

Spectrum2 still would not start because there seemed some disagreement on which user should be used. The documentation said "spectrum", however the systemd unit installed at nano /usr/lib/systemd/system/spectrum2.service is starting spectrum2 as root. I adjusted the systemd unit and also ran chown -R spectrum:spectrum /var/lib/spectrum2/ so spectrum could write to its directories.

Odd that it wants to run as root. But it seems you fixed it.

I then proceeded and added the /etc/spectrum2/transports/purple-gowhatsapp.cfg you kindly provided. I chose to use localhost in all places. So the prosody configuration becomes Component "whatsapp.localhost" and purple-gowhatsapp.cfg reads jid = whatsapp.localhost.

Again, not sure if this can ever work. If you own a domain, you could use a subdomain. e.g. im.example.com for prosody and whatsapp.im.example.com for your transport. They all need valid SSL certs (e.g. letsencrypt)

Unfortunately, started with systemctl restart spectrum2.service, spectrum2_manager would only output `Can't connect to database.

You could try the strace tool to find, which file it's trying to open.

Check the log to find out the reason.However, in/var/log/spectrum2/whatsapp.localhost/spectrum2.logthere was no error message. The informationOpening database /var/lib/spectrum2/whatsapp.localhost/database.sql` looks fine to me.

Yeah, that sounds like a bug. There should be log output.

Though I think it is odd to use .sql for an sqlite3 database instead of the usual .db.

Indeed, but that's your smallest problem.

Now systemctl restart spectrum2 succeeds and I have two processes running:

/usr/bin/spectrum2 -j whatsapp.localhost /etc/spectrum2/transports/purple-gowhatsapp.cfg
/usr/bin/spectrum2_libpurple_backend --host 127.0.0.1 --port 30400 --service.backend_id=1 -j whatsapp.localhost /etc/spectrum2/transports/purple-gowhatsapp.cfg

So… what do I now? How do I actually use Spectrum? What is the "service discovery"?

Sounds like you're up & running. Assuming everything works, you can now connect to your prosody server using pidgin (or any XMPP client). In pidgin you need the "XMPP Service Discovery" plugin. When you activate it, do:

  • Select from the pidgin menu "Tools -> XMPP Service Discovery -> XMPP Service Discovery".
  • In the window that opens, select the account associated with your prosody server from the dropdown on the top.
  • Press "Browse" button
  • In the "Server name request" window, enter you server address (localhost in your case) and press "Find Services"
  • Select your transport: whatsapp.localhost
  • Press "Register"
  • enter your whatsapp details: [email protected]
  • You should receive the QR code
  • Pair
  • Add new contacts like any other XMPP contact but escaping the @. E.g. 4987654321\[email protected]

Hope that helps.

@vitalyster
Copy link
Contributor

Spectrum was created few years before systemd ;) Actually the whole spectrum2_manager concept may be replaced by proper systemd configuration. Provided systemd unit is a quick and dirty solution and yes, it expects to have some configuration before installation.

  1. You should create spectrum user yourself and specify user= and group= in <transport>.cfg configuration file. Spectrum manager will start transport instances using specified user.
  2. spectrum_manager.cfg is not copied to /etc/spectrum2 - it seems to be a packaging bug, but yes it solves by copying an example configuration.
  3. Database is not required with latest spectrum version (2.2.0), and you can use database=none setting. However, it was a recent change and need to double check is configuration without database works as expected.
  4. "Service discovery" is a common XMPP term known by all XMPP users except Pidgin ones ;) You should install XMPP Service Discovery plugin and follow steps provided by @heeplr. Alternatively, you can register XMPP user via commands sent to transport JID or by using Web-interface, but Service Discovery is the most used way.

@hoehermann
Copy link
Owner

Thank you for your help. With your combined efforts, I was able to get Spectrum (with Prosody and Apache) up and running. Here are the things I learned:

Client

  • Swift: I tried this first since libswiften is used by Spectrum. I could not find a "service discovery" menu. Also, listing chat rooms does not work.
  • Gajim: This indeed cannot be used with a self-signed certificate even though it was possible in the past. @heeplr
  • Pidgin: This one works. Thank you for pointing out "service discovery" is a plug-in. @vitalyster

Spectrum

Using it for the first time, I learned much about Spectrum and how it handles MUCs in particular. I had assumed that Spectrum just forwards the JIDs and leaves "JID→friendly-name" look-up to the client. While in fact, Spectrum does some translation on the server side.

In Pidgin, the user can call roomlist_get_list for getting a list of all group chats. Chats can then be joined. After the chat has been joined, the list of participants is populated. Friendly name look-ups happen in the background as needed. The list of contacts is fetched asynchronously and persisted for the next launch.
In Spectrum, roomlist_get_list is called automatically immediately after the connection has been established. With the given configuration, every chat is joined automatically. The list of participants are populated. However, Spectrum cannot do friendly name look-ups yet, since the list of contacts has not yet been supplied by the WhatsApp servers. So you end up with chat rooms populated by phone numbers.

I now reorganized the connection procedure so the connection is only marked as "connected" after the contacts have been fetched. Group chat participant lists now seem to be populated with friendly names.

Continuing from here

I want to wait two weeks so the bitlbee users can notify me of regressions. I also want to do some tests myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Someone else is free to do this
Projects
None yet
Development

No branches or pull requests