Message to push to SNS
{
"types":["MAIL_REQUEST", "WS_REQUEST"],
"broadcast": true,
"users":[{"userId": 123, "fields": "value"}],
"room": "roomid_hashed",
"websocketData": {
"action":"PUBLICATION_REQUESTED",
"value": "data"
},
"emailData":{
"body": "<body></body>",
"subject": "Email subject"
}
}
Types:
-
MAIL_REQUEST: this will queue the message for being sent using SMTP, if MAIL_REQUEST is listed
emailData
is required and should contain the html body -
WS_REQUEST: using this label, you cand send the notification to the users involven in the notification if there are any connected in the service. if WS_REQUEST is listed,
websocketData
is required and this is the payload sent to clients.
Flags
users
: should be an array with the user information, theuserId
will be required for delivering the message to user if it's connectedroom
: if no user is sent, the service will deriver the message for everyone connected in the room sent.Note: the user should be registered before to this room
broadcast
: this will delivery the message to all the users connected.
- Connect client to WebSockets using the ApiGateway URL
- send the register event
{"action": "register", "data": {"userId": 123, roomId: "123" }}
userId
is required to sent furter notificationsroomId
will be useful to relate the user with a view or shared room- Note:
userId
&roomId
are managed by you
- once the client is registered you can sent notifications to SNS topic (building)
- Mail notifications is not current available. Only works for Websockets notification
$ npm i -g serverless aws-cli
$ aws configure
$ serverless deploy --stage prod
const AWS = require('aws-sdk')
AWS.config.update({
region: AWS_REGION
});
const SNSInstance = new AWS.SNS({
apiVersion: '2010-03-31',
accessKeyId: AWS_KEY,
secretAccessKey: AWS_SECRET_KEY,
})
const message_notification = {
users: [{userId: 123}],
websocketData: {
type: "NEW_COMMENT",
comment: {
id: 'x72n9c3j90xm',
body: 'this is a new comment',
}
}
}
const params = {
Message: JSON.stringify(message_notification),
TopicArn: AWS_ARN_TOPIC_ARN,
MessageAttributes: {
'types': {
DataType: 'String',
StringValue: 'WS_REQUEST'
},
}
}
const result = await SNSInstance.publish(params).promise()