Setting up FCM with SNS Using AWS Sdk - amazon-web-services

My backend is on Laravel and App is on Flutter
I have found this FCM WITH AWS
However my question is how to send GCM data showed by #Nathan using AWS Sdk/Api
{
"GCM": "{ \"notification\": { \"title\": \"test title\", \"body\": \"test body\" } }"
}
My message is delivering to my app however I can't set few variables such as
contentAvailable
Also not sure how to send sound type.
Thanks for the help

I have managed to make it work even it's partially for now.
This works for me
$GCM = json_encode(json_encode([
"notification" => [
"content_available" => true,
"body" => "Don't forget to put your fogo bin outside",
"title" => "Hello"
],
]), JSON_UNESCAPED_SLASHES);
$message = '{ "default": "test", "GCM":' . $GCM . ' }';
I have not managed to set contentAvailable and not sure how to send sound in there but getting there so if anyone can help me with remaining tasks will be highly appreciated :)

Related

How can I play a WebRTC livestream from flutter?

my use case is a webrtc livestream is coming from AWS Kinesis, that I want to play in flutter app. I am new to WebRTC and AWS. And for flutter_webrtc lib, there is no proper documentation available.
Here is my sample response which comes from live video API (hiding few details in response):
{
"status": true,
"data": {
"shadowState": "Device Shadow updated successful!",
"channelARN": "arn:aws:kinesisvideo:us-west-2:",
"region": "us-west-2",
"clientId": "clientId",
"signalingChannelEndpoint": "wss://v-123.kinesisvideo.us-west-2.amazonaws.com",
"signedEndpointUrl": "wss://v-123.kinesisvideo.us-west-2.amazonaws.com/?...&X-Amz-SignedHeaders=host",
"iceServers": [
{
"urls": "stun:stun.kinesisvideo.us-west-2.amazonaws.com:443"
},
{
"urls": [
"turn:12-34-567-890.t-123.kinesisvideo.us-west-2.amazonaws.com:443?transport=udp",
"turns:12-34-567-890.t-123.kinesisvideo.us-west-2.amazonaws.com:443?transport=udp",
"turns:12-34-567-890.t-123.kinesisvideo.us-west-2.amazonaws.com:443?transport=tcp"
],
"username": "1....2:djE....UxODc1",
"credential": "2eg..NOc/1c..."
}
]
}
}
And there is no official lib from AWS for this, so I tried to use this lib aws_kinesis_video_signaling_api but again no proper documentation is there. Anyone please help me understand these things. Thank you
The flutter_webrtc takes in a configuration map something similar to the one mentioned.
Map<String, dynamic> configuration = {
"iceServers": [
{"url": "stun:stun.l.google.com:19302"},
]
};
You can add some offerSdpConstraints and pass this configuration to
RTCPeerConnection pc =
await createPeerConnection(configuration, offerSdpConstraints);
to connect to a remote peer. The documentation isn't very helpful but if you're looking for a guide on Flutter x WebRTC, I've written an article on Flutter and WebRTC integration on the 100ms blog.

AWS SES SendBulkTemplatedEmailResponse for tracking email statues

I am referring to .net SDK here but I believe class level concepts are all same.
This is for sending bulk emails using templates (https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html)
https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SimpleEmail/TSendBulkTemplatedEmailResponse.html
SendBulkTemplatedEmailResponse response = client.SendBulkTemplatedEmailAsync(sendBulkTemplatedEmailRequest).Result
SendBulkTemplatedEmailRequest has more than one email addresses and SendBulkTemplatedEmailResponse is returned with individual status for each email as List<BulkEmailDestinationStatus> (https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SimpleEmail/TBulkEmailDestinationStatus.html).
Each BulkEmailDestinationStatus has MessageId and Status (some predefined constants). But not having the email-address for which the status is returned (obviously there are more than one recipients so there are individual status for each recipient.)
With that said, how to figure out mapping from email-address to MessageId or vice-versa?
I am getting confused about what is the use of messageId in BulkEmailDestinationStatus where there is not any associated recipient email-address. Am I missing something very basic here?
While I didn't find any resources on this, I'll just leave what I gathered testing this feature, for anyone else that may find this question.
The order of the emails sent (ie. the order of the emails in the Destinations property) is the order of the returned messageIds.
So, using the docs json sample:
{
"Source":"Mary Major <mary.major#example.com>",
"Template":"MyTemplate",
"ConfigurationSetName": "ConfigSet",
"Destinations":[
{
"Destination":{
"ToAddresses":[
"anaya.iyengar#example.com"
]
},
"ReplacementTemplateData":"{ \"name\":\"Anaya\", \"favoriteanimal\":\"angelfish\" }"
},
{
"Destination":{
"ToAddresses":[
"liu.jie#example.com"
]
},
"ReplacementTemplateData":"{ \"name\":\"Liu\", \"favoriteanimal\":\"lion\" }"
},
{
"Destination":{
"ToAddresses":[
"shirley.rodriguez#example.com"
]
},
"ReplacementTemplateData":"{ \"name\":\"Shirley\", \"favoriteanimal\":\"shark\" }"
},
{
"Destination":{
"ToAddresses":[
"richard.roe#example.com"
]
},
"ReplacementTemplateData":"{}"
}
],
"DefaultTemplateData":"{ \"name\":\"friend\", \"favoriteanimal\":\"unknown\" }"
}
The object sent would be a
(SendBulkTemplatedEmailRequest) request with the following list:
request.Destinations[0].ToAddresses = {"anaya.iyengar#example.com"}
request.Destinations[1].ToAddresses = {"liu.jie#example.com"}
request.Destinations[2].ToAddresses = {"shirley.rodriguez#example.com"}
request.Destinations[3].ToAddresses = {"richard.roe#example.com"}
And the (SendBulkTemplatedEmailResponse) response would have this list:
response.Status[0].MessageId = "0000000000000000-11111111-2222-3333-4444-111111111111-000000"
response.Status[1].MessageId = "0000000000000000-11111111-2222-3333-4444-222222222222-000000"
response.Status[2].MessageId = "0000000000000000-11111111-2222-3333-4444-333333333333-000000"
response.Status[3].MessageId = "0000000000000000-11111111-2222-3333-4444-444444444444-000000"
Where:
the MessageId "0000000000000000-11111111-2222-3333-4444-111111111111-000000" refers to the email sent to anaya.iyengar#example.com;
the MessageId
"0000000000000000-11111111-2222-3333-4444-222222222222-000000"
refers to to the email sent to "liu.jie#example.com";
and so on.

AWS PinPoint - SMS Message From Postman

I'm trying to initiate a SMS message using Postman, but I keep getting a response indicating "Invalid Request Body". I can't seem to find a good example on the AWS documentation (Is it just me or does anyone else encounter this with AWS?)
Below is the request body I'm submitting with my request. Any help would be much appreciated!
{
"ApplicationId": "<MyApplicationID>",
"MessageRequest": {
"Addresses": {
"[{{Destination}}]": {
"BodyOverride": "Test",
"ChannelType": "SMS"
}
},
"MessageConfiguration": {
"SMSMessage": {
"Body": "Test",
"SenderId": "Test",
"MessageType": "TRANSACTIONAL",
"Keyword": "<MyKeyword>",
"OriginationNumber": "<Origination number in E.164 Format>"
}
}
}
}
Looking at the Amazon Pinpoint SendMessages REST API, the request body doesn't include either the application-id key or MessageRequest key.
Resolution:
You will need to put the Amazon Pinpoint application-id in the URI part (or create an environmental variable) and then specify the request body as shown below :
Hope this helps!

how to get aws sms delivery report programmatically?

I am using AWS SNS to send SMS to mobile.
I can see S3 Delivery Status upload on S3 Option is there. But for that, I have to run batch daily. The report will almost delayed.
The Second Option I can see on Cloudwatch.
Is it possible from cloudwatch we can publish SQS event with logs detail So that I can write SQS subscriber to fetch the message delivery status? or if any other option available which I have not explored so far please let me know.
I am using Java and aws-java-sdk to fetch detail.
Please Note I have gone through the document but unable to find something useful.
Any Suggestion is welcome.
Please I have gone through document but unable to find
To get SMS delivery status you have to do the following
Enable 'Delivery status logging' to AWS Cloudwatch More Info
set permission for the user (used in script) to access the AWS Cloudwatch log
Read the log entry from cloudwatch with awssdk.
See the below PHP code which I am using in my project, you can refer this to a create java code
require 'inc/awsSdkForPhp/aws-autoloader.php';
$params = array(
'credentials' => array(
'key' => '<YOUR KEY>',
'secret' => '<YOUR SECRET>',
),
'region' => 'us-east-1', // your aws from SNS region
'version' => 'latest'
);
$cwClient = new \Aws\CloudWatchLogs\CloudWatchLogsClient($params);
$queryRes = $cwClient->startQuery([
'endTime' => 1621231180, // UNIX TIMESTAMP
'logGroupName' => 'sns/us-east-1/***/DirectPublishToPhoneNumber', // YOUR LOG GROUP NAME
'queryString' => 'fields #timestamp, status, #message
| filter notification.messageId="5a419afc-c4b3-55b3-85f9-c3e7676b2dd2"', // YOUR MESSAGE ID
'startTime' => 1620954551 // START UNIX TIMESTAMP
]);
$qryID = $queryRes->get('queryId');
sleep(3); // To wait the execution to be completed.
$resultObj = $cwClient->getQueryResults(array(
'queryId' => $qryID, // REQUIRED
));
//echo "<pre>";print_r($resultObj);echo "</pre>";
$result = $resultObj->get('results');
$jsnRs = json_decode($result[0][2]['value']); // TO get the delivery array
echo "<br>status :".$jsnRs->status;
echo "<br>phone Carrier :".$jsnRs->delivery->phoneCarrier;
echo "<br>provider Response :".$jsnRs->delivery->providerResponse;
echo "<pre>";print_r($jsnRs);echo "</pre>";
I believe it will help someone
we can use lamda to readlogs from awscloudwatch by watch awscloudwatch events.

AWS Pinpoint/Ionic - "Resource not found" error when trying to send push through CLI

I am new at programming with AWS services, so some fundamental things are pretty hard for me. Recently, I was asked to develop an app that used Amazon Pinpoint to send push notifications, as a test for considering future implementations.
As you can see in another question I posted in here (Amazon Pinpoint and Ionic - Push notifications not working when app is in background), I was having trouble trying to send push notifications to users when my app is running in the background. The app was developed using Ionic by following these steps.
When I was almost giving up, I decided to try sending the pushes directly through Firebase, and it finally worked. Some research took me to this question, in which another user described the problem as only happening in AWS Console, so the solution would be to use CLI. After searching a little about it, I found this tutorial about how to sending pinpoint messages to users using CLI, that seems to be what I wanted. Combining it with this documentation about phonegap plugin, I was able to generate a JSON I thought could be a solution:
{
"ApplicationId":"io.ionic.starter",
"MessageRequest":{
"Addresses": {
"": {
"BodyOverride": "",
"ChannelType": "GCM",
"Context": {
"": ""
},
"RawContent": "",
"Substitutions": {},
"TitleOverride": ""
}
},
"Context": {
"": ""
},
"Endpoints": {"us-east-1": {
"BodyOverride": "",
"Context": {},
"RawContent": "",
"Substitutions": {},
"TitleOverride": ""
}
},
"MessageConfiguration": {
"GCMMessage": {
"Action": "OPEN_APP",
"Body": "string",
"CollapseKey": "",
"Data": {
"": ""
},
"IconReference": "",
"ImageIconUrl": "",
"ImageUrl": "",
"Priority": "High",
"RawContent": "{\"data\":{\"title\":\"sometitle\",\"body\":\"somebody\",\"url\":\"insertyourlinkhere.com\"}}",
"RestrictedPackageName": "",
"SilentPush": false,
"SmallImageIconUrl": "",
"Sound": "string",
"Substitutions": {},
"TimeToLive": 123,
"Title": "",
"Url": ""
}
}
}
}
But when I executed it in cmd with aws pinpoint send-messages --color on --region us-east-1 --cli-input-json file://test.json, I got the response An error occurred (NotFoundException) when calling the SendMessages operation: Resource not found.
I believe I didn't write the JSON file correctly, since it's my first time doing this. So please, if any of you know what I am doing wrong, no mattering which step I misunderstood, I would appreciate the help!
"Endpoints" field in the Message request deals with the endpoint id (the identifier associated with an end user device while registering to pinpoint and not the region.)
In case if you haven't registered any endpoints with Pinpoint, you can use the "Addresses" field. After registering the GCM Channel in Amazon Pinpoint, you can get the GCM device token from your device and specify it here.
Here is a sample for sending direct messages using Amazon Pinpoint Note: The example deals with sending SMS message. You should have registered a SMS channel first and created an endpoint with the endpoint id as "test-endpoint1". Otherwise, you can use the "Addresses" field instead of "Endpoints" field.
aws pinpoint send-messages --application-id $APP_ID --message-request '{"MessageConfiguration": {"SMSMessage":{"Body":"hi hello"}},"Endpoints": {"test-endpoint1": {}}}
Also Note: ApplicationId is generated by Pinpoint. When you visit the Pinpoint console and choose your application, the URL will be of the format
https://console.aws.amazon.com/pinpoint/home/?region=us-east-1#/apps/someverybigstringhere/
Here "someverybigstringhere" is the ApplicationId and not the name you give for your project.