Hello everyone, everything good?
I’m starting with Parse Server. It already contributes with improvements and I’m now deepening my knowledge with Cloud Functions.
I need to perform the following rule in Cloud Function.
The function should check who is authenticated and request an external api for sending SMS.
Can you help me please?
Parse.Cloud.define('sendsms', function(request, response){
/*
Check and identified user
if(user != authenticated)
return 'Aunauthorized';
*/
var pin = Math.floor(Math.random() * (99999 - 10000)) + 10000;
/*
Save class for before verification
const object = new Parse.Object('pinvalues');
object.set('pin', pin);
const token = { sessionToken: user.getSessionToken() };
await object.save(null, token);
*/
/// THIS USE EXTERNAL SERVICE TO SEND SMS
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://externalservicesms.com',
headers: {
'Authorization': 'Bearer mysecrettoken',
'Content-Type': 'application/json',
},
body: {
from: '+19072000010',
to: ['19072120721'],
body: 'This is your confirmed code ' + pin,
}
}).then(function(httpResponse) {
return 'success';
}, function(httpResponse) {
return 'Request failed with response code ' + httpResponse.status;
});
});