TypeError [ERR_INVALID_ARG_TYPE]:

Viewed 2954

I'm trying to get response from Dialog Flow, but I'm getting this error:

 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. 

Here's the code.

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);
        })
    }

and I've subscribed it in react component file 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 Answers
Related