简体   繁体   English

Claudia.js文字回应和Alexa的问题

[英]issues with Claudia.js text responses and Alexa

I'm working on a Claudia.js bot that can be reached through Slack, FB messenger, and as an Alexa skill. 我正在开发一个Claudia.js机器人,可以通过Slack,FB Messenger和Alexa技能来实现。 Supposedly in claudia, you can return plain text and the framework will give it back to the "frontend" correctly... What I have currently have here works fine with FB and Slack, but when I access it through the Alexa "Service Simulator" I always get "The response is invalid." 据说在claudia中,您可以返回纯文本,并且框架会将其正确地返回给“前端” ...我目前在这里拥有的功能与FB和Slack都可以正常工作,但是当我通过Alexa“ Service Simulator”访问它时我总是收到“响应无效”。 Here is the lambda that uses Claudia.js. 这是使用Claudia.js的lambda。 Basically it gets messages from the client and then shunts them to another Lambda that is the "AI". 基本上,它从客户端获取消息,然后将它们分流到另一个Lambda,即“ AI”。 Alexa seems to be choking on line 67. Ideas? Alexa似乎在67号线上令人窒息。

const promiseDelay = require('promise-delay');
// const aws = require('aws-sdk');
// const lambda = new aws.Lambda();
const lambda = require('aws-lambda-invoke');

const botBuilder = require('claudia-bot-builder');

const stackTrace = require('stack-trace');

//const slackDelayedReply = botBuilder.slackDelayedReply;
const getIntentName = alexaPayload =>
    alexaPayload &&
    alexaPayload.request &&
    alexaPayload.request.type === 'IntentRequest' &&
    alexaPayload.request.intent &&
    alexaPayload.request.intent.name;


const api = botBuilder((message, apiRequest) => {
  console.log = console.log.bind(null, '[LOG]');
  console.info = console.info.bind(null, '[INFO]');
  console.error = console.error.bind(null, '[ERROR]');
  console.warn = console.warn.bind(null, '[WARN]');

  console.info(message, apiRequest);
  console.log(apiRequest.body);

  const requestData = {
    'user-id': {
      type: message.type,
      ID: message.sender
    },
    epoch: 1484771343.01,
    'payload-type': 'luis',
    facets: {},
    utterance: 'Seek Showtimes',
    payload: {
      query: 'Seek Showtime',
      topScoringIntent: {
        intent: 'SeekShowtime',
        score: 1.0
      },
      intents: [{
        intent: 'SeekShowtime',
        score: 1
      }],
      entities: []
    }
  };
  if (message.text) {
    return new Promise((resolve, reject) => {
      lambda.raw.invoke({
        FunctionName: 'ca2',
        Payload: JSON.stringify(requestData),
      }, (err, done) => {
        if (err) {
          const trace = stackTrace.parse(err);
          console.warn(err);
          console.error(trace);
          return reject(err);
        }
        resolve(done);
      });
    }).then((result) => { // the initial response
      const payload = JSON.parse(result.Payload);
      console.log(payload.utterance);
      return payload.utterance;
    }).catch((error) => {
      const trace = stackTrace.parse(error);
      console.warn(error);
      console.error(trace);
      return 'Could not setup';
    });
  } else if (getIntentName(apiRequest.body) === 'ExitApp') {
    return {
      response: {
        outputSpeech: {
          type: 'PlainText',
          text: 'Bye from Bot!'
        },
        shouldEndSession: true
      }
    };
  } else {
    return {};
  }
},
{ platforms: ['facebook', 'slackSlashCommand', 'alexa'] }
);

module.exports = api;

Update -- even if I hardcode a plain text string response or use Alexa Message Builder I still get "The response is invalid." 更新-即使我对纯文本字符串响应进行硬编码或使用Alexa Message Builder,我仍然会收到“响应无效”。 as the Service Response is coming back "undefined." 服务响应返回“未定义”。

Looking at logs, as soon as the response is returned (for parsing by botBuilder and a pass to Alexa) this error occurs [TypeError: Cannot read property 'replace' of undefined] 查看日志,返回响应后(用于botBuilder解析并传递给Alexa),就会发生此错误[TypeError: Cannot read property 'replace' of undefined]


Another update: 另一个更新:

If I replace return payload.utterance with something like 如果我用类似的东西替换return payload.utterance

if (type === 'alexa-skill') {
        Console.warn('trying to contact alexa');
        return "Hi from Alexa";
      }

The problem persists. 问题仍然存在。

Here is where the Json Request comes in, no problem: 这是Json Request传入的地方,没问题:

2017-04-27T18:06:30.552Z    3d70c273-2b74-11e7-a1c8-bf3fec00cbff    STORE Map { "user-id": Map { "type": "alexa-skill", "ID": "amzn1.ask.account.AF6FUNJDSHGCXPVSAO5HUSRYFBD3SPCJJLILC4HLPS3K3L4AOWIMXPS4ZDDCXQ3ZVIV5L4FOMYD23PWZXEIAKYQBVXIQTPE2WW2PMBIXQIY3TUATXADCVNYO7NYUR2B45EU5GRIWBFHQIPLQVDQZMXD7IYVGTKAV3OWPHROCPR7XIUGNSJEAGQZJOMULSKT5HYSNUNJONASE34Y" }, "epoch": 1484771343.01, "payload-type": "luis", "utterance": "when is Logan playing", "payload": Map { "query": "when is Logan playing" } }

Here is the response I get back from the other lambda (the payload): 这是我从另一个lambda(有效负载)获得的响应:

017-04-27T18:06:32.513Z 3d70c273-2b74-11e7-a1c8-bf3fec00cbff    [LOG] mnlpData { StatusCode: 200,
Payload: '{"utterance": "To find movies playing near you, I need to know where you are. Please tell me your zip code.", "AskLocation": 1, "context": {"updated": 1493316392.162429, "user_id": "TEST_ID_TUES_14", "sessions": [{"intents": ["SeekShowtime", "SeekShowtime"], "facet-delta": {}, "facets": {"ity.location": {"ity.zip": "", "ity.code": "", "ity.theatre-name": ""}, "ity.movie": {"ity.title": "", "ity.code": ""}, "ity.time": [], "ity.date": []}, "modes": ["", "SHOWTIME_SWITCH", "AskLocation", "SHOWTIME_SWITCH", "AskLocation"]}], "created": 1493316379.950335, "mode_process_count": 2, "user-id": {"type": "alexa-skill", "ID": "amzn1.ask.account.AF6FUNJDSHGCXPVSAO5HUSRYFBD3SPCJJLILC4HLPS3K3L4AOWIMXPS4ZDDCXQ3ZVIV5L4FOMYD23PWZXEIAKYQBVXIQTPE2WW2PMBIXQIY3TUATXADCVNYO7NYUR2B45EU5GRIWBFHQIPLQVDQZMXD7IYVGTKAV3OWPHROCPR7XIUGNSJEAGQZJOMULSKT5HYSNUNJONASE34Y"}, "utterance": ["To find movies playing near you, I need to know where you are. Please tell me your zip code."]}}' }

then: 然后:

2017-04-27T18:06:32.514Z    3d70c273-2b74-11e7-a1c8-bf3fec00cbff    [WARN] trying to contact alexa

and then the error: 然后是错误:

2017-04-27T18:06:32.514Z    3d70c273-2b74-11e7-a1c8-bf3fec00cbff    [TypeError: Cannot read property 'replace' of undefined]

If you haven't already, run claudia update --configure-alexa-skill and enter your bot's name, then use the url it gives in your alexa skill builder setup. 如果尚未安装,请运行claudia update --configure-alexa-skill并输入您的机器人名称,然后使用其在alexa技能生成器设置中提供的网址。 Select HTTPS instead of lambda arn. 选择HTTPS而不是lambda arn。

Currently, message.text is being passed as an empty string, which means that none of your log blocks are firing, and you are returning an empty object at the very bottom of your code. 当前, message.text作为空字符串传递,这意味着没有日志块被触发,并且您在代码的最底部返回了一个空对象。 Test it yourself by replacing that empty object with a string, the alexa tester no longer complains. 通过用字符串替换该空对象自己进行测试,alexa测试人员不再抱怨。

So why is message.text an empty string? 那么,为什么message.text是一个空字符串? Claudia js populates the text field by concatenating all the slots that have been filled for your intent. Claudia js通过串联所有已填入您的意图的插槽来填充文本字段。 If your intent has no slots, then claudia passes an empty string. 如果您的意图没有插槽,则claudia传递一个空字符串。

Add slots to your intent, make sure the skill is configured, and fix the logic statement issues. 向您的意图添加插槽,确保已配置技能,并修复逻辑语句问题。

First, if you notice the payload that is sent to you from the other lambda, you can see the utterance is an array, so you might have to pass the first element if present. 首先,如果您注意到从另一个lambda发送给您的有效负载,则可以看到utterance是一个数组,因此,如果存在,您可能必须传递第一个元素。

By looking at the code of the bot builder, my best bet is that the error you're getting is due to the fact your alexaAppName is undefined, and when passing it down to the responder that is encoded in base64, it's not possible to run a replace of this variable. 通过查看机器人生成器的代码,我最好的选择是,您得到的错误是由于alexaAppName未定义的事实alexaAppName的,当将其传递 alexaAppName base64编码的响应器时,是不可能运行的替换此变量。

I would try to make sure my app name is correctly configured and what's given is a valid string as shown in the alexa claudia example . 我将尝试确保正确配置了我的应用程序名称,并提供了一个有效的字符串,如alexa claudia示例中所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM