dequis / purple-facebook

Facebook protocol plugin for libpurple (moved from jgeboski/purple-facebook)
GNU General Public License v2.0
955 stars 87 forks source link

Will be the plugin able to handle workplace chat ? #371

Open cicciofuser opened 6 years ago

cicciofuser commented 6 years ago

Hi, I'm using this plugin and I would like to know if handling the workplace chat is into the roadmap ?

Thanks a lot

marsjaninzmarsa commented 6 years ago

How such chats are handled by Facebook Messenger for Android?

jaymzh commented 6 years ago

There's a separate app. It logs in through .facebook.com. I believe bitlbee just got support for it, so hopefully it can make its way here in short order.

jaymzh commented 6 years ago

https://github.com/bitlbee/bitlbee-facebook/commit/24db488909604dd389b584c1f1ce43c549648dbe adds support.

@dequis - any chance of getting this pulled in ? In the meantime, would that patch apply to purple-facebook's codebase?

jaymzh commented 6 years ago

I'm happy to donate moneys for this, btw

jaymzh commented 6 years ago

Happy New Year @dequis !

Just wanted to loop back around to this... any thoughts?

dequis commented 6 years ago

Hm. Poke me in two weeks.

jaymzh commented 6 years ago

Will do. Thanks!

jaymzh commented 6 years ago

Roughly two-week ping, as requested. :)

jaymzh commented 6 years ago

Any guesses here on ETA?

dequis commented 6 years ago

This weekend, hopefully!

dequis commented 6 years ago

So, since this issue exists due to the divergence between both projects and the hassle that is updating stuff in this one, I'm going to try to do this The Right Way™ for once.

And this is going to take some yak shaving:

  1. Split the actual code of this plugin from the pidgin hg repo to a standalone git repo
  2. Change the build system of this thing to use a git submodule
  3. Pick one indentation style, either the one in this plugin or the one in the other plugin.
  4. Diff stuff and unify changes
  5. Get bitlbee-facebook to use that submodule too. This means adapting the http code
  6. Do something about the fact that there's a second build of purple-facebook to fix hangs after login because fixing someone's hang after login broke it for other random set of people (issue 366)
  7. Make releases for both plugins, probably naming them 2.0 to sync version numbers.

I'll probably have a branch up with this feature by step 4.

Right now I'm at the first step - git subtree is nice and easier to use than i expected, but uhm, at some point in the last year my pidgin hggit repo suffered from some data corruption in a packfile which results in i/o errors and crashing git. I'll have to report that to git at some point. At least now i'm fairly sure that the corruption isn't a big deal, and made backups.

jaymzh commented 6 years ago

Oh that would be awesome @dequis - you not having to do back/forward ports all the time would just generally make everyone happier I think. :) Thanks! Happy to help with testing things along the way.

jaymzh commented 6 years ago

Hey @dequis - I figured I'd check in on how it's going. Also if you want any help with the git stuff, it's been a while but I've had to jam git subtree, and hggit together before, so if you run into weird things I can probably help.

jaymzh commented 6 years ago

2 week check-in - how's this going?

dequis commented 6 years ago

Hi! Couldn't allocate much time to this lately, but it's definitely in my mind.

dequis commented 6 years ago

Here's a thing! https://github.com/dequis/purple-facebook/tree/wip-work-chat

Didn't test much and the sso auth looks very ugly (you don't need that part anyway)

This sort-of covers up to step 4 of the plan above. There's more to unify but... some other day.

At least now I have two trees with equivalent indentation style and as a side effect of this i managed to spot what went wrong with the "hang after login" bug, so, yay.

jaymzh commented 6 years ago

yay!!

OK so I checked out that branch, ran ./autogen.sh;./configure;make;sudo make install and restarted pidgin, but I don't see how to sign into a workplace account. I don't have a new type of account, or any options under the Facebook type. Did I miss something?

dequis commented 6 years ago

Modify account -> advanced tab -> login as a workplace account

jaymzh commented 6 years ago

Ah, I see that. But I can't add another account with the same username... does that mean I can't login to both my personal and work account at the same time? Or does that checkbox log into both?

jaymzh commented 6 years ago

OK so I took my current account and checked the box and signed out/in - but I'm still connected to my personal account... I can message people on my personal account, but not my work account and work messages don't show up on it.

dequis commented 6 years ago

Oh. That's awkward. Maybe I'll do another account type then.

Changing that checkbox in your personal account won't do anything because it's logging in with the cached access token of the personal account.

You could take advantage of that to change the username of your personal account to something else, which will be ignored until the next actual login. Or use an alternative way to represent the username, like phone number or facebook username (as in facebook.com/thisusername without the facebook.com/)

But yeah, you need to add a new account for it to try to login with this method.

jaymzh commented 6 years ago

I can do that temporarily just to test, but it'll break when that token expires, as you implied... so yeah I think we'll need a new accountype.

Also, it's worth noting you can be a member of more than one Workplace. It's not common... but you could for example be part of a non-profit and a group that both use Workplace.... I'm not sure how this effects things.

jaymzh commented 6 years ago

Oh I take that back. I can use my work email as the login.

jaymzh commented 6 years ago

IT WORKS!!!!! <3 <3 <3 <3 <3 <3 <3 <3 <3

dequis commented 6 years ago

Yay.

Also, it's worth noting you can be a member of more than one Workplace. It's not common... but you could for example be part of a non-profit and a group that both use Workplace.... I'm not sure how this effects things.

So the thing is that certain companies which were early adopters of workplace (have a guess) rely on the now-deprecated login method personal_account_password_with_work_username (this is discoverable by poking emails into prelogin)

As far as I know, this is the only method that allows having multiple work "communities" at the same time, and newly created orgs don't have that, and just use the more-common method work_account_password which is a plain work email - work password association, with different usernames for each company.

I mentioned this here https://github.com/bitlbee/bitlbee-facebook/commit/24db488909604dd389b584c1f1ce43c549648dbe

  1. Linked personal account

    This is deprecated but still needed in some companies. Looks just like password auth to users. In rare cases there may be more than one work account linked to a personal account, in which case this will only use the first one. Usually they can be de-linked by assigning a password (see the official docs)

I think it's rare enough that it's safe to wait for someone to complain, if they actually need it and de-linking doesn't work.

The commit also says

In all cases, the username is the work account email

I totally forgot about this, the whole personal account linking mess confused me. Sooo yeah, the username conflict is not that big of a deal, I guess!

jaymzh commented 6 years ago

Yup. Makes sense. This is working really well for me for the last hour or so. I'll install it on other machines tonight and let you know if I hit any problems. Let me know if there's anything else I can provide or test.

Thank you so much!

jaymzh commented 6 years ago

This morning my workplace account is disconnecting with Invalid API key (101)

dequis commented 6 years ago

Heh it's https://github.com/bitlbee/bitlbee-facebook/commit/553593d07170d6d1563d0079dbedd481dcec5b00 again. I knew I had applied some of it because it's in api.c, but I didn't notice there was another file.

Pushed fix to the same branch as 68ca266c266c87119daadfa3e0a49dacab184f91

jaymzh commented 6 years ago

Sweet, thanks!

jaymzh commented 6 years ago

So far so good... but I have found one bug. If someone sends a message that has a link it in, the message does not come through at all. This seems to be specific to the work account.

dequis commented 6 years ago

Can't reproduce, sooo, you're on your own! I'm not going to ask for debug logs for this one. Maybe try to convince the gatekeepers to have it apply to everyone first.

If you want to have a look at it yourself, a normal incoming message with a URL and no attached preview (or, in this case, explicitly removed by clicking the X in the preview before sending) looks like this:

(23:19:02) facebook: Parsing JSON: {"deltas":[{"deltaNewMessage":{"messageMetadata":{"threadK
ey":{"otherUserFbId":100015634145083},"messageId":"mid.$cAAAAACblQZRn_AboIFhysGffiVYN","offli
neThreadingId":6373350382861112845,"actorFbId":100015070322351,"timestamp":1519525142560,"sho
uldBuzzDevice":1,"tags":["source:chat:web"],"skipSnippetUpdate":0},"body":"https://www.youtub
e.com/watch?v=SBjQ9tuuTJQ","attachments":[]}}],"firstDeltaSeqId":180,"lastIssuedSeqId":180}

And one with attached preview looks like this:

(23:19:12) facebook: Parsing JSON: {"deltas":[{"deltaNewMessage":{"messageMetadata":{"threadK
ey":{"otherUserFbId":100015634145083},"messageId":"mid.$cAAAAACblQZRn_Ab3d1hysGtSjnAT","offli
neThreadingId":6373350397675728915,"actorFbId":100015070322351,"timestamp":1519525146487,"sho
uldBuzzDevice":1,"tags":["source:chat:web"],"skipSnippetUpdate":0},"body":"https://www.youtub
e.com/watch?v=SBjQ9tuuTJQ","attachments":[{"id":"338706133308395","fbid":338706133308395,"xma
GraphQL":"{\"ZXh0ZW5zaWJsZV9tZXNzYWdlX2F0dGFjaG1lbnQ6MzM4NzA2MTMzMzA4Mzk1\":{\"__type__\":{\"
name\":\"ExtensibleMessageAttachment\"},\"id\":\"ZXh0ZW5zaWJsZV9tZXNzYWdlX2F0dGFjaG1lbnQ6MzM4
NzA2MTMzMzA4Mzk1\",\"is_forwardable\":true,\"story_attachment\":{\"deduplication_key\":\"f222
7d9244cdaceefacad8d8486a7b9b\",\"description\":{\"text\":\"Foo Fighters' official music video
 for 'The Pretender'. Click to listen to Foo Fighters on Spotify: http:\\/\\/smarturl.it\\/Fo
oFSpotify?IQid=FooFTP As featured on...\"},\"media\":{\"__type__\":{\"name\":\"GenericAttachm
entMedia\"},\"image\":{\"uri\":\"https:\\/\\/external.faep4-1.fna.fbcdn.net\\/safe_image.php?
d=AQC3yyAZufZKdHyP&w=960&h=960&url=https\\u00253A\\u00252F\\u00252Fi.ytimg.com\\u00252Fvi\\u0
0252FSBjQ9tuuTJQ\\u00252Fmaxresdefault.jpg&cfs=1&_nc_hash=AQB6cihzAtJolOgq\"},\"playable_url\
":\"https:\\/\\/www.youtube.com\\/embed\\/SBjQ9tuuTJQ?autoplay=1\"},\"properties\":[{\"attach
ment_property_type\":\"double\",\"key\":\"width\",\"value\":{\"text\":\"1536\"}},{\"attachmen
t_property_type\":\"double\",\"key\":\"height\",\"value\":{\"text\":\"864\"}}],\"source\":{\"
text\":\"youtube.com\"},\"style_list\":[\"share\",\"fallback\"],\"target\":{\"__type__\":{\"n
ame\":\"ExternalUrl\"}},\"title\":\"Foo Fighters - The Pretender\",\"tracking\":\"{}\",\"url\
":\"fbrpc:\\/\\/facebook\\/nativethirdparty?app_id=87741124305&tap_behavior=app_fallback_web&
target_url=https\\u00253A\\u00252F\\u00252Fwww.youtube.com\\u00252Fwatch\\u00253Fv\\u00253DSB
jQ9tuuTJQ&extra_applink_key=al_applink_data&referer_data_key=extras&al_applink_data=\\u00257B
\\u002522target_url\\u002522\\u00253A\\u002522https\\u00253A\\u00255C\\u00252F\\u00255C\\u002
52Fwww.youtube.com\\u00255C\\u00252Fwatch\\u00253Fv\\u00253DSBjQ9tuuTJQ\\u002522\\u00252C\\u0
02522extras\\u002522\\u00253A\\u00257B\\u002522fb_app_id\\u002522\\u00253A87741124305\\u00257
D\\u00252C\\u002522referer_app_link\\u002522\\u00253A\\u00257B\\u002522url\\u002522\\u00253A\
\u002522fb-messenger\\u00253A\\u00255C\\u00252F\\u00255C\\u00252F\\u00255C\\u00252F\\u002522\
\u00252C\\u002522app_name\\u002522\\u00253A\\u002522Messenger\\u002522\\u00252C\\u002522packa
ge\\u002522\\u00253A\\u002522com.facebook.orca\\u002522\\u00257D\\u00257D&appsite_data=\\u002
57B\\u002522android\\u002522\\u00253A\\u00255B\\u00257B\\u002522is_app_link\\u002522\\u00253A
true\\u00252C\\u002522app_name\\u002522\\u00253A\\u002522YouTube\\u002522\\u00252C\\u002522ap
psite_url\\u002522\\u00253A\\u002522vnd.youtube\\u00253A\\u00255C\\u00252F\\u00255C\\u00252Fw
ww.youtube.com\\u00255C\\u00252Fwatch\\u00253Fv\\u00253DSBjQ9tuuTJQ\\u002526feature\\u00253Da
pplinks\\u002522\\u00252C\\u002522fallback_url\\u002522\\u00253A\\u002522https\\u00253A\\u002
55C\\u00252F\\u00255C\\u00252Fwww.youtube.com\\u00255C\\u00252Fwatch\\u00253Fv\\u00253DSBjQ9t
uuTJQ\\u002522\\u00252C\\u002522market_uri\\u002522\\u00253A\\u002522market\\u00253A\\u00255C
\\u00252F\\u00255C\\u00252Fdetails\\u00253Fid\\u00253Dcom.google.android.youtube\\u002526refe
rrer\\u00253Dutm_source\\u00255Cu00253Dapps.facebook.com\\u00255Cu002526utm_campaign\\u00255C
u00253Dfb4a\\u00255Cu002526utm_content\\u00255Cu00253D\\u00255Cu0025257B\\u00255Cu00252522app
\\u00255Cu00252522\\u00255Cu0025253A87741124305\\u00255Cu0025252C\\u00255Cu00252522t\\u00255C
u00252522\\u00255Cu0025253A1519525146\\u00255Cu0025257D\\u002522\\u00252C\\u002522package\\u0
02522\\u00253A\\u002522com.google.android.youtube\\u002522\\u00257D\\u00255D\\u00257D&has_app
_link=1&accessToken=https\\u00253A\\u00252F\\u00252Fwww.youtube.com\\u00252Fwatch\\u00253Fv\\
u00253DSBjQ9tuuTJQ\"}}}"}]}}],"firstDeltaSeqId":181,"lastIssuedSeqId":181}

The xmaGraphQL looks super hairy but that's mostly because it's json inside a string, and then even more serialization inside the fbrpc:// url (which i believe only happens when it knows a native app that could load it, in this case youtube)

In this case both have a "body" with text (fourth line in the paste above), that ensures there's a text representation of it.

Otherwise we have to dig into the fbrpc:// url. That can happen if you paste the url in the web client, let the preview generate, then remove the url from the body of the message. Or with some kinds of "share" features. The code that digs into that url is https://github.com/bitlbee/bitlbee-facebook/commit/3e8dd702c65c8b374e30b41f9886466325dae671 - this sounds like the weakest part of the whole thing, but I haven't seen it fail yet.

There's also code that omits showing the second url if it's the same as the one in the body, but I don't expect that will break it.

Anyway that's pretty much all I know. Open a debug window, receive a link and go nuts.

manuelnaranjo commented 6 years ago

Great work! I can connect to my workplace account with it, even behind SSO! I will try to make a build of this for Adium, any idea when this will be merged back into the main plugin?

jaymzh commented 6 years ago

@dequis - can we merge this to master? I merged the recent TLS stuff onto the wip branch, but it'd be nice to just be able to build with all the latest stuff.

jschwartzenberg commented 6 years ago

I just merged this to master (in my own fork) and did a build. I can log in without problems, but then it's not really obvious how I could start a chat with someone. Maybe some UI is still needed to search for colleagues to chat with? I guess it could be done similarly to how the SIPE plug-in does it.

jaymzh commented 5 years ago

@dequis - workplace + 2fac seems to not be working for me wiht the same flow... login -> modify acct to add 2fac code -> click save, it claims Invalid username or password again.

dequis commented 5 years ago

@jaymzh fun. Honestly the thing of using the password field for 2fa auth codes always seemed like a hack that worked magically because the server is generous. Was your auth flow work_account_password or personal_account_password_with_work_username?

dequis commented 5 years ago

Oh also a general update: been kinda neglecting this plugin for a while due to work stuff combined with burnout and all. Just returned from a three week vacation and i'm starting a new job next month, so i'll deal with whatever needs to be done in this plugin in the next couple of weeks.

jaymzh commented 5 years ago

personal_account_password_with_work_username. Our workplace doesn't have separate passwords. :/

jaymzh commented 5 years ago

Hey @dequis - any information I can provide? Logs?

jaymzh commented 5 years ago

@dequis - can/will donate money to you or your favorite charity :)

spookbench commented 5 years ago

Any news about this? Using facebook workplace through browser is making me want to shoot my head off

jaymzh commented 5 years ago

So I found a workaround:

that works for me now.

jaymzh commented 5 years ago

Hmm, I can't consistently make this work on workplace, sometimes it does, sometimes it doesn't. :/

jaymzh commented 5 years ago

@dequis - Gentle ping?

petermolnar commented 4 years ago

Bump. The wip-work-chat branch has been running smoothly for me for years. Is it possible to merge it?

Note: I compiled master yesterday to see if workplace would work out of the box, I got invalid API key error, so I guess no.