I am using Amazon SNS Mobile Push Notifications both for android and ios. I am quite successful with sending push notification with text and icon only. Now i am trying to send the notification with an image bottom. I searched every where but couldn't find a perfect docs to work on. Any suggestions please.
i installed this package using npm , i used this to send push notification. please refer this link.
https://www.npmjs.com/package/sns-mobile
AWS_SNS_App.getUsers(function (err, allDevices) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
if (allDevices.length != 0) {
var totalDevices = 0;
for (var i = 0; i < allDevices.length; i++) {
totalDevices = totalDevices + 1;
AWS_SNS_App.sendMessage(allDevices[i].EndpointArn, message, function (err, messageId) {
if (err) {
console.log('An error occured sending message to device %s');
res.send(err);
} else {
//res.send('Successfully sent a message to device , MessageID was : ' + messageId);
}
});
}
if (totalDevices === allDevices.length) {
res.send('Successfully sent a message to all devices');
}
}
}
});
sendMessage(endpointArn, message, callback) Send a message to a user.
The message parameter can be a String, or an Object with the formats
below. The callback format is callback(err, messageId).
from docs it indicates to send a endpointArn,message and we will get a callback of any response. what i suppose to send an image along with the image, is that possible or any another way to do that.
thanks.
Every image-containing push notification sent could contain a mediaReference that the app can later use to obtain content from a web service or from the apps bundled resources.
In any media case, the final resource link / bundle-resource-ref. can be composed within the app, (example) depending on other parameters within the push.
Remember that if the resource is not bundled you will have to download the image before displaying the notification (using it)
So the solution is in the client-side...
Implement specific methods for each of your platforms (android & ios), perform the required operations (i repeat, different and specific to the platform) in order to display the push notification with the image.
NOTE :
Tell me if you need references for building platform specific notifications with images. (and if so, what min sdk version you are using for each)
Related
I'm using ibmmq module https://github.com/ibm-messaging/mq-mqi-nodejs
I need to get an xml message from a queue and than make an xsl-transformation.
I put messages to the queue with JMeter and if I browse messages in rfhutil I can see them as is on the Data tab.
But when I get it in the code
function getCB(err, hObj, gmo,md,buf, hConn ) {
// If there is an error, prepare to exit by setting the ok flag to false.
if (err) {...
} else {
if (md.Format=="MQSTR") {
console.log("message <%s>", decoder.write(buf));
} else {
console.log("binary message: " + buf);
}
}
I get my message with some service information:
buf=RFH �"�MQSTR � <mcd><Msd>jms_text</Msd></mcd> X<jms><Dst>queue://MY_QM/MY_QUEUE</Dst><Tms>1657791724648</Tms><Dlv>2</Dlv></jms> ...My_message...
How can I get only My message like I do in rfhutil?
I can get it with string methods, but it looks like crutches.
That message has the headers created by a JMS application. There are various ways of dealing with it. You can
Have the sending app disable sending that structure (setting the targClient property)
Use GMO options to ignore the properties (MQGMO_NO_PROPERTIES)
Have your application deal with the RFH2 stucture. See for example the amqsget.js sample in the Node.js repo which includes this fragment:
switch (format) {
case MQC.MQFMT_RF_HEADER_2:
hdr = mq.MQRFH2.getHeader(buf);
I'm trying to write a cloud function which sends a push notification to an iOS device. The logs say that sendToDevice was successful. But my device isn't receiving any notifications. Neither Xcode nor Cloud Functions are showing any errors. How can I diagnose this problem?
My cloud function takes a registration token from the realtime database. This token is saved to the database during the didRegisterForRemoteNotificationsWithDeviceToken function in the ios app, confirming that the front end is registering for remote notifications. The app has been given permission to show notifications and the push notification capabilities have been enabled in Xcode.
This block of code comes from my cloud function (Node.js):
// This snapshot was taken from the realtime database
// Xcode logs confirmed that this function is receiving the correct key
const notificationKey = userSnapshot.child("notificationKey").val();
const payload = {
notification: {
title: 'Test Notification Title',
body: 'Test Notification Body',
sound: 'default',
badge: '1'
}
};
return admin.messaging().sendToDevice(notificationKey, payload).then(function (response) {
console.log("Successfully sent message: ", JSON.stringify(response));
return;
}).catch(function (error) {
console.log("Error sending message: ", error);
return;
});
When calling the cloud function above, the logs showed this console log (Id numbers truncated):
"Successfully sent message: {"results":[{"messageId":"0:154/* ... */"}],"canonicalRegistrationTokenCount":0,"failureCount":0,"successCount":1,"multicastId":576/* ... */}"
But my test device (iPhone 7) hasn't received any notifications. My app has the following delegate functions (Swift 4):
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
print("Notification will present: \(notification.request.content.userInfo)")
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: #escaping () -> Void) {
print("Notification received: \(response.notification.request.content.userInfo)")
}
Neither print statement is appearing in Xcode's output. The only relevant print statements found are the ones I included in didRegisterForRemoteNotificationsWithDeviceToken. My APNs certificate is apparently still valid and has not expired.
The issue was simply that my podfile was missing:
pod 'Firebase/Messaging'
That allowed my didReceiveRemoteNotification to receive the notification payloads from Firebase cloud function. Then once I added UNUserNotificationCenter.current().delegate = self to the AppDelegate, the UNUserNotificationCenterDelegate functions worked as intended.
Strange how the missing pod didn't give me any compiler errors.
I am implementing a cisco spark bot , which is now known as Webex teams. I am able to send receive simple text message from user. Is there a way to send rich card to user from Bot? I could not find any helpful documentation.
Here is my code I use to interact with bot
var SparkBot = require("node-sparkbot");
var SparkAPIWrapper = require("node-sparkclient");
// Starts your Webhook with default configuration where the SPARK API access
token is read from the SPARK_TOKEN env variable
var bot = new SparkBot();
var spark = new SparkAPIWrapper(process.env.SPARK_TOKEN);
bot.onMessage(function (trigger, message) {
if (message.personEmail != "mytestbot#webex.bot")
spark.createMessage(message.roomId, "You said " + message.text, {
"markdown":
true }, function (err, message) {
if (err) {
console.log("WARNING: could not post message to room: " +
message.roomId);
return;
}
});
});
Rich cards may contain buttons , links, list , thumbnail etc..
This is not supported yet on the platform side. The best you have at the moment is you can use markdown to style messages.
We are using AWS SNS to send SMS messages. In testing, it works for all but one of our devs who isn't receiving messages, the logs show the following:
Invalid parameter: PhoneNumber Reason: +1207XXXXXXX is not valid to publish to
I left his area code in case it's relevant. Again, this is the only number we've had issues with, it's an iPhone. It works fine for all the other numbers we've tried. I can also successfully SMS that number via the AWS SNS Console without issue.
I should note, we're only sending a 6 character string (for 2 factor auth).
We're doing this from a Lambda. Here's the relevant portion of the code:
export function sendSNS(PhoneNumber, Message) {
return new Promise<boolean>((resolve, reject) => {
const sns = new AWS.SNS({ region: 'us-east-1' })
const params = {
MessageStructure: 'String',
Message,
PhoneNumber
}
sns.setSMSAttributes({
attributes: {
DefaultSenderID: 'mycompany',
DefaultSMSType: 'Transactional'
}
})
sns.publish(params, function(err, data) {
if (err) {
console.log(err)
reject(false)
} else {
console.log(`Sent this SMS via Amazon: ${Message} to ${PhoneNumber}`)
console.log(data)
resolve(true)
}
})
})
}
I was able to fix this by updating the user's phone number directly in our MySQL DB by hand. Not sure if it was a character encoding issue or similar, but am assuming it must've been. I'll post back if I determine the exact cause.
UPDATE:
This was definitely caused by an encoding issue, paste the code below into jsfiddle, and mouseover to see the warning on the first plus sign which reads:
This character may get silently deleted by one or more browsers
var x = '+1207XXXXXXX'
var y = '+1207XXXXXXX'
You can also try deleting/backspacing the + or 1 in the offending string (var x). Some weird results.
This data was initially entered into the MySQL DB via a GraphQL mutation from Prisma Playground using Chrome on Mac.
If I convert both strings above to hex to inspect, you can see they are indeed different:
2b31202c32303758585858585858 (bad)
2b3132303758585858585858 (good)
Also be aware that not all AWS regions support sending SMS's and you'll see this same error "InvalidParameter: Invalid parameter: PhoneNumber Reason: +614##### is not valid to publish" when sending messages to a region that doesn't support it (in my case us-west-1).
For a list of regions that do support sending SMS's, see the sns amazon docs on supported regions.
Credit to user RichPeaua in this comment of the AWS forums.
Please explain with one example as I am getting Error: 400 - The specified resource description is invalid.
Basically, I want to update badge value. But there is no template for badge registration in WnsService API document (http://azure.github.io/azure-sdk-for-node/azure-sb/latest/WnsService.html). So, I am trying with "createRawTemplateRegistration" template to update the badge value.
Please help me on this.
You can directly use the function sendBadge() to push badge value to client devices.
Please try the following code:
var azure = require('azure');
var notificationHubService = azure.createNotificationHubService('<hubname>', '<connectionstring>');
notificationHubService.wns.sendBadge(null,99,function(error,response){
if(error) console.log(error);
console.log(response);
})
Any further concern, please feel free to let me know.
update
Do you mean that you want only one template and to handle all the types of notifications including Raw, Toast, Badge? If so, I think the answer is negative. According the description http://azure.github.io/azure-sdk-for-node/azure-sb/latest/WnsService.html#createRawTemplateRegistration:
Remember that you have to specify the X-WNS-Type header
So the header option is required. And according the REST API which is invoked via this api in nodejs is Create Registration, and we can find the description:
The BodyTemplate element is mandatory, as is the X-WNS-Type header.
So we should specify the notification type for the template.
update1
This code sample works fine on my side:
var channel = '<devicetoken>';
var templateMessage = { text1: '$(message)' };
notificationHubService.wns.createRawTemplateRegistration(channel,'tag',JSON.stringify(templateMessage), {headers: { 'X-WNS-Type': 'wns/raw' }},
function (e, r) {
if (e) {
console.log(e);
} else {
console.log({
id: r.RegistrationId,
deviceToken: r.DeviceToken,
expires: r.ExpirationTime
});
}
}
)