quickblox chat.connect失败,出现422错误 - 无法处理的实体

时间:2017-09-07 10:54:55

标签: node.js quickblox

我使用下面的代码使用chatbot node js module quickbox chatbots连接quickblox。通过使用以下步骤

mkdir my_awesome_bot

cd my_awesome_bot

npm init

npm install quickblox --save

触摸index.js

然后打开index.js文件并编写以下代码:

'use strict';

const QB = require('quickblox');
const CONFIG = {
    "appId": "XX",
    "authKey": "XX",
    "authSecret": "XX",
    "botUser": {
        "id": "XX",
        "password": "XX",
        "fullname": "XX"
    }
};

// Initialise QuickBlox
QB.init(CONFIG.appId, CONFIG.authKey, CONFIG.authSecret);

// Connect to Real-Time Chat
QB.chat.connect({
    userId: CONFIG.botUser.id,
    password: CONFIG.botUser.password
  }, (chatConnectError) => {
    if (chatConnectError) {
        console.log('[QB] chat.connect is failed', JSON.stringify(chatConnectError));
        process.exit(1);
    }

    console.log('[QB] Bot is up and running');

    // Add chat messages listener
    QB.chat.onMessageListener = onMessageListener();
});

function onMessageListener(userId, msg) {

  if (msg.type == 'chat') {
    if(msg.body){
        let answerMessage = {
            type: 'chat',
            body: msg.body, // echo back original message
            extension: {
                save_to_history: 1
            }
        };

        QB.chat.send(userId, answerMessage);
    }
  }

}

process.on('exit', function () {
    console.log('Kill bot');
    QB.chat.disconnect();
}); 

但无法连接并低于结果..

chat.connect is failed {"code":422,"status":"error","detail":"Status.ERROR - An error has occurred","message":"Unprocessable Entity"}

1 个答案:

答案 0 :(得分:0)

你必须填写这个:

const CONFIG = {
    "appId": "XX",
    "authKey": "XX",
    "authSecret": "XX",
    "botUser": {
        "id": "XX",
        "password": "XX",
        "fullname": "XX"
    }
};