NodeJS TypeError [ERR_INVALID_ARG_TYPE]:

moiiocjp  于 2023-06-05  发布在  Node.js
关注(0)|答案(1)|浏览(569)

我尝试从对话流获取响应,但收到此错误:

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],
      });
    });
  }
bfnvny8b

bfnvny8b1#

此错误发生在连接到componentDidMount()中的通道时-> env变量的名称应该是PUSHER_KEY而不是APP_SECRET_KEY。
下面是可以用于推送器客户端和服务器连接的有效env变量列表:PUSHER_APP_ID PUSHER_KEY PUSHER_SECRET

相关问题