我正在尝试将 Amazon LEX 集成到我的应用程序中。最初我添加了 Amazon cognito,然后我得到了 Cognito Id。接下来,当我尝试与 LEX 通信时,返回一个错误,如下所示
Error Domain=com.amazonaws.AWSLexErrorDomain Code=0 "null" UserInfo={NSLocalizedDescription=null, NSLocalizedFailureReason=AccessDeniedException:http://internal.amazon.com/coral/com.amazon.coral.service/}
AppDelegate 代码:
{
// Override point for customization after application launch.
AWSDDLog.sharedInstance.logLevel = .verbose
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: “given the Id”)
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
credentialProvider.getIdentityId().continueWith(block: { (task) -> AnyObject? in
if (task.error != nil)
{
print("Error: " + task.error!.localizedDescription)
}
else
{
let cognitoId = task.result!
print("Cognito Id is, \(cognitoId)")
}
return task
})
let chatConfig = AWSLexInteractionKitConfig.defaultInteractionKitConfig(withBotName: "BookTrip", botAlias: "Chatting")
AWSLexInteractionKit.register(with: configuration!, interactionKitConfiguration: chatConfig, forKey: "AWSLexVoiceButton")
chatConfig.autoPlayback = false
//AWSLexInteractionKit.register(with: configuration!, interactionKitConfiguration: chatConfig, forKey: "chatConfig")
return true
}
视图控制器代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
(self.voiceButton)?.delegate = self
// (self.voiceButton as AWSLexVoiceButton).delegate = self
}
func voiceButton(_ button: AWSLexVoiceButton, on response: AWSLexVoiceButtonResponse) {
DispatchQueue.main.async(execute: {
// `inputranscript` is the transcript of the voice input to the operation
print("Input Transcript: \(String(describing: response.inputTranscript))")
if let inputTranscript = response.inputTranscript {
self.input.text = "\"\(inputTranscript)\""
}
print("on text output \(String(describing: response.outputText))")
self.output.text = response.outputText
})
}
public func voiceButton(_ button: AWSLexVoiceButton, onError error: Error) {
print("error \(error)")
}
我是否需要将认知 ID 与 LEX 一起传递。谁能帮我这里有什么问题。提前致谢。