From 1591a886fcc8ee66f8851c4a20934cdff9708876 Mon Sep 17 00:00:00 2001 From: Antoine SEIN <142824551+asein-sinch@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:16:49 +0200 Subject: [PATCH] DEVEXP-558: Add snippets for Verification API --- .../report-flashcall-verification-by-id.js | 19 ++++++++++++++++ ...port-flashcall-verification-by-identity.js | 19 ++++++++++++++++ .../report-phonecall-verification-by-id.js | 19 ++++++++++++++++ ...port-phonecall-verification-by-identity.js | 19 ++++++++++++++++ .../report-sms-verification-by-id.js | 19 ++++++++++++++++ .../report-sms-verification-by-identity.js | 19 ++++++++++++++++ .../start-data-verification.js | 19 ++++++++++++++++ .../start-flashcall-verification.js | 19 ++++++++++++++++ .../start-phonecall-verification.js | 20 +++++++++++++++++ .../start-sms-verification.js | 22 +++++++++++++++++++ .../verification-status/verification-by-id.js | 17 ++++++++++++++ .../verification-by-identity.js | 18 +++++++++++++++ .../verification-by-reference.js | 17 ++++++++++++++ 13 files changed, 246 insertions(+) create mode 100644 snippets/verification/report-verification/report-flashcall-verification-by-id.js create mode 100644 snippets/verification/report-verification/report-flashcall-verification-by-identity.js create mode 100644 snippets/verification/report-verification/report-phonecall-verification-by-id.js create mode 100644 snippets/verification/report-verification/report-phonecall-verification-by-identity.js create mode 100644 snippets/verification/report-verification/report-sms-verification-by-id.js create mode 100644 snippets/verification/report-verification/report-sms-verification-by-identity.js create mode 100644 snippets/verification/start-verification/start-data-verification.js create mode 100644 snippets/verification/start-verification/start-flashcall-verification.js create mode 100644 snippets/verification/start-verification/start-phonecall-verification.js create mode 100644 snippets/verification/start-verification/start-sms-verification.js create mode 100644 snippets/verification/verification-status/verification-by-id.js create mode 100644 snippets/verification/verification-status/verification-by-identity.js create mode 100644 snippets/verification/verification-status/verification-by-reference.js diff --git a/snippets/verification/report-verification/report-flashcall-verification-by-id.js b/snippets/verification/report-verification/report-flashcall-verification-by-id.js new file mode 100644 index 0000000..ec96b09 --- /dev/null +++ b/snippets/verification/report-verification/report-flashcall-verification-by-id.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationID = 'the_verification_ID'; + const verificationCLI = 'the_phone_number_calling_for_verification'; + + /** @type {Verification.ReportFlashCallVerificationByIdRequestData} */ + const requestData = Verification.reportVerificationByIdHelper.buildFlashCallRequest( + verificationID, + verificationCLI, + ); + + const response = await verificationService.verifications.reportFlashCallById(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-flashcall-verification-by-identity.js b/snippets/verification/report-verification/report-flashcall-verification-by-identity.js new file mode 100644 index 0000000..f827e72 --- /dev/null +++ b/snippets/verification/report-verification/report-flashcall-verification-by-identity.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const verificationCLI = 'the_phone_number_calling_for_verification'; + + /** @type {Verification.ReportFlashCallVerificationByIdentityRequestData} */ + const requestData = Verification.reportVerificationByIdentityHelper.buildFlashCallRequest( + phoneNumber, + verificationCLI, + ); + + const response = await verificationService.verifications.reportFlashCallByIdentity(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-phonecall-verification-by-id.js b/snippets/verification/report-verification/report-phonecall-verification-by-id.js new file mode 100644 index 0000000..93425a9 --- /dev/null +++ b/snippets/verification/report-verification/report-phonecall-verification-by-id.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationID = 'the_verification_ID'; + const verificationCode = 'the_verification_code_received_by_phone_call'; + + /** @type {Verification.ReportCalloutVerificationByIdRequestData} */ + const requestData = Verification.reportVerificationByIdHelper.buildCalloutRequest( + verificationID, + verificationCode, + ); + + const response = await verificationService.verifications.reportCalloutById(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-phonecall-verification-by-identity.js b/snippets/verification/report-verification/report-phonecall-verification-by-identity.js new file mode 100644 index 0000000..aa79d10 --- /dev/null +++ b/snippets/verification/report-verification/report-phonecall-verification-by-identity.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const verificationCode = 'the_verification_code_received_by_phone_call'; + + /** @type {Verification.ReportCalloutVerificationByIdentityRequestData} */ + const requestData = Verification.reportVerificationByIdentityHelper.buildCalloutRequest( + phoneNumber, + verificationCode, + ); + + const response = await verificationService.verifications.reportCalloutByIdentity(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-sms-verification-by-id.js b/snippets/verification/report-verification/report-sms-verification-by-id.js new file mode 100644 index 0000000..729b20b --- /dev/null +++ b/snippets/verification/report-verification/report-sms-verification-by-id.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationID = 'the_verification_ID'; + const verificationCode = 'the_verification_code_received_by_SMS'; + + /** @type {Verification.ReportSmsVerificationByIdRequestData} */ + const requestData = Verification.reportVerificationByIdHelper.buildSmsRequest( + verificationID, + verificationCode, + ); + + const response = await verificationService.verifications.reportSmsById(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-sms-verification-by-identity.js b/snippets/verification/report-verification/report-sms-verification-by-identity.js new file mode 100644 index 0000000..9da1b56 --- /dev/null +++ b/snippets/verification/report-verification/report-sms-verification-by-identity.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const verificationCode = 'the_verification_code_received_by_SMS'; + + /** @type {Verification.ReportSmsVerificationByIdentityRequestData} */ + const requestData = Verification.reportVerificationByIdentityHelper.buildSmsRequest( + phoneNumber, + verificationCode, + ); + + const response = await verificationService.verifications.reportSmsByIdentity(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/start-verification/start-data-verification.js b/snippets/verification/start-verification/start-data-verification.js new file mode 100644 index 0000000..c3863d7 --- /dev/null +++ b/snippets/verification/start-verification/start-data-verification.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const reference = 'the_verification_reference'; + + /** @type {Verification.StartSeamlessVerificationRequestData} */ + const requestData = Verification.startVerificationHelper.buildSeamlessRequest( + phoneNumber, + reference, + ); + + const response = await verificationService.verifications.startSeamless(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/start-verification/start-flashcall-verification.js b/snippets/verification/start-verification/start-flashcall-verification.js new file mode 100644 index 0000000..e927126 --- /dev/null +++ b/snippets/verification/start-verification/start-flashcall-verification.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const reference = 'the_verification_reference'; + + /** @type {Verification.StartFlashCallVerificationRequestData} */ + const requestData = Verification.startVerificationHelper.buildFlashCallRequest( + phoneNumber, + reference, + ); + + const response = await verificationService.verifications.startFlashCall(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/start-verification/start-phonecall-verification.js b/snippets/verification/start-verification/start-phonecall-verification.js new file mode 100644 index 0000000..2dd9637 --- /dev/null +++ b/snippets/verification/start-verification/start-phonecall-verification.js @@ -0,0 +1,20 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const reference = 'the_verification_reference'; + + /** @type {Verification.StartCalloutVerificationRequestData} */ + const requestData = Verification.startVerificationHelper.buildCalloutRequest( + phoneNumber, + reference, + 'fr-FR', + ); + + const response = await verificationService.verifications.startCallout(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/start-verification/start-sms-verification.js b/snippets/verification/start-verification/start-sms-verification.js new file mode 100644 index 0000000..f71b554 --- /dev/null +++ b/snippets/verification/start-verification/start-sms-verification.js @@ -0,0 +1,22 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const reference = 'the_verification_reference'; + + /** @type {Verification.StartSmsVerificationRequestData} */ + const requestData = Verification.startVerificationHelper.buildSmsRequest( + phoneNumber, + reference, + { + codeType: 'Alphanumeric', + }, + ); + + const response = await verificationService.verifications.startSms(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/verification-status/verification-by-id.js b/snippets/verification/verification-status/verification-by-id.js new file mode 100644 index 0000000..b30c214 --- /dev/null +++ b/snippets/verification/verification-status/verification-by-id.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationID = 'the_verification_ID'; + + /** @type {Verification.VerificationStatusByIdRequestData} */ + const requestData = { + id: verificationID, + }; + + const response = await verificationService.verificationStatus.getById(requestData); + + console.log(`Verification status:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/verification-status/verification-by-identity.js b/snippets/verification/verification-status/verification-by-identity.js new file mode 100644 index 0000000..75f0cf8 --- /dev/null +++ b/snippets/verification/verification-status/verification-by-identity.js @@ -0,0 +1,18 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + + /** @type {Verification.VerificationStatusByIdentityRequestData} */ + const requestData = { + method: 'sms', + endpoint: phoneNumber, + }; + + const response = await verificationService.verificationStatus.getByIdentity(requestData); + + console.log(`Verification status:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/verification-status/verification-by-reference.js b/snippets/verification/verification-status/verification-by-reference.js new file mode 100644 index 0000000..ebb30e5 --- /dev/null +++ b/snippets/verification/verification-status/verification-by-reference.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationReference = 'the_verification_reference'; + + /** @type {Verification.VerificationStatusByReferenceRequestData} */ + const requestData = { + reference: verificationReference, + }; + + const response = await verificationService.verificationStatus.getByReference(requestData); + + console.log(`Verification status:\n${JSON.stringify(response, null, 2)}`); +};