-
-
Save rickyrobinett/cb65bf7015c43dddafc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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