TwHello - IDE and Cloud Service for Telecom - Powered by Twilio
Register for FreeLogin
FeaturesPricingDocsHelp
Introduction
Message Interfaces
Twilio Classes
Twilio.Verb Classes
Twilio.Noun Classes
Utility Classes
3rd Party Integrations

FluidSurveys Classes

These classes provide a simplified integration with FluidSurveys.com to conduct surveys via voice and messaging. FluidSurveys is online survey software made easy. Create surveys, forms & questionnaires using the web's best survey tool. More Features. Advanced Reporting. Try it free!

Requirements
You will have to create an account on FluidSurveys.com. They do have a limited free plan. You will also need to find your API User Key. That is located in the admin under User Preferences > Developer (the little hammer).

The Basics
Due to the constraints of the FluidSurveys API, features like advanced logic, piping, looping, extraction, etc. are not supported. TwHello will pull your surveys from your FluidSurveys account and iterate through each question in order. In turn, due to the constraints of voice and messaging, not all survey types are supported, like Ranking and File Upload.

For reference on the FluidSurveys API, click here.

Note: You will find a demo workflow for survey integration in your workflow list.

Example of usage:

 
// Retrieve a survey from FluidSurveys
var survey = FluidSurveys.getSurvey("API_KEY", "PASSWORD", "SURVEY_ID");
// Get the question iterator for the session.
var iterator = survey.sessionIterator();
     
// Check if there are more questions.
if( iterator.hasNext() ) {
    // Get the next question.
    var question = iterator.next();
    var progressSay = new Twilio.Verb.Say("This is question "+ (question.index+1) +" of "+ survey.getNumQuestions() +".");
    // SAY the question.
    var questionSay = new Twilio.Verb.Say( question.title );
    
    // Build the answer options.
    var choices = [];
    for( var i=0 ; i < question.choices.length ; i++ ) {
        var choice = question.choices[i];
        var verb = new Twilio.Verb.Say( "Enter "+ (i+1) +" for "+ choice.label +"." );
        choices.push( verb );
    }
    var gather = new Twilio.Verb.Gather().withVerbs( choices );
    // Output the TwiML.
    resp.send(progressSay, questionSay, gather);
         
} else {
    resp.go("ThankYouVoice");
}
 

Question Object

Some of the methods return a question object. The parameters and structure are as follows:

{
    id         : String,  // The id of the question.
    title      : String,  // The title of question.
    type       : String,  // The type of question.
    index      : Integer, // The index of the question.
    pageNum    : Integer, // The page number of the question.
    choiceType : String,  // The type of choice.
    choices : [
        {
            score : Integer, // The score for the question.
            label : String   // The answer text for the question.
        }
    ]
}
Question TypesChoice Types 
dropdown-choice single Expects one response value of question index.
single-choice single Expects one response value of question index.
boolean-choice boolean Expects one response value of question index.
multiple-choice multi Expects a series of index response values: "12345"
text-response string Expects a text string. For voice, transcribe a <Record> verb.
slider string Expects an integer within the specified slider range.

FluidSurveys Class

This class and child classes integrate with the FluidSurveys Surveys API. It will let you retrieve surveys, iterate through the questions and respond with answers.

Methods

static getSurvey ( apiKey, password, surveyId ) : FluidSurveys.Survey

Loads the survey from the web service and creates, on the first call, the the response group. On production servers, the survey is cached for 10 minutes.

Parameters:

Returns:
FluidSurveys.Survey : A FluidSurveys.Survey instance.


FluidSurveys.Survey Class

This class represents the survey retrieved from your FluidSurveys account. Tip: To find a survey's Id, look at the URL. For example, http://fluidsurveys.com/account/surveys/123456/.

The constructor is private.

Methods

getTitle ( ) : String

Returns the title of the survey.

Returns:
String : The title of the survey.


getStatus ( ) : String

Returns the status of the survey.

Returns:
String : The status of the survey.


getURL ( ) : String

Returns a URL to the online version of the survey.

Returns:
String : A URL to the survey.


getNumPages ( ) : Integer

Returns the number of pages to the survey. This does not affect how TwHello handles the questions.

Returns:
Integer : The number of pages.


getNumQuestions ( ) : Integer

Returns the number of questions in the survey.

Returns:
Integer : Number of questions.


getQuestion ( index ) : Object

Returns a survey question by the specified index.

Parameters:

Returns:
Object : The question parameters.


getQuestionById ( id ) : Object

Returns a survey question by the specified id set by FluidSurveys.

Parameters:

Returns:
Object : The question parameters.


sessionIterator ( index ) : FluidSurveys.Survey.Iterator

Returns an iterator to the questions that persists for a session.

Parameters:

Returns:
FluidSurveys.Survey.Iterator : The question parameters.


recordAnswer ( questionId, answer ) : Boolean

Sends the given answer of the given question to FluidSurveys.

Parameters:

Returns:
Boolean : The success of the operation.


FluidSurveys.Survey.Iterator Class

This iterator traverses the survey questions in order, persisting position for the duration of the session.

The constructor is private.

Methods

hasNext ( ) : Boolean

Returns true if the iteration has more questions.

Returns:
Boolean : True if the iteration has more questions.


next ( ) : Object

Returns the next question in the iteration.

Returns:
Object : The next question.


current ( ) : Object

Returns the current question in the iteration.

Returns:
Object : The current question.


recordAnswer ( answer ) : Boolean

Sends the given answer to the current question to FluidSurveys.

Parameters:

Returns:
Boolean : The success of the operation.

An IDE and Cloud Service for Voice and Messaging Applications.

Design by workflow. Program in JavaScript. Deploy to AWS. Powered by Twilio.

TwHello - IDE and Cloud Service for Voice and Messaging Apps - Powered by Twilio   About UsContactLegal

© 2014 TwHello, Inc. All rights reserved.