I need to send SMS via Twilio and iāve tried 2 things so far. First I was hoping the NodeJS SDK would be allowed to require, but it appears that is isnāt considered a āwhitelistedā plugin (you might want to consider that.
Next Iāve tried to use the Moralis.Cloud.httpRequest and try and use the standard REST APIs from Twilio. This doesnāt seem to run. Here is my code. I canāt seem to get any logs to print so I feel as if itās not running, but i canāt figure out why.
Moralis.Cloud.define("test", async (request) => {
const web3 = Moralis.web3ByChain("0x3"); // Ropsten
const abi = Moralis.Web3.abis.erc20;
const address = "0x484f56061DFD2166754b572913C822E9BD19d513";
const contract = new web3.eth.Contract(abi, address);
const ethAddy = await request.user.get("ethAddress");
//Get balance of the user calling the functions
const balance = await contract.methods
.balanceOf(ethAddy)
.call();
//send SMS
//*******This code doesn't work ********
const accountSid = 'XXX';
const authToken = 'XXX';
Moralis.Cloud.httpRequest({
method: 'POST',
url: 'https://api.twilio.com/2010-04-01/Accounts/'+accountSid+'/Messages.json',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic XXX'
},
form: {
'Body': 'Yo yo',
'To': '+111',
'From': '+111'
}
}).then(function(httpResponse) {
console.log(httpResponse.text);
}, function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
});
//**************************************
return ethAddy +" "+balance;
});
BTW - as a side noteā¦the moralis-admin-cli wonāt work on my macOS. It seems to install but when I try to use it I get the error: command not found.