Created
February 23, 2016 09:59
-
-
Save axpence/cbd81deebc92fe40435f to your computer and use it in GitHub Desktop.
broadcastToSNS.js
This file contains hidden or 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
| function broadcastToSNS(event,stateMachineName,currentStateProperties,validTransition,cb){ | |
| //SNS for lambda chat | |
| var sns = new AWS.SNS(); | |
| var payload = event; | |
| if(event.broadcastEventType === BroadcastEventTypes.fromOutgoingMessage) { | |
| payload.channel = event.outGoingMessage.toNumber;//channel is partition key on dynamo for UI. | |
| payload.fromNumber = event.outGoingMessage.fromNumber; | |
| payload.toNumber = event.outGoingMessage.toNumber; | |
| payload.body = event.outGoingMessage.body; | |
| // payload.mediaUrl = event.outGoingMessage.image; | |
| } else if (event.broadcastEventType === BroadcastEventTypes.fromIncomingMessage) { | |
| payload.channel = event.fromNumber;//channel is partition key on dynamo for UI. | |
| } | |
| payload.StateMachineName = stateMachineName; | |
| payload.currentStateProperties = currentStateProperties; | |
| payload.validTransition = validTransition; | |
| //not in INITIAL_STATE, vcard input, search input, ![1,2,3] | |
| // var doesNotNeedResponseFromHuman = (validTransition !== null ;//|| currentStateProperties.stateName === "SEARCH_CONTACTS" || currentStateProperties.stateName === "ADD_MY_CONTACT_INFO" ); | |
| payload.needsResponseFromHuman = (validTransition === null); | |
| console.log('Sending SNS! -- payload=' + JSON.stringify(payload)); | |
| if(cb !== null) { | |
| sns.publish({ | |
| Message: JSON.stringify(payload),//64kb limit. | |
| TopicArn: 'arn:aws:sns:us-west-2:776491063347:lambda-chat'//TODO: change to proper ARN! | |
| }, cb); | |
| } else { | |
| sns.publish({ | |
| Message: JSON.stringify(payload),//64kb limit. | |
| TopicArn: 'arn:aws:sns:us-west-2:776491063347:lambda-chat'//TODO: change to proper ARN! | |
| }, function(err, data) { | |
| if (err) { | |
| console.log(err.stack); | |
| console.log('ERROR in sending SNS.'+err.stack); | |
| } else { | |
| console.log('SNS push sent'); | |
| console.log('respone data='+JSON.stringify(data)); | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment