Node
Get your api key from the dashboard and write Node.js code to make HTTP requests to the TokenChannel API.
Installation
$ npm install tokenchannel
Challenge
import Tokenchannel from 'tokenchannel'
const apiKey = 'TCk-b8FCP2nwPSrpei74rMI9WQJSAnb0fgifwJAK';
const client = new Tokenchannel(apiKey);
const channel = Channel.EMAIL; // Channel.SMS or Channel.VOICE
const identifier = 'info@tokenchannel.io'; // '+14155552671'
const options: IChallengeOptions = {
language: "en",
codeLength: 6,
charset: Charset.DEC,
maxAttempts: 3
};
try {
const {requestId} = await client.challenge(channel, identifier, options);
catch (error) {
console.log("Error: ", JSON.stringify(error));
}
Authenticate
try {
await tokenchannel.authenticate(requestId, validationCode);
console.log("Challenge succeed! ");
} catch (e) {
if (e instanceof InvalidCodeError) {
console.log("Invalid code. Try again ...");
} else if (e instanceof MaxAttemptsExceededError) {
console.log("Two many attempts. BYE!");
} else {
console.log("Error: ", JSON.stringify(error));
}
}
Retrieve validation code for a Test Challenge
const {validationCode} = await tokenchannel.getValidationCodeByTestChallengeId(requestId);
Retrieve supported countries
const countries : string[] = await tokenchannel.getSupportedCountries();
Retrieve supported languages
const languages : string[] = await tokenchannel.getSupportedLanguages();
Retrieve SMS Price List
const smsPrices : string[] = await tokenchannel.getSMSPrices();
Retrieve Voice call Price List
const smsPrices : string[] = await tokenchannel.getVoicePrices();
Retrieve Whatsapp Price List
const smsPrices : string[] = await tokenchannel.getSMSPrices();