可能的未处理的承诺拒绝(id:0):TypeError:未定义不是对象(正在评估'result.query.Result.fulfillmentMessages')

时间:2019-05-27 05:50:04

标签: reactjs react-native dialogflow react-native-gifted-chat

 import React from "react";
 import { View } from "react-native";
 import { GiftedChat } from "react-native-gifted-chat";
 import { Dialogflow_V2 } from "react-native-dialogflow-text";



const BOT_USER = {
_id: 2,
 name: "SmartBot",
 avatar: "https://placeimg.com/140/140/any"
 };



export default class App extends React.Component {
constructor(props) {
  super(props);
let firstMsg = {
  _id: 1,
  text: "Hello CoderSchool Fan!",
  createdAt: new Date(),
  user: BOT_USER
};

this.state = {
  messages: [firstMsg]
};
}

componentDidMount() {
Dialogflow_V2.setConfiguration(
  dialogflowConfig.client_email,
  dialogflowConfig.private_key,
  Dialogflow_V2.LANG_ENGLISH_US,
  dialogflowConfig.project_id
 );
 }

 sendBotResponse(text) {
  let msg = {
  _id: this.state.messages.length + 1,
  text,
  createdAt: new Date(),
  user: BOT_USER
};
this.setState(previousState => ({
  messages: GiftedChat.append(previousState.messages, [msg])
}));
}

handleGoogleResponse(result) {
console.log(result);
let text = result.queryResult.fulfillmentMessages[0].text.text[0];
this.sendBotResponse(text);
}

onSend(messages = []) {
this.setState(previousState => ({
  messages: GiftedChat.append(previousState.messages, messages)
}));
let message = messages[0].text;

Dialogflow_V2.requestQuery(
  message,
  result => this.handleGoogleResponse(result),
  error => console.log(error)
);
}

render() {
return (
  <View style={{flex: 1}}>
    <GiftedChat
      messages={this.state.messages}
      onSend={messages => this.onSend(messages)}
      user={{
        _id: 1
      }}
    />
  </View>
 );
}
}

我正在聊天-我的react本机应用程序中的bot使用react-native-gifted-chat和dialogFlow,但是当我键入任何文本并期望该bot的输出时,此警告将发出而没有任何答复。我尝试了很多事情,例如对result.query进行字符串化。...但是之后没有任何反应。 。 enter image description here

0 个答案:

没有答案