-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support to others protocols than application
for subscriptions (eg email
or sms
)
#30
base: master
Are you sure you want to change the base?
Conversation
… (eg `email`or `sms`)
Hi @claustres looks good, and more importantly - no breaking changes 👍 One thing I'm not sure about is how this fits with the goal of this module. For example, if a user uses This assumes we are sending to |
Well I already tested it by sending a message to a topic where SMS subscriptions have occurred. In this specific case the endpoint you provide when subscribing the user is the phone number instead of the ARN. I used the default message format with a top-level If you already send platform specific data in the message your functions let it untouched so fine. Otherwise I am not sure that what you do is necessary if you set a default root key because you simply repeat the same thing in each specific platform entry. These entries should be used to insert additional options such as However we probably need to perform more testing. Indeed I strongly believe your module could at least support SMS because it is mobile-oriented. I agree email or lambda is more farther than the initial objective of your module but the nice thing with AWS SNS is that it unifies all protocols under almost the same API. Let me know what you think. Regards |
That's interesting. So it "just worked". Here's how I think it worked - I just read the code for each conversion function in this module and can see that if you set the
or
I'm not sure I understand this. Do you mean the formatting is no longer necessary, and that passing
Agreed. I think the correct solution here might be to update What do you think? |
Yes you are right I only use android for now. According to this the specific message payload is only used if the default one is missing so it does not seem to be mandatory except for additional attributes. Not sure about sms as a new platform, this might be confusing with aws sdk where it is a protocol. Or we should replace 'platform' by 'protocol' and create a 'push' protocol. It could manage all the underlying platforms specified at creation. I did a code like this on top of yours because you usually want to target all platforms. |
You were right, due to my specific app flow I did not realize I could not send simultaneously SMS + Push on Android. To do so the message has to be structured like this to target simultaneously different protocols: {
"default": "message",
"email": "message",
"sms": "message",
"APNS": "{\"aps\":{\"alert\": \"message\"} }",
"APNS_SANDBOX":"{\"aps\":{\"alert\":\"message\"}}",
"GCM": "{ \"data\": { \"message\": \"message\" } }",
"ADM": "{ \"data\": { \"message\": \"message\" } }"
} So this work with my change as far as you give this message structure. Otherwise I would suggest that your converter function merge the input message when adding a To manage SMS attributes we should only expose a specific function calling AWS SDK's one just like you do for endpoints here. Another great benefit your module can offer is also a promise-based API that is not availalbe through the Amazon SDK. |
@claustres I was actually planning to update it for Promises and some TypeScript definitions very soon. No ETA though - too busy sometimes 😄 For my specific use case I never had the need to send many formats in one payload, but I see the use case and AWS even discuss here 👍
This is nice and convenient, but it can add some inefficiency due to the larger payloads. I think maybe in a future version we could have something like this: const SNS = require('sns-mobile')
const sender = new SNS.Sender({
// default protocols to include
protocols: [SNS.protocols.GCM]
})
const msg = {
// override defaults so we send to sms AND google (known as FCM now)
protocols: [SNS.protocols.SMS, SNS.protocols.GCM]
message: 'Hi there!'
}
sender.sendMessage(targetArn, msg)
.then((response) => console.log('success', response))
.catch((e) => console.log('darn, something went wrong', e)) |
Does not break API because a new
subscribeWithProtocol
method has been added but is called internally bysubscribe
with the defaultapplication
protocol.