Ошибка типа [ERR_INVALID_ARG_TYPE]: - PullRequest
1 голос
/ 04 апреля 2020

Я пытаюсь получить ответ от 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);
        })
    }

, и я подписал его в файле реагирующего компонента 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],
      });
    });
  }
...