AWS Pinpoint. Mobile push notifications. Why сontent-available always sets to 1? - python-3.x

I am using boto3 and in some cases I need to send silent notifications. I can do it by setting "SilentPush": True. Example:
response = client.send_messages(
ApplicationId='string',
MessageRequest={
'Addresses': {
'string': {
'ChannelType': 'APNS'
}
},
'MessageConfiguration': {
'DefaultPushNotificationMessage': {
'SilentPush': True,
}
}
)
In this case on the device I get push notification with 'content-available': 1, that tells me this is silent notification. The problem is, if I change SilentPush to False, I still get 'content-available': 1. Even if I send notification through aws console, I get the same result.
Please help me.

Related

Getting message in ibmmq Node.js

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);

Dialogflow integration with Viber doesn't work with Rich Media type of message

I tried to use a custom payload to send the Carousel to the Viber client from my NODEJS fulfillment. It gives no response. Here is my code:
payload = new Payload(agent.VIBER, {
"type":"rich_media",
"rich_media":{
"Type":"rich_media",
"ButtonsGroupColumns":6,
"ButtonsGroupRows":7,
"BgColor":"#FFFFFF",
"Buttons":[
{
"Columns":6,
"Rows":3,
"ActionType":"open-url",
"ActionBody":"https://www.google.com",
"Image":"http://html-test:8080/myweb/guy/assets/imageRMsmall2.png"
},
{
"Columns":6,
"Rows":2,
"Text":"<font color=#323232><b>Headphones with Microphone, On-ear Wired earphones</b></font><font color=#777777><br>Sound Intone </font><font color=#6fc133>$17.99</font>",
"ActionType":"open-url",
"ActionBody":"https://www.google.com",
"TextSize":"medium",
"TextVAlign":"middle",
"TextHAlign":"left"
},
{
"Columns":6,
"Rows":1,
"ActionType":"reply",
"ActionBody":"https://www.google.com",
"Text":"<font color=#ffffff>Buy</font>",
"TextSize":"large",
"TextVAlign":"middle",
"TextHAlign":"middle",
"Image":"https://s14.postimg.org/4mmt4rw1t/Button.png"
},
{
"Columns":6,
"Rows":1,
"ActionType":"reply",
"ActionBody":"https://www.google.com",
"Text":"<font color=#8367db>MORE DETAILS</font>",
"TextSize":"small",
"TextVAlign":"middle",
"TextHAlign":"middle"
}
]
}
}, { sendAsMessage: true, rawPayload: false }
);
agent.add(payload);
The only workaround I found is to use a direct API call to Viber Messaging API from my Fulfillment. It explained well here: https://www.npmjs.com/package/messaging-api-viber
It seems it is a limitation of the Dialogflow at this moment. Just use workaround: a direct API call to Viber Messaging API from my Fulfillment. It explained well here: https://www.npmjs.com/package/messaging-api-viber

AWS SNS - Invalid Parameter - Phone Number is not valid to publish to. On specific phone number only

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: +1‬207XXXXXXX 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 = '+1‬207XXXXXXX'
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.

SNS Push Notifications with image using Node.js?

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)

Send RAW Azure Push Message

I'm trying to send a raw push notification message from Azure to my mobile device through an Web API. Previously I made use of a toast message and I got that working just fine, but not so much with the raw message type. This is what I've tried so far in my web API, without any success:
var jObject = new JObject
{
{
"Body", pushMessage.Body
},
{
"From", pushMessage.From
},
{
"Date", DateTime.Now.ToString(CultureInfo.InvariantCulture)
},
{
"Title", pushMessage.Title
},
{
"TargetType", pushMessage.TargetType.ToString()
}
};
Notification notification = new WindowsNotification(jObject.ToString());
notification.Headers.Add("X-WNS-Type", "wns/raw");
notification.ContentType = "application/json";
var task = Notifications.Instance.Hub.SendNotificationAsync(notification, "some tag value");
The above code never pushes the actual message. Could someone please provide me with some information regarding this. I've tried various methods described on the web, without any success.
Many thanks!
Turns out the above code works just fine - there was an issue with one of the settings in Azure ... pretty stupid mistake in the end o_O

Resources