Skip to content

Instantly share code, notes, and snippets.

@rickyrobinett
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickyrobinett/cb65bf7015c43dddafc4 to your computer and use it in GitHub Desktop.
Save rickyrobinett/cb65bf7015c43dddafc4 to your computer and use it in GitHub Desktop.
var stellarAddress = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var WebSocket = require('ws');
var ws = new WebSocket('ws://live.stellar.org:9001');
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY';
var client = require('twilio')(accountSid, authToken);
ws.on('open', function() {
var msg = {
command: 'subscribe',
accounts: [ stellarAddress ]
};
ws.send( JSON.stringify( msg ), function( err ) {
console.error( err );
});
});
ws.on('message', function(data, flags) {
var msg = JSON.parse(data);
console.log( msg )
if(
msg.engine_result_code === 0 &&
msg.type === 'transaction' &&
msg.transaction.Destination === stellarAddress
) {
client.sendMessage({
to:'+15555555555', // Your phone number
from: '+15551234567', // Your Twilio number
body: 'You received ' + msg.transaction.Amount/1000000 + ' STR' // body of the SMS message
}, function(err, responseData) {
if (!err) {
console.log(responseData.body);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment