response post in node the app java and invoke callback
Hello, I wanted to ask you for an adaptation that I made to your code to respond to a post from a java app, which I cannot modify, I mean the code, but I do know the code that is sent in the post
in this zip is the java file with the query, on line 34
Context.getClient (). Target (this.url + this.token) .request (). Async (). Post (Entity.json ((Object) message), (InvocationCallback) new InvocationCallback <Object> () ... .
This is where I don't know how to make the response code of the node server work, which does work in a test with postman, but in the app, it gives the error log Whatsapp API error because it does not understand the number or the format, it has to be example 542234556678, without the serialized, @us.
the code servidor node
function inicial (message, Object, next) { console.log(message.connection.remoteAddress); app.use(express.json()) // for parsing application/json app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
const phone = phoneNumberFormatter(message.body.phone); const message1 = message.body.message; console.log('req'+ (message.body.phone)); const isRegisteredNumber = checkRegisteredNumber(phone);
next(); if (!isRegisteredNumber) { return Object.status(200).json({ status: false, message: 'The number is not registered' }); }
Object.status(200).json({ phone: message.body.phone, message: message.body.message }); console.log('inicial ' + Object); console.log('phone ' + message.body.phone); console.log('message ' + message.body.message); Object.end();
};
function final (Object, response, next) {
const phone = phoneNumberFormatter(Object.body.phone);
const message = Object.body.message;
console.log('invocation ' + (Object.body.phone));
client.sendMessage(phone, message).then(response => {
response.status(200).json({
status: true,
response: response
});
}).catch(err => {
res.json({
status: false,
response: err
});
});
console.log('reponse final ' + (response));
};
app.post('/api/send/8s8d9s9fs9', inicial, final); app.get('/api/send/8s8d9s9fs9', inicial, final);
Any help would help me to understand the callback, also thank you for your time