Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error in sending system notification #425

Open
sanidhya1712 opened this issue Apr 13, 2022 · 9 comments
Open

Getting error in sending system notification #425

sanidhya1712 opened this issue Apr 13, 2022 · 9 comments

Comments

@sanidhya1712
Copy link

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

@ghost
Copy link

ghost commented Apr 13, 2022

Hello, I assume that the issue is related to execution of code - the context.
Please make sure that QuickBlox JavaScript SDK is initialized correctly and you have already followed our official documentation: https://docs.quickblox.com/docs/js-users#before-you-begin

Please refactor your code as we can see that the issue is outside from QuickBlox JavaScript SDK and related to Node implementation.

Unfortunately, we do not provide support with Node.js.

@sanidhya1712
Copy link
Author

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.

@ghost
Copy link

ghost commented Apr 25, 2022

@sanidhya1712 The init seems to be correct.
You may check our sample:
https://github.com/QuickBlox/quickblox-javascript-sdk/tree/gh-pages/samples/chat
Also, please make sure that you use the latest version of the SDK:
https://github.com/QuickBlox/quickblox-javascript-sdk/releases/tag/2.13.11
You can modify the sample by adding your notification functionality to identify the issue.
Additionally, please specify where exactly you are getting the error.

@sanidhya1712
Copy link
Author

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?

@ghost
Copy link

ghost commented Apr 26, 2022

@sanidhya1712 Hello, unfortunately, we don't have backend (Node.js) samples. As the JS sample works as expected, I assume that the issue is related to the Node.js implementation. Unfortunately, we do not provide support with Node.js. Please review the implementation on your end.

@sanidhya1712
Copy link
Author

sanidhya1712 commented 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?

@ghost
Copy link

ghost commented Apr 26, 2022

@sanidhya1712 To investigate the issue further, please provide a sample and step-by-step instructions on how to reproduce the issue.

@sanidhya1712
Copy link
Author

@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
Copy link

BertoGz commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants