Repository navigation
Description
I am using quickblox system notification in my platform for sending live notifications in NodeJs.
First time I try to send live notification, It works perfectly fine but when I try to send notification afterwards, I am getting the following error, even though it send the notification.
TypeError: Cannot read property 'querySelector' of null
at Object.getElementText (/abc/dropN/did/node_modules/quickblox/src/modules/chat/qbChatHelpers.js:123:26)
at ChatProxy._onSystemMessageListener (/abc/dropN/did/node_modules/quickblox/src/modules/chat/qbChat.js:641:42)
at Client. (/abc/dropN/did/node_modules/quickblox/src/modules/chat/qbChat.js:862:30)
at Client.emit (events.js:315:20)
at Client.EventEmitter.emit (domain.js:482:12)
at Client._handleStanza (/abc/dropN/did/node_modules/node-xmpp-client/lib/Client.js:227:12)
at Client.onStanza (/abc/dropN/did/node_modules/node-xmpp-client/lib/Client.js:221:8)
at Connection.emit (events.js:315:20)
at Connection.EventEmitter.emit (domain.js:482:12)
at Connection.onStanza (/abc/dropN/did/node_modules/node-xmpp-core/lib/Connection.js:377:10)
at StreamParser. (/abc/dropN/did/node_modules/node-xmpp-core/lib/Connection.js:231:10)
at StreamParser.emit (events.js:315:20)
at StreamParser.EventEmitter.emit (domain.js:482:12)
at SaxLtx. (/abc/dropN/did/node_modules/@xmpp/streamparser/index.js:69:14)
at SaxLtx.emit (events.js:315:20)
Due to this, my code keeps crashing. Is there any way through which I can prevent this error and send the system notifications seamlessly.
Here is my code through which I am sending these notification.
QB.init(APPLICATION_ID, AUTH_KEY, AUTH_SECRET, ACCOUNT_KEY);
var params = {
userId: 121312,
password: XXXXXYYYYYYY,
};
console.log(params);
QB.createSession({
userId: 121312,
password: XXXXXYYYYYYY,
}, function (err, result1) {
if (err) {
console.log('Something went wrong: ' + JSON.stringify(err));
reject(err)
} else {
console.log("new session created---", JSON.stringify(result1));
QB.chat.connect({
userId: 121312,
password: XXXXXYYYYYYY,
}, async function (error, contactList) {
if (error) {
console.log('not connected to chat', error);
reject(error)
} else {
console.log(error, 'connected to chat', contactList);
var message = {
body: "System_notification",
extension: {
param1: "value1",
param2: "value2",
},
};
var opponentId = 12321321;
try {
message.id = QB.chat.sendSystemMessage(opponentId, message);
console.log("Notification sent", message.id)
resolve("notification sent")
// or message.id = QB.chat.sendSystemMessage(opponentId, message) if message ID is needed
} catch (e) {
if (e.name === "ChatNotConnectedError") {
console.log("not connected")
reject(e)
}
}
}
});
}
});
Activity
sanidhya1712 commentedon Apr 18, 2022
var QuickBlox = require('quickblox').QuickBlox;
var QB = new QuickBlox();
QB.init(APPLICATION_ID, AUTH_KEY, AUTH_SECRET, ACCOUNT_KEY);
This is how I have initialized the quickblox. Is this an incorrect way to initialize because I have followed the documentation.
I have also added the code with I am using above. Is there any issue with that ?
Error which I am getting is in quickblox node modules, So I don't think that it's an nodejs issue.
sanidhya1712 commentedon Apr 26, 2022
Hi @QB-nikolay-zolotarov , All the sample chat code is from the frontend perspective. We already have a running code on our frontend application but the issue we are facing are on backend side(NodeJs) while send system notification.
Do you have any sample of code from backend perspective?
sanidhya1712 commentedon Apr 26, 2022
@QB-nikolay-zolotarov This problem is not about Nodejs. We have written just a piece of javascript code, by referring Quickblox documentation .
Can we explain the reason that when this error occurs in quickblox node module?
sanidhya1712 commentedon Apr 27, 2022
@QB-nikolay-zolotarov
Sample code-
var QuickBlox = require('quickblox').QuickBlox;
var QB = new QuickBlox();
async function sendSystemNotification(req) {
return new Promise(async (resolve, reject) => {
console.log("here");
// let adminSession = await createSession(req);
QB.init(APPLICATION_ID, AUTH_KEY, AUTH_SECRET, ACCOUNT_KEY);
var params = {
userId: parseInt(req.body.senderQBUserId),
password: req.body.senderQBPassword,
};
console.log(params);
QB.createSession({
userId: parseInt(req.body.senderQBUserId),
password: req.body.senderQBPassword,
}, function (err, result1) {
if (err) {
console.log('Something went wrong: ' + JSON.stringify(err));
reject(err)
} else {
console.log("new session created---", JSON.stringify(result1));
QB.chat.connect({
userId: parseInt(req.body.senderQBUserId),
password: req.body.senderQBPassword,
}, async function (error, contactList) {
if (error) {
console.log('not connected to chat', error);
reject(error)
} else {
console.log(error, 'connected to chat', contactList);
var message = {
body: "System_notification",
extension: {
param1: "value1",
param2: "value2",
},
};
var opponentId = Number(req.body.recieverQBuserId);
try {
message.id = QB.chat.sendSystemMessage(opponentId, message);
console.log("Notification sent", message.id)
QB.chat.disconnect();
//let destroy = await destroySession(req)
resolve("notification sent")
// or message.id = QB.chat.sendSystemMessage(opponentId, message) if message ID is needed
} catch (e) {
if (e.name === "ChatNotConnectedError") {
console.log("not connected")
reject(e)
}
}
}
});
}
});
});
}
Instruction to run this-
call sendNotification api with payload {senderQBUserId:xxxxxx, senderQBPassword: xxxxxx,opponentId:xxxxx} --> Call sendSystemNotification function which send the notification
BertoGz commentedon Dec 10, 2022
Im also seeing "TypeError: Cannot read property 'querySelector' of null" after the opponent receives a system message.
I have already configured quickblox correctly as instructed in the docs since I am able to confirm an active user session. Im able to create dialogs, send chats, use isTyping listener etc. The only thing failing at the moment is the onSystemMessageListener. On one occasion I was able to successfully get the handler to work correctly, but it wasnt related to my code. Im investigating more.