TypeError [ERR_INVALID_ARG_TYPE]:

时间:2020-04-04 00:01:20

标签: node.js reactjs dialogflow-es pusher

我正在尝试从Dialog Flow中获取响应,但是却收到此错误:

 TypeError[ERR_INVALID_ARG_TYPE]:The "key" argument must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received undefined.
 The arguments ('bot', 'bot-response') are undefined. 

这是代码。

process_message.js

      const request = {
        session: sessionPath,
        queryInput: {
          text: {
            text: message,
            languageCode,
          },
        },
      };
      sessionClient
        .detectIntent(request)
        .then(responses => {
          const result = responses[0].queryResult;
          return pusher.trigger('bot', 'bot-response', {
            message: result.fulfillmentText,
          });
        })
        .catch(err => {
          console.error('ERROR:', err);
        })
    }

我已经在React组件文件chatbot.component.js中订阅了它

componentDidMount() {
    const pusher = new Pusher(process.env.APP_SECRET_KEY, {
      cluster: process.env.APP_CLUSTER,
      encrypted: true,
    });

    const channel = pusher.subscribe('bot');
    channel.bind('bot-response', data => {
      const msg = {
        text: data.message,
        user: 'ai',
      };
      this.setState({
        conversation: [...this.state.conversation, msg],
      });
    });
  }

0 个答案:

没有答案