javascript - react-native 应用程序中的 Amazon Lex 应查询 SQL 数据库并回答用户问题
问题描述
我已经成功地将 Lex 集成到 react-native 应用程序中。按照以下步骤
https://aws-amplify.github.io/docs/js/interactions
下面是我的 React-native Lex 应用程序:
import React, { Component } from 'react';
import { StyleSheet, Text, SafeAreaView, Alert, StatusBar } from 'react-native';
import Amplify from 'aws-amplify';
import { ChatBot } from 'aws-amplify-react-native';
import voiceLibs from 'aws-amplify-react-native/dist/Interactions/ReactNativeModules'
import awsconfig from './aws-exports';
Amplify.configure(awsconfig);
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
paddingTop: StatusBar.currentHeight,
},
});
export default class App extends Component {
state = {
botName: 'SampleBotApp',
welcomeMessage: 'Welcome, what would you like to do today?',
};
constructor(props) {
super(props);
this.handleComplete = this.handleComplete.bind(this);
}
handleComplete(err, confirmation) {
if (err) {
Alert.alert('Error', 'Bot conversation failed', [{ text: 'OK' }]);
return;
}
Alert.alert('Done', JSON.stringify(confirmation, null, 2), [{ text: 'OK' }]);
this.setState({
botName: 'SampleBotApp',
});
return 'Thank you! what would you like to do next?';
}
render() {
const { botName, showChatBot, welcomeMessage } = this.state;
return (
<SafeAreaView style={styles.container}>
<ChatBot
botName={botName}
welcomeMessage={welcomeMessage}
onComplete={this.handleComplete}
clearOnComplete={false}
styles={StyleSheet.create({
itemMe: {
color: 'red'
}
})}
voiceEnabled={true}
voiceLibs={voiceLibs}
conversationModeOn={true}
/>
</SafeAreaView>
);
}
}
我的要求是从用户那里获得输入,例如“有多少学生选择了英语科目?” 连接到 SQL 数据库查询结果和响应返回给用户说“有 20 名学生选择了英语科目。”。
我真的不知道如何连接到 SQL 数据库并将查询结果定向到 Lex,以便 Lex 给出正确的响应。
我有 POST api 将返回我 JSON 对象,我已经在 C# 中为.Net 项目连接过。但是在本机反应(javascript)中,我如何从 Amazon Lex 读取响应并查询到数据库并取回结果,Lex 将响应用户..
提前致谢....
解决方案
推荐阅读
- kendo-ui-angular2 - 对话服务内容中的换行符被忽略
- c# - 在日期、小时和分钟之间迭代
- node.js - 在第二个计划中制作节点检查文件
- powershell - 如果程序存在卸载
- ios - 如何将 UILabel 添加到 UICollectionView 控制器
- xml - XSLT:当“n”被赋予另一个属性的值时,重复输出值 n 次
- java - 如何在流中查找字符串数组的值
- heroku - 由于缺少导入程序,Keystone.js 应用程序在 Heroku 上启动失败?
- linkedin - 使用 LinkedIn V2 API 使用视频资产创建 UGC 帖子
- python - 如何总结不同的groupby组合?