انتقل إلى المحتوى الرئيسي

Get list of countries

To get the countries list, you can update the open event listener like so:

index.js
const ping_interval = 12000; // it's in milliseconds, which equals to 120 seconds
let interval;
// subscribe to `open` event
websocket.addEventListener('open', (event) => {
console.log('websocket connection established: ', event);
const payload = JSON.stringify({
residence_list: 1,
});
websocket.send(payload);

// to Keep the connection alive
interval = setInterval(() => {
const sendMessage = JSON.stringify({ ping: 1 });
websocket.send(sendMessage);
}, ping_interval);
});

Now update the message event listener to render the data:

index.js
// subscribe to `message` event
websocket.addEventListener('message', (event) => {
const receivedMessage = JSON.parse(event.data);
switch (receivedMessage.msg_type) {
case 'residence_list':
console.log('list of countries', receivedMessage.residence_list);
break;
case 'ping':
console.log('ping/pong response: ', receivedMessage.ping);
break;
default:
console.log('received message: ', receivedMessage);
break;
}
});

the response should be an object:

{
"echo_req": {
"req_id": 1,
"residence_list": 1
},
"msg_type": "residence_list",
"req_id": 1,
"residence_list": [
{
"identity": {
"services": {
"idv": {
"documents_supported": {},
"has_visual_sample": 0,
"is_country_supported": 0
},
"onfido": {
"documents_supported": {},
"is_country_supported": 0
}
}
},
"phone_idd": "35818",
"text": "Aland Islands",
"value": "ax"
},
{
"identity": {
"services": {
"idv": {
"documents_supported": {},
"has_visual_sample": 0,
"is_country_supported": 0
},
"onfido": {
"documents_supported": {
"driving_licence": {
"display_name": "Driving Licence"
},
"national_identity_card": {
"display_name": "National Identity Card"
},
"passport": {
"display_name": "Passport"
}
},
"is_country_supported": 1
}
}
},
"phone_idd": "355",
"text": "Albania",
"tin_format": ["^[A-Ta-t0-9]\\d{8}[A-Wa-w]$"],
"value": "al"
}
]
}

With this call, you'll get useful information for the supported countries, such as:

  • 2-letter code for each country
  • Identity service providers for each country
  • Country Tax Identifier Format (tin_format)
  • etc

This can be useful to account creation forms, in which you need to ask your users to provide validated information about their identity base, depending on their country of residence.

حذر

For address and tax ID validations, please use the provided 'tin_format' for the country.

The country of your users is important for our next steps. With it, you can determine which assets and features the client can use.

تلميح

It's better if you get the list of countries before populating your form.

خطر

We need detailed content about IDV and ONFIDO identity services, their differences and possibilities

your final code should be:

index.js
const app_id = 1089; // Replace with your app_id or leave as 1089 for testing.
const websocket = new WebSocket(`wss://ws.binaryws.com/websockets/v3?app_id=${app_id}`);
const ping_interval = 12000; // it's in milliseconds, which equals to 120 seconds
let interval;

// subscribe to `open` event
websocket.addEventListener('open', (event) => {
console.log('websocket connection established: ', event);
const payload = JSON.stringify({
residence_list: 1,
});
websocket.send(payload);

// to Keep the connection alive
interval = setInterval(() => {
const sendMessage = JSON.stringify({ ping: 1 });
websocket.send(sendMessage);
}, ping_interval);
});

// subscribe to `message` event
websocket.addEventListener('message', (event) => {
const receivedMessage = JSON.parse(event.data);
switch (receivedMessage.msg_type) {
case 'residence_list':
console.log('list of countries', receivedMessage.residence_list);
break;
case 'ping':
console.log('ping/pong response: ', receivedMessage.ping);
break;
default:
console.log('received message: ', receivedMessage);
break;
}
});

// subscribe to `close` event
websocket.addEventListener('close', (event) => {
console.log('websocket connectioned closed: ', event);
clearInterval(interval);
});

// subscribe to `error` event
websocket.addEventListener('error', (event) => {
console.log('an error happend in our websocket connection', event);
});