I am attempting to send a raw notification to WNS by setting message attributes, but it appears that a toast notification is being sent instead.
Here is the C# code I'm using to build the publish request.
var request = new PublishRequest()
{
TopicArn = TOPIC_ARN,
Message = "Test Message",
MessageAttributes = new Dictionary<string, MessageAttributeValue>()
{
{ "AWS.SNS.MOBILE.WNS.Type", new MessageAttributeValue() { StringValue = "wns/raw", DataType = "String" } }
}
};
From what I can tell, I am setting the X-WNS-Type correctly using SNS
Message Attributes, but the notification is still received as a toast on the client. Are there any examples of somebody doing this successfully?
I was able to get it working by using MessageStructure. Setting the value to json and updating Message to have a message specifically for WNS did the trick. My assumption is that the WNS value for MessageAttributes only applies if a message is defined specifically for WNS.
var request = new PublishRequest()
{
TopicArn = TOPIC_ARN,
Message = "{ \"default\": \"default message\", \"WNS\" : \"raw message\"}",
MessageAttributes = new Dictionary<string, MessageAttributeValue>()
{
{ "AWS.SNS.MOBILE.WNS.Type", new MessageAttributeValue() { StringValue = "wns/raw", DataType = "String" } }
},
MessageStructure = "json",
};
Related
I'm trying to use the SendGrid API to create and schedule a Single Send email to a contact list when my Azure Functions endpoint is called. Here is the minimum amount of information that I can create the single send with and have it work with a 200 response.
private static SendGridClient _client = new SendGridClient(
Environment.GetEnvironmentVariable("SendGridApiKey")
);
...
var data = new {
name = "Title",
send_to = new {
list_ids = new [] {
$"{Environment.GetEnvironmentVariable("SendGridMailingId")}",
}
},
email_config = new {
design_id = $"{Environment.GetEnvironmentVariable("SendGridDesignId")}",
}
};
var singleSendResp = await _client.RequestAsync(
method: SendGridClient.Method.POST,
urlPath: "marketing/singlesends",
requestBody: JsonConvert.SerializeObject(data)
);
return singleSendResp;
The problem is that I'd like to include the send_at: "now", suppression_group_id, and sender_id, but if I include any of them (as well as all of them), I get this response:
{
"errors": [
{
"field": "",
"message": "json could not be unmarshalled"
}
]
}
I've tried all combinations of the above, and have even tried including all the properties that can't be null (minus the subject, html_content, etc since I have design_id.
I'm using the 9.28.1 SendGrid NuGet package, which should correspond to SendGrid's v3 API. I'm doing my testing locally with Postman. I am using the free version of the API, if that matters.
Any help would be appreciated. Thank you!
EDIT: Here would be my ideal object to send, with extra fields.
var data = new {
name = "Title",
send_at = "now",
send_to = new {
list_ids = new [] {
Environment.GetEnvironmentVariable("SendGridMailingId")
}
},
email_config = new {
design_id = Environment.GetEnvironmentVariable("SendGridDesignId"),
sender_id = Environment.GetEnvironmentVariable("SendGridSenderId"),
suppression_group_id = Environment.GetEnvironmentVariable("SendGridSuppressionId")
}
};
I finally figured out the issue, and it's a dumb mistake (as always). sender_id and suppression_group_id are supposed to be integers, but I was just sending the string. Wrapping the values in an int.Parse() works.
Also, even though send_at is supposed to be allowed a value of "now", it only works with the date string. For this, I included the following to format the string
string scheduleDate = DateTime.Now
.ToUniversalTime()
.AddMinutes(5)
.ToString("yyyy-MM-ddTHH:mm:ssZ");
I seem to be unable to access the SingleValueExtendedProperties set in my MVC App using the Microsoft Graph API from the recipient account.. When checking the same message in either the senders Sent Items or sending the same message to myself, it all works fine?
The SingleValueExtendedProperties just appear null when trying to access a message sent from an account that differs from the recipient, the exact same code is used for both situations, and the GUID the properties are assigned with is identical.
Here is my generation of the message:
Message newMessage = new Message()
{
ToRecipients = new List<Recipient>()
{
new Recipient() { EmailAddress = recipient }
},
Subject = message.Subject,
Body = new ItemBody()
{
Content = message.Content
},
SingleValueExtendedProperties = new MessageSingleValueExtendedPropertiesCollectionPage()
{
new SingleValueLegacyExtendedProperty()
{
Id = String.Format("String {{{0}}} Name {1}", guid, "ValueOne"),
Value = prop1
},
new SingleValueLegacyExtendedProperty()
{
Id = String.Format("String {{{0}}} Name {1}", guid, "ValueTwo"),
Value = prop2
}
}
};
And here is my send request:
await client.Me.SendMail(newMessage, true).Request().PostAsync();
And my get request:
var message = await client.Me.Messages[messageId].Request()
.Expand("singleValueExtendedProperties(
$filter=id eq 'String {guid} Name ValueOne' or id eq 'String {guid} Name ValueTwo')")
.GetAsync();
As I said, this all works flawlessly when sending mail to the same account as the sender, or reading the message from the senders Sent Items, but when receiving from a different account to the sender, the singleValueExtendedProperties are always null!
I am currently working on web push notifications and am at the last stage of using the web push libraries to send the notification.
I am using the C# web push library here. However, I do not see a notification when on the page or when not on it.
I am attaching my code below:
I wrote the code in my store subscription method so it could be one of the issues.
[HttpPost]
public void StoreSubscription(string [] publicKey, string [] auth, string notificationEndPoint )
{
var pushEndpoint = notificationEndPoint;
var pushAuth = auth[0].ToString();
var pushP256DH = publicKey[0].ToString();
var subject = "mailTo:hhhhhhh#gmail.com";
var uPublicKey = "yyzzxx";
var privateKey = "xxyyzz";
System.IO.File.WriteAllText(#"\Desktop\Subscription.txt", pushEndpoint);
var subscription = new PushSubscription(pushEndpoint, pushP256DH, pushAuth);
var gcmAPIKey = "AAAA";
var vapidDetails = new VapidDetails(subject, uPublicKey, privateKey);
var webPushClient = new WebPushClient();
try
{
webPushClient.SetGCMAPIKey(gcmAPIKey);
webPushClient.SendNotification(subscription, "payload", gcmAPIKey);
}
catch (WebPushException exception)
{
Console.WriteLine("HTTP status Code:" + exception.StatusCode);
}
}
And my service worker code is as follows for handling the push:
self.addEventListener('push', function (event) {
debugger
var body;
if (event.data) {
body = event.data.text();
} else {
body = 'Push message no payload';
}
var options = {
body: body,/*'This message was generated from a push'*/
icon: '/Images/noun_Pushing_1823359.png',
vibrate: [100, 200, 100, 200, 400],
data: {
dateOfArrival: Date.now(),
primaryKey: '2'
},
actions: [
{
action: 'explore', title: 'Explore this new world',
icon: '/Images/noun_Check Mark_4870.png'
},
{
action: 'close', title: 'Close',
icon: '/Images/noun_Close_887590.png'
},
]
};
event.waitUntil(
self.registration.showNotification('Push Notification', options)
);
});
I have been stuck on this for almost a long time now and very new to promise, service worker and push and notification apis.
the function is getting hit and does not throw any exception. Also, when i put a debugger in the service worker, it does not get hit so apparently the push is not getting handles.I might be completely wrong on this.
I had the same issue. I base 64 encoded my auth and p256dh used to create the subscription.
If there is no exception it could mean the JSON payload is valid JSON but in the wrong format for the service worker. I Changed my payload to a valid JSON object for my service worker (Angular):
{ "notification": {"title": "message title", "body": "message body"} }
Please see docs... https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification
Sent notification and hit the service worker.
I was using Vapid Details not GCMApiKey.
I am trying to send to mobile devices a remote notification through Amazon SNS. I got a database which i store the JSON (payload) which needs to be given to PublishRequest of the SNS. I serialise the json in code and pass it to the request.
The issue is that SNS fails with an error: "MESSAGE STRUCTURE - JSON MESSAGE BODY FAILED TO PARSE"
As a requirement, the service (which is responsible to communicate with SNS and send the notification) has to retrieve from DB (MySQL) the json.
What I am missing?
The database is MySQL and the service is written in .Net Core
string messageFromDb = JsonConvert.SerializeObject(input.Payload);
var request = new PublishRequest
{
TargetArn = endpoint.EndpointArn,
MessageStructure = "json",
Message = messageFromDb
};
PublishResponse publishResponse = await _client.PublishAsync(request);
JSON from DB:
{"APNS": {"aps": {"alert": "Check out the new!", "sound": "default"}, "category": {"type": "sports"}}}
I tried also this without any luck:
{"default": "something", "APNS": {"aps": {"alert": "Check out the new games!", "sound": "default"}, "game": {"type": "Xbox"}}}
Finally I figured it out, maybe this answer will help someone. The JSON in the DB should be
{"aps": {"alert": "Check out the new!", "sound": "default"}, "category": {"type": "sports"}}
The .Net code should be:
AWSRoot obj = new AWSRoot(input.Payload);
var request = new PublishRequest
{
TargetArn = endpoint.EndpointArn,
MessageStructure = "json",
Message = JsonConvert.SerializeObject(obj)
};
PublishResponse publishResponse = await _client.PublishAsync(request);
AWSRoot is the root object that we create for SNS
public class AWSRoot
{
public string APNS { get; set; }
public AWSRoot(string payload)
{
APNS = payload;
}
}
I want to send a carousel of images with buttons from my bot on Facebook Messenger.
How do I set the ContentUrl and ContentType of Attachments generated by a Form in the Microsoft Bot Framework?
I can do this manually when creating a Message object:
C# Code, JSON Response and Messenger
var reply = message.CreateReplyMessage();
reply.Attachments = new List<Attachment>();
var actions = new List<Microsoft.Bot.Connector.Action>();
actions.Add(new Microsoft.Bot.Connector.Action
{
Title = "Small",
Image = #"https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png",
Message = "Small"
});
actions.Add(new Microsoft.Bot.Connector.Action
{
Title = "Large",
Image = #"https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png",
Message = "Large"
});
reply.Attachments.Add(new Attachment
{
Title = "Flat White",
Actions = actions,
ContentUrl = #"http://imgur.com/XbCCntC.png",
ContentType = "image/png"
});
But I don’t know how to do it when using a Form. I can use the DescribeAttribute to set the Image URL of an Action, which shows up in the JSON response.
But that doesn’t do/display anything, and I think the image needs to be a part of the Attachment object not the Action anyway.
Partial C# Code, JSON Response and Messenger
public enum WhiteStyle
{
Invalid = 0,
[Describe(Image = #"http://imgur.com/XbCCntC.png")]
FlatWhite,
[Describe(Image = #"http://imgur.com/qbbi6yc.png")]
Latte,
[Describe(Image = #"http://imgur.com/sF95Vsc.png")]
Cappuccino
}