我是React-native的新手,我正尝试将dialogflow与react-native集成。
我的代码是:
import React, {Component} from 'react';
import { StyleSheet, View, Button } from 'react-native';
import { Dialogflow_V2 } from "react-native-dialogflow";
class App extends Component() {
constructor(props) {
super(props);
Dialogflow_V2.setConfiguration(
"sample.iam.gserviceaccount.com",
'-----BEGIN PRIVATE KEY-----\sample\n-----END PRIVATE KEY-----\n"',
Dialogflow_V2.LANG_ENGLISH,
'sample-44ce3'
);
}
render() {
const { dialogflow } = this.props.Dialogflow_V2;
return (
<View style={styles.container}>
<Button onPress={() => {
dialogflow.requestQuery("hello", result=>console.log(result), error=>console.log(error));
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default App;
但这告诉我这个错误
谁能向我解释这到底是什么问题,需要什么纠正?提前致谢。
那是因为它无法从道具中找到Dialogflow_V2参考。
在渲染函数中删除此行
const { dialogflow } = this.props.Dialogflow_V2;
直接使用您已经导入的Dialogflow_V2。
Dialogflow_V2.requestQuery("hello", result=>console.log(result), error=>console.log(error));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句