How to use ask-sdk-v1adapter - 7 common examples

To help you get started, we’ve selected a few ask-sdk-v1adapter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexa / skill-sample-nodejs-salesforce / lambda / custom / voiceCodeHandlers.js View on Github external
this.emitWithState("AMAZON.StopIntent");
    },
    "AMAZON.CancelIntent": function () {
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("AMAZON.CancelIntent");
    },
    "Unhandled": function () {
      console.log("in New Code unhandled");
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("UnhandledError");
    },
    "SessionEndedRequest": function () {
      console.log("Session ended in NEW_CODE state: " + this.event.request.reason);
    }
  }),
  helpStateHandlers: Alexa.CreateStateHandler(constants.STATES.HELP, {
    "helpTheUser": function () {
      const speechOutput = this.t("HELP_MESSAGE");
      const repromptText = this.t("SHORT_HELP");
      // Defaulting to secure state for the next question, if the customer
      // doesn't have their code set, it will redirect to the code prompt process
      this.handler.state = constants.STATES.SECURE;
      this.emit(":ask", speechOutput, repromptText);
    },
    "AMAZON.StartOverIntent": function () {
      resetAttributes(true, this.attributes);
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("SetupAccount");
    },
    "AMAZON.HelpIntent": function () {
      this.emitWithState("helpTheUser");
    },
github alexa / skill-sample-nodejs-salesforce / lambda / custom / voiceCodeHandlers.js View on Github external
this.emitWithState("SetupAccount");
    },
    'AMAZON.HelpIntent': function () {
      this.handler.state = constants.STATES.HELP;
      this.emitWithState("helpTheUser");
    },
    "Unhandled": function () {
      if (Object.keys(this.attributes).length === 0) {
        resetAttributes(true, this.attributes);
      }
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("SetupAccount");
    }
  }),

  codeStateHandlers: Alexa.CreateStateHandler(constants.STATES.CODE, {
    "SetupAccount": function () {
      // Access token is passed through the session information
      const accessToken = this.event.session.user.accessToken;
      let speechOutput;
      let repromptText;

      // Check to see if the user has linked their account
      if (accessToken) {
        const salesforceUserId = this.attributes[constants.SALESFORCE_USER_ID];
        const hasCode = this.attributes[constants.ATTRIBUTES_HAS_CODE];
        if (salesforceUserId && salesforceUserId.value && hasCode && hasCode.value && verifyVoiceCodeTimeout.call(this)) {
          // We know the salesforce user ID and that the person has a code
          speechOutput = this.t("WELCOME_MESSAGE") + this.t("WELCOME_HAS_CODE");
          this.attributes[constants.ATTRIBUTES_HAS_CODE] = true;
          this.emit(":ask", speechOutput, this.t("WELCOME_HAS_CODE"));
        } else {
github alexa / skill-sample-nodejs-salesforce / lambda / custom / secureHandlers.js View on Github external
*/

'use strict';

var Alexa = require('ask-sdk-v1adapter');
var bcrypt = require('bcryptjs');

const constants = require('./constants');
const voiceCodeHandlers = require('./voiceCodeHandlers');
const sf = require('./salesforce');

const imageObj = {
  largeImageUrl: 'https://s3.amazonaws.com/alexa-salesforce-demo-skill-images/sales_image.png'
};

const handlers = Alexa.CreateStateHandler(constants.STATES.SECURE, {
  'LaunchRequest': function () {
    if (preFunctions.call(this)) {
      let output = '';

      // Get the messaging for the user depending on their state of their voice code 
      if (this.attributes[constants.ATTRIBUTES_CHANGED_CODE]) {
        // Case where user just changed a code
        output = this.t("WELCOME_SUCCESS_NEW_CODE");
        this.attributes[constants.ATTRIBUTES_CHANGED_CODE] = null;
      } else if (this.attributes[constants.ATTRIBUTES_CREATED_CODE]) {
        // Case where user just created a new voice code
        output = this.t("CODE_SET");
        this.attributes[constants.ATTRIBUTES_CREATED_CODE] = null;
      } else if (this.attributes[constants.ATTRIBUTES_CONFIRMED_CODE]) {
        // Case where user confirmed code (coming from another handler)
        output = this.t("WELCOME_SUCCESS_CODE");
github alexa / skill-sample-nodejs-salesforce / lambda / custom / voiceCodeHandlers.js View on Github external
},
    "AMAZON.CancelIntent": function () {
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("AMAZON.CancelIntent");
    },
    "Unhandled": function () {
      console.log("in Change Code unhandled");
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("UnhandledError");
    },
    "SessionEndedRequest": function () {
      console.log("Session ended in CHANGE_CODE state: " + this.event.request.reason);
    }
  }),

  newCodeHandlers: Alexa.CreateStateHandler(constants.STATES.NEW_CODE, {
    "PromptForCode": function () {
      const firstAttempt = this.attributes[constants.ATTRIBUTES_NUM_ATTEMPTS] === 0;
      const speechOutput = firstAttempt ? this.t("CHANGE_NEW_CODE") : this.t("CODE_REPEAT_REQUEST");

      this.emit(":ask", speechOutput, speechOutput);
    },
    "CodeIntent": function () {
      validateCode.call(this);
    },
    "AMAZON.StartOverIntent": function () {
      resetAttributes(true, this.attributes);
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("SetupAccount");
    },
    "AMAZON.HelpIntent": function () {
      this.handler.state = constants.STATES.HELP;
github alexa / skill-sample-nodejs-salesforce / lambda / custom / voiceCodeHandlers.js View on Github external
this.emitWithState("SetupAccount");
    },
    "SessionEndedRequest": function () {
      console.log("Session ended waiting for a code: " + this.event.request.reason);
    },
    "UnhandledError": function () {
      console.log("In constants.STATES.CODE UnhandledError");

      if (Object.keys(this.attributes).length === 0) {
        resetAttributes(true, this.attributes);
      }
      this.emit(":tell", this.t("UNKNOWN_ERROR"));
    }
  }),

  changeCodeHandlers: Alexa.CreateStateHandler(constants.STATES.CHANGE_CODE, {
    "PromptForCode": function () {
      const firstAttempt = this.attributes[constants.ATTRIBUTES_NUM_ATTEMPTS] === 0;
      const speechOutput = firstAttempt ? this.t("CHANGE_PROVIDE_CODE") : this.t("CODE_REPEAT_REQUEST");

      this.emit(":ask", speechOutput, speechOutput);
    },
    "CodeIntent": function () {
      validateCode.call(this);
    },
    "AMAZON.StartOverIntent": function () {
      resetAttributes(true, this.attributes);
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("SetupAccount");
    },
    "AMAZON.HelpIntent": function () {
      this.handler.state = constants.STATES.HELP;
github alexa / skill-sample-nodejs-salesforce / lambda / custom / index.js View on Github external
exports.handler = function (event, context, callback) {
  const alexa = Alexa.handler(event, context);
  alexa.appId = constants.appId;
  alexa.debug = constants.DEBUG;
  alexa.dynamoDBTableName = constants.dynamoDBTableName;
  alexa.resources = languageStrings;
  alexa.registerHandlers(
    voiceCodeHandlers.newSessionHandlers,
    voiceCodeHandlers.codeStateHandlers,
    voiceCodeHandlers.changeCodeHandlers,
    voiceCodeHandlers.newCodeHandlers,
    voiceCodeHandlers.helpStateHandlers,
    secureHandlers
  );
  if (alexa.debug) {
    console.log("\n" + "******************* REQUEST **********************");
    console.log("\n" + JSON.stringify(event, null, 2));
  }
github alexa / skill-sample-nodejs-salesforce / lambda / custom / voiceCodeHandlers.js View on Github external
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

'use strict';

const Alexa = require('ask-sdk-v1adapter');
const bcrypt = require('bcryptjs');

const constants = require('./constants');
const sf = require('./salesforce');

const voiceCodeHandlers = {
  newSessionHandlers: Alexa.CreateStateHandler(constants.STATES.START, {
    'LaunchRequest': function () {
      if (Object.keys(this.attributes).length === 0) {
        resetAttributes(true, this.attributes);
      }
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("SetupAccount");
    },
    'AMAZON.StartOverIntent': function () {
      resetAttributes(true, this.attributes);
      this.handler.state = constants.STATES.CODE;
      this.emitWithState("SetupAccount");
    },
    'AMAZON.HelpIntent': function () {
      this.handler.state = constants.STATES.HELP;
      this.emitWithState("helpTheUser");
    },

ask-sdk-v1adapter

Adapter from v1 Alexa Node.js SDK to v2

Apache-2.0
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis