Registration Assistant Guide

Steps to integrate the registration assistant into your app

Slang’s Web registration assistant (aka SlangRegistrationAssistant) is a fully trained voice assistant specialized for Web apps to help users register on their platform using voice.

The following guide describes the steps that apps need to take in order to integrate with the assistant.

Step 1: Add the assistant to your project

Case 1: You're using node modules.

Just install slang-registration-assistant package from npm

npm install slang-registration-assistant

or if you're using yarn:

yarn add slang-registration-assistant

Then to bring slang into scope:

import SlangRegistrationAssistant from "slang-registration-assistant"

Case 2: You're using script tags

Include this in ALL the pages you want Slang Assistant to show up.

That's it.

Note: The ordering of the tags are important. Any code where you refer to SlangRegistrationAssistant should come after the assistant tag.

Step 2: Initialize slang assistant

First initialize the slang registration assistant.

SlangRegistrationAssistant.init({
    assistantID: "<assistant_id>",  // you would have gotten it from the Slang team. Required.
    apiKey: "<api_key>",    // you would have gotten it from the Slang team. Required.
    environment: "prod",    // use "stage" when in development mode. Defaults to stage if omitted.
    isSpa: true,            // this is a boolean flag to indicate whether it's a single page application or not. Multi Page applications
                            // should set this as false. Defaults to false if omitted.
});

Step 3: Start Registration

Create an object with an onResponse attribute, which is a function that will get called when slang receives a response for the current field.

Then call SlangRegistrationAssistant.setAction with that object.

SlangRegistrationAssistant.setAction(
    {
        onResponse: (currentField, value, session) => {doSomethingWith(value);}
    });

onResponse can be async, in which case either return a promise or use async/await.

Slang would consider the action to have failed and speak out the failure prompt in the following cases:

  • the handler returned the boolean false.

  • the handler threw an exception.

  • the handler returned a promise that got rejected.

In all other cases slang would consider the action to have succeeded.

NOTE: Return values will only be honoured for SPAs. For multi page applications, unsupported prompt will be spoken only in case “action handler” is not set for a certain action. In all other scenarios, the success prompt will be spoken.

Then call SlangRegistrationAssistant.readInput(registrationField)

SlangRegistrationAssistant.startRegistration(currentRegistrationField,{});

currentRegistrationField is a enum value indicating the current field whose value you are looking for.

It’s one of the following values:

  • "NAME"

  • "EMAIL"

  • "PHONE_LANDLINE"

  • "PHONE_MOBILE"

  • "GENDER"

  • "ADDRESS"

  • "PREVIOUSLY_EMPLOYED"

  • "TOTAL_WORK_EXPERIENCE"

  • "EMPLOYER"

  • "DESIGNATION"

  • "CITY"

  • "COURSE_TYPE"

  • "COURSE_YEAR"

  • "CTC"

  • "DEPARTMENT"

  • "HIGHEST_EDUCATIONAL_QUALIFICATION"

  • "INDUSTRY"

  • "INSTITUTE"

  • "JOB_START_DATE"

  • "SKILL"

  • "SPECIALIZATION"

  • "FILL_ANOTHER_EDUCATION_DETAILS"

  • "FILL_ANOTHER_WORK_EXPERIENCE"

Here’s an example

SlangRegistrationAssistant.setAction(
{
    onResponse: (currentField, value, session) => {
            setField (currentField, value);
            switch(currentField){
                case SlangRegistrationAssistant.REGISTRATION_FIELD.NAME : {
                    SlangRegistrationAssistant.readInput(
                    SlangRegistrationAssistant.REGISTRATION_FIELD.GENDER,
                    {});
                    return SlangRegistrationAssistant.STATUS.SUCCESS
                }
                case SlangRegistrationAssistant.REGISTRATION_FIELD.GENDER : {
                    SlangRegistrationAssistant.readInput(
                    SlangRegistrationAssistant.REGISTRATION_FIELD.ADDRESS,
                    {});
                    return SlangRegistrationAssistant.STATUS.SUCCESS
                }
}}});

SlangRegistrationAssistant.readInput(SlangRegistrationAssistant.REGISTRATION_FIELD.NAME,{});

"Value" types in "onResponse"

The "value" object passed to onResponse will have the following types:

  • "NAME" - string

  • "EMAIL" - string

  • "PHONE_LANDLINE" - string

  • "PHONE_MOBILE" - string

  • "GENDER" - string

  • "ADDRESS" - string

  • "PREVIOUSLY_EMPLOYED" - boolean

  • "TOTAL_WORK_EXPERIENCE" - object {years,months}

  • "EMPLOYER" - string

  • "DESIGNATION" - string

  • "CITY" - string

  • "COURSE_TYPE" - string

  • "COURSE_YEAR" - date

  • "CTC" - number

  • "DEPARTMENT" - string

  • "HIGHEST_EDUCATIONAL_QUALIFICATION" - string

  • "INDUSTRY" - string

  • "INSTITUTE" - string

  • "JOB_START_DATE" - date

  • "SKILL" - []string

  • "SPECIALIZATION" - string

  • "FILL_ANOTHER_EDUCATION_DETAILS" - boolean

  • "FILL_ANOTHER_WORK_EXPERIENCE" - boolean

"Session" in "onResponse"

The "session" object in onResponse has the following important fields:

  • isSkip - boolean, means the user wants to skip the field. (the value should be ignored here). App can return "STATUS.SUCCESS" to let Slang know that skip was successful or "STATUS.SKIP_FAILURE" to let Slang know that this field is unskippable and Slang would re-prompt for that field.

  • isFinal - boolean, this will be set true if the user is done filling this field. (IMPORTANT: this only works in case of "SKILL")

Returning from "onResponse"

From onResponse you have to return a status code to let the assistant know what is intended next.

return SlangRegistrationAssistant.STATUS.SUCCESS

SlangRegistrationAssistant.STATUS is an enum with the following values:

  • SUCCESS - app handled the user input correctly

  • FAILURE - app did not accept the user input. The assistant will retry.

  • SUCCESS_REPEAT - app handled the user input correctly and wants to give a chance to the user to input more values for the same field. (IMPORTANT: only works for "SKILL")

  • SKIP_FAILURE - the user wanted to skip this field but this field is not skippable

Speech Recognition Hints

While you start registration for any field you can provide speech recognition hints like so :

SlangRegistrationAssistant.readInput(currentRegistrationField,{
    speechRecognitionHints: {
      "en-IN": ["foo","bar"],
    }
});

This helps in improving speech recognition for that field.

Last updated