Truecaller
2.8.0
Search
⌃K

Invoking verification

Once you have set the deep link parameters, you are ready to invoke the Truecaller verification on your mobile web page. You need to invoke the deep link using Javascript on your webpage. This will show the Truecaller verification dialog to the user if the Truecaller app is present on the user's mobile device. Please note that in case Truecaller app is not present on the user's device, the deep link won't trigger anything. To effectively handle this case, you should use the deep as suggested in the example below :
window.location = "truecallersdk://truesdk/web_verify?
requestNonce=UNIQUE_REQUEST_ID
&partnerKey=YOUR_PARTNER_KEY
&partnerName=YOUR_APP_NAME
&lang=LANGUAGE_LOCALE
&title=TITLE_STRING_OPTION";
setTimeout(function() {
if( document.hasFocus() ){
// Truecaller app not present on the device and you redirect the user
// to your alternate verification page
}else{
// Truecaller app present on the device and the profile overlay opens
// The user clicks on verify & you'll receive the user's access token to fetch the profile on your
// callback URL - post which, you can refresh the session at your frontend and complete the user verification
}
}, 600);
This would trigger the deep link, and open the user's Truecaller profile dialog if the app is present on the device. And in case the app is not present, nothing opens. So now, using javascript, you can check for the document focus: a. If the truecaller dialog opened, the document would have lost focus and you'll be taken to the else condition in the above check. b. While in case the Truecaller app is not present on the device, the focus would always remain with the document and hence, you'll have the control in the 'if' condition. Accordingly, you can map the next action on your page based on the two conditions.
Please note that the Truecaller verification flow for mobile websites is currently supported for browsers on Android OS only. You can gracefully handle invoking Truecaller SDK only on Android and not iOS, by using either of the below to detect the iOS platform:
1) Looking for User Agent
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
2) Another way is relying on navigator.platform:
var iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
iOS will be either true or false