0
I need to send a simple notification using onesignal, but is giving error in the build of the web app because of https import, as the code I am importing as follows:
var https = require('https');
Note: This example is from the site of onesignal itself, the problem is that I can not do the request otherwise, so it works, but at the time of the build error. So what I need to basically do is, figure out another way to call this https to request the onesignal api and solve the problem. That’s all I need to close this project.
notificaAgendamentoCriadoProfissional(){
var sendNotification = function(data) {
var headers = {
"Content-Type": "application/json; charset=utf-8"
};
var options = {
host: "onesignal.com",
port: 443,
path: "/api/v1/notifications",
method: "POST",
headers: headers
};
var https = require('https');
var req = https.request(options, function(res) {
res.on('data', function(data) {
console.log("Response:");
console.log(JSON.parse(data));
});
});
req.on('error', function(e) {
console.log("ERROR:");
console.log(e);
});
req.write(JSON.stringify(data));
req.end();
};
var message = {
app_id: "meu id",
contents: {"en": "Você recebeu uma nova solicitação. Verifique imediatamente a sua lista de agendamentos"},
include_player_ids: [this.idOneSignalProfissional]
};
sendNotification(message);
}
The mistake I’m getting is always this:
[18:23:19] typescript: ...roAdm/src/pages/criar-agendamento-procedimento/criar-agendamento-procedimento.ts, line: 178
Cannot find name 'require'.
L178: var https = require('https');
I solved here, I was able to reassemble the function and do the post!
– Diego Estacho
Diego, consider posting an answer showing what was wrong and how you managed to solve it.
– Boneco Sinforoso
I updated, and put the example of the correction
– Diego Estacho