kontalk / specs

Kontalk specifications and documentation
Other
21 stars 5 forks source link

Is it possible to send in a sha1 and find out if that phone number has kontalk? #17

Closed singpolyma closed 7 years ago

daniele-athome commented 7 years ago

In theory you can (by using the same request that contact sync makes), but there is no UI for that yet. You have to add the contact with his/her real phone number to your Android contact list.

singpolyma commented 7 years ago

Yes, of course there's no UI. I don't want a UI, but an API, for integration with my service :)

daniele-athome commented 7 years ago

The roster match protocol is what is used in this case: https://github.com/kontalk/specs/blob/master/roster-match.md

...which is unfinished... ehm...

But it is very easy, you can easily infer the protocol from the source code here: https://github.com/kontalk/client-common-java/blob/master/src/main/java/org/kontalk/client/RosterMatch.java

Quickly explained, it just builds a roster block in a custom namespace with JIDs to lookup, all having the same server part (which is the server host name you're sending the request to):

<iq id='bv1bs71f' to='probe@beta.kontalk.net' type='get'>
    <query xmlns='http://kontalk.org/extensions/roster'>
      <item jid='sha1_hash@beta.kontalk.net'/>
      <item jid='another_sha1_hash@beta.kontalk.net'/>
      ...
    </query>
</iq>

The request must be sent to probe@beta.kontalk.net (it will be discoverable one day, for now it's hard-coded).

The response will contain only those JIDs found in the whole network (the server will look them up for you).

<iq id='bv1bs71f' from='probe@beta.kontalk.net' to='you@beta.kontalk.net' type='result'>
    <query xmlns='http://kontalk.org/extensions/roster'>
      <item jid='sha1_hash@beta.kontalk.net'/>
      ...
    </query>
</iq>

Please note that JIDs might be found in another server (that is, the result might contain JIDs coming from other servers): in order to match users with your original request, you'll need to match them by only using the local part - but this is fine since a given phone number can exist only once in the network.

I hope it was clear enough. If you have questions I'm here.

P.S. I'm curious, what's your service about? :-)

singpolyma commented 7 years ago

Thanks! I will try this out later.

I'm working with https://soprani.ca and we want to try alternate routes for SMS where available, so for example if one of our users messages a number with a Kontalk account, it would be nice to just route the message to Kontalk instead of over the phone network

daniele-athome commented 7 years ago

Nice! Feel free to ask anything else you may need.