AWS Amplify MissingRequiredParameter userId错误

问题描述 投票:1回答:1

我正在按照Interactions开始的指南。当我在Interactions上调用send方法时,我收到以下错误:

(node:27796)UnhandledPromiseRejectionWarning:MissingRequiredParameter:在params中缺少必需的键'userId'

看起来Interactions期待一个userq参数,在@aws-amplify/interactions/lib/Providers/AWSLexProvider.js中,应该是从credentials.identityId中提取的。但是,当我记录credentials时,它是SharedIniFileCredentials类型,它没有identityId属性according to the documentation

reading the docsidentityId必须是Cognito用户。 AWSLexProvider.js没有试图让CognitoIdentityCredentials获得Cognito证书。

因此,我不确定identityId应该来自哪里。

我的代码是Amplify网站的示例:

import Amplify, { Interactions } from 'aws-amplify';
import aws_exports from './aws-exports';

Amplify.configure(aws_exports);

async function test() {
    let userInput = "I want to reserve a hotel for tonight";

    // Provide a bot name and user input
    const response = await Interactions.send("BookTrip", userInput);

    // Log chatbot response
    console.log (response['message']);
}

test();

那我在这里错过了什么?

amazon-web-services aws-sdk amazon-lex aws-amplify amplifyjs
1个回答
0
投票

我之前没有使用过AWS Amplify,所以这个答案可能不是原因,但我以前曾多次使用过Amazon Lex。这正在寻找的UserId字段可能是Lex PostText / PostContent请求的UserId参数(请参阅下面的代码)

来自PostText Documentation:

var params = {
  botAlias: 'STRING_VALUE', /* required */
  botName: 'STRING_VALUE', /* required */
  inputText: 'STRING_VALUE', /* required */
  userId: 'STRING_VALUE', /* required - THIS IS MISSING FROM YOUR EXAMPLE */
  requestAttributes: {
    '<String>': 'STRING_VALUE',
    /* '<String>': ... */
  },
  sessionAttributes: {
    '<String>': 'STRING_VALUE',
    /* '<String>': ... */
  }
};
lexruntime.postText(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

PostContent Documentation:

var params = {
  botAlias: 'STRING_VALUE', /* required */
  botName: 'STRING_VALUE', /* required */
  contentType: 'STRING_VALUE', /* required */
  inputStream: new Buffer('...') || 'STRING_VALUE' || streamObject, /* required */
  userId: 'STRING_VALUE', /* required - THIS IS MISSING FROM YOUR EXAMPLE */
  accept: 'STRING_VALUE',
  requestAttributes: any /* This value will be JSON encoded on your behalf with JSON.stringify() */,
  sessionAttributes: any /* This value will be JSON encoded on your behalf with JSON.stringify() */
};
lexruntime.postContent(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

现在,就像我之前说过的那样,我之前没有使用过AWS Amplify,所以老实说我不确定,但希望这能指出你正确的方向。

© www.soinside.com 2019 - 2024. All rights reserved.