如何为带数字的Amazon Alexa Skills Kit(ASK)混合字符串提供输入? [英] How to give input to Amazon Alexa Skills Kit (ASK) mixed string with numbers?

查看:78
本文介绍了如何为带数字的Amazon Alexa Skills Kit(ASK)混合字符串提供输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Amazon Alexa技能套件来进行某种自动化,这将需要接受由字符串和数字组成的语音输入( a-test12fish )。

I'm trying to create a Amazon Alexa Skills Kit to do some kind of automation which would be required to take speech input comprised of strings and numbers (a-test12fish).

当我在Alexa Skills Kit中使用自定义插槽时,并不是让我用数字键入字符串。当我尝试键入询问alexa时,dangerZone找到a-test12fish 时,出现以下错误:

When I've used custom slots in Alexa Skills Kit, it is not letting me key in strings with numbers. When I try to key in ask alexa, dangerZone find a-test12fish, I'm getting the following error:


错误:无效的文本输入。文本应以字母开头,并且只能包含字母,空格,句点或撇号

Error: Invalid text input. Text should begin with alphabets and should only contain alphabets, whitespaces, periods or apostrophes

如何克服此错误?

推荐答案

这是一个解决方案。

您可能不想在此完成意向架构。而是尝试使用Node.js创建自定义模式,该模式将字母,数字和符号编译为单个响应。这是我对字母数字输入模式的再现。请注意:我只是为了回答您的问题而写的,而没有以更高的技能进行测试。话虽如此,我在 MODES 上取得了巨大的成功,并且如果有机会,我一定会以自己的技能来实现这一点。

You probably don't want to complete this in the intent schema. Instead try creating a custom mode withing Node.js that compiles letters, numbers and symbols into a single response. This is my rendition of an alpha numeric input Mode. Please Note: I just wrote this in response to your question and have not tested it in a larger skill. With that said I've had great success with MODES and will certainly implement this in my own skill when I have a chance.

此代码背后的想法是,您将用户推入一个单独的模式,该模式将忽略 NumberIntent 以外的所有意图, LetterIntent SymbolIntent 和一些帮助功能。用户快速输入其字母数字值,并在完成后激活CompletedIntent。然后可以在您的技能的其他地方使用该字母数字值。如果您尚未使用模式,请注意,在完成或退出时,您将被重定向回 LOBBYMODE ,在此您可以继续访问您的技能的其他意图。

The idea behind this code is that you push users into a seperate Mode that ignores all intents other than NumberIntent, LetterIntent, SymbolIntent, and a few help features. The user quickly enters their alpha numeric value and upon completion activates the CompletedIntent. That alphanumeric value can then be used elsewhere in your skill. If you have not used Modes note that on completion or exit you will be redirected back to LOBBYMODE where you can continue to access other intents in your skill.

var lobbyHandlers = Alexa.CreateStateHandler(states.LOBBYMODE, {

    'enterPasswordIntent': function () {
      this.attributes['BUILDPASSWORD'] = '';
      this.handler.state = states.PASSWORDMODE;
      message = ` You will now create a password one letter, number or symbol at a time.  there will be no message after each entry.  simply wait for alexa's ring to become solid blue then stay your next value.  When you are satisfied say complete. Begin now by saying a number, letter, or keyboard symbol. `;
      reprompt = `Please say a number letter or symbol`;
      this.emit(':ask', message, reprompt);
    },

    //Place other useful intents for your Skill here

    'Unhandled': function() {
        console.log("UNHANDLED");
        var reprompt = ` You're kind of in the middle of something.  Say exit to end createing this password.  otherwise say complete if you've stated the whole password.  or repeat to hear the current password you've entered.  `;
        this.emit(':ask', reprompt, reprompt);
    }
});


var buildAlphaNumericPasswordHandlers = Alexa.CreateStateHandler(states.PASSWORDMODE, {
    'numberIntent': function () {// Sample Utterance: ninty nine  AMAZON.NUMBER
      var number = this.event.request.intent.slots.number.value; //I believe this returns a string of digits ex: '999'
      this.attributes['BUILDPASSWORD'] = this.attributes['BUILDPASSWORD'].concat(number);
      message = ``; //No message to make saying the next letter, number or symbol as fluid as possible.
      reprompt = `Please say the next number letter or symbol`;
      this.emit(':ask', message, reprompt);
    },
    'letterIntent': function () {// Sample Utterance: A   -- Custom Slot LETTERS [A, b, c, d, e, ... ]
      var letter = this.event.request.intent.slots.letter.value;
      this.attributes['BUILDPASSWORD'] = this.attributes['BUILDPASSWORD'].concat(letter);
      message = ``; //No message to make saying the next letter, number or symbol as fluid as possible.
      reprompt = `Please say the next number letter or symbol`;
      this.emit(':ask', message, reprompt);
    },
    'symbolIntent': function () {// Sample Utterance: Dash -- Custom Slot SYMBOLS [Pound, Dash, Dollar Sign, At, Exclamation point... ]
      var symbol = this.event.request.intent.slots.symbol.value;

      // Create a dictionary object to map words to symbols ex Dollar Sign => $.  Will need this because you likely cant put $ as a custom slot value. Can also map multiple names to the same value  ex. Dash => Tack = \> "-"
      var singleCharacterSymbol = symbolDict[symbol]; //^^^ Need to create dictionary

      this.attributes['BUILDPASSWORD'] = this.attributes['BUILDPASSWORD'].concat(singleCharacterSymbol);
      message = ``; //No message to make saying the next letter, number or symbol as fluid as possible.
      reprompt = `Please say the next number letter or symbol`;
      this.emit(':ask', message, reprompt);
    },
    'CompleteIntent': function() { //Sample Utterance: Complete
        console.log("COMPLETE");
        this.handler.state = states.LOBBYMODE;
        var reprompt = ` Your entry has been saved, used to execute another function or checked against our database. `;
        this.emit(':ask', reprompt, reprompt);
    },
    'ExitIntent': function() { //Sample Utterance: Exit
        console.log("EXIT");
        this.handler.state = states.LOBBYMODE;
        message = `You have returned to the lobby, continue with the app or say quit to exit.`;
        this.emit(':ask', message, message);
    },
    'RepeatIntent': function() {
        var currentPassword = this.attributes['BUILDPASSWORD'];
        var currentPasswordExploded  =  currentPassword.replace(/(.)(?=.)/g, "$1 "); //insert a space between each character so alexa reads correctly.
        var message = ` Your current entry is as follows. `+currentPasswordExploded;
        var reprompt = `  say complete if you've stated the whole password. Otherwise continue to say numbers letters and symbols. `;
        this.emit(':ask', reprompt, reprompt);
    },
    'Unhandled': function() {
        console.log("UNHANDLED");
        var reprompt = ` You're kind of in the middle of something.  Say exit to end creating this password, say complete if you've stated the whole password, say repeat to hear the current password you've entered, or continue to state letters, numbers and symbols  `;
        this.emit(':ask', reprompt, reprompt);
    }
});

这篇关于如何为带数字的Amazon Alexa Skills Kit(ASK)混合字符串提供输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆