I'm using Microsoft.Azure.NotificationHubs SDK v1.0.8 to integrate with the azure notification hub and send pushes. While iOS and Android work just fine, my Windows Phone pushes stop working some time ago. There the payload I use:
<?xml version="1.0" encoding="utf-8"?>
<wp:Notification xmlns:wp="WPNotification">
<wp:Toast>
<wp:Text1>Notification Title</wp:Text1>
<wp:Text2>Notification Text!</wp:Text2>
<wp:Param>?param1=value1¶m2=value2</wp:Param>
</wp:Toast>
</wp:Notification>
And here is the error I'm getting:
System.ArgumentException: The payload is not in accepted XML format.
The first node should be Tile/Toast. If want to send raw notification,
please set "X-NotificationClass" to "3" in header. at
Microsoft.Azure.NotificationHubs.RegistrationSDKHelper.DetectMpnsTemplateRegistationType(String
body, String errorMsg)
I tried to send the push directly from the azure portal or visual studio - it works fine. So the issue is somewhere in the SDK I guess.
This guide shows how to send the same notification using regular web request and special headers are set to send toast
sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
sendNotificationRequest.Headers.Add("X-NotificationClass", "2");
With the Azure SDK I have no way to setup these headers and can use only the following method to send my payload which gives me the error above:
await Hub.SendMpnsNativeNotificationAsync(payload, userIdTag);
What could be wrong in my setup here?
The issues was in this line
<wp:Param>?param1=value1¶m2=value2</wp:Param>
& value should be encoded so xml could be properly parsed by the Azure Notification Hub SDK, so I changed it to
<wp:Param>?param1=value1¶m2=value2</wp:Param>
Related
Following what's outlined here I've been able to so far read all registered devices, delete a device registration by id, and get a specific device registration by tag. What I want to do is register a device with a specific tag.
I found the page that specifies using this POST endpoint:
https://{namespace}.servicebus.windows.net/{NotificationHub}/registrations/?api-version=2015-01
I've applied the correct headers - Content Type, Authorization, and x-ms-version.
My question comes in the XML body that is getting sent. Where do I find the correct ChannelUri or is there something else in Azure / Firebase that I should be using in place of the channel uri?
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<WindowsRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag, myOtherTag</Tags>
<ChannelUri>{ChannelUri}</ChannelUri>
</WindowsRegistrationDescription>
</content>
Also, am I correct in thinking that the above api call will successfully register a device with the azure notification hub or am I missing a step somewhere?
The ChannelUri is a value that will be provided to you via UWP that allows you to target the particular Windows machine your application is running on (e.g.the example that you've provided above is WNS specific payload.)
Each Push Notification Service (PNS) has its own mechanism for uniquely identifying a device that should receive notifications. Other examples are included on the reference page you found, for instance you'll notice that Apple devices require a DeviceToken instead.
I'd like to leverage the new Google TTS using a simple rest request. To that end, I've created a Service Account which downloaded a JSON file containing a private key id, a private key, client email, client id, client_x509_cert_url, etc.
I've also set the environment variable for the system:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", jsonFile);
I then found this sample CURL request to use the WaveNet TTS engine provided by Google:
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
--data "{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1beta1/text:synthesize" > writtenfile.txt
I want to create a simple C# webrequest from the above CURL request, but the line "gcloud auth application-default print-access-token" is a problem for me. I cannot install a CLI gcloud instance on this machine. Isn't there some way to setup the webrequest authorization access token from the JSON service account file? Surely I don't HAVE to have gcloud installed.
Looking for code sample demonstrating how to convert CURL code to a C# rest request using the service account json file without gcloud.
In case you don't want to install the gcloud packages, you can execute REST calls by using API Keys. These keys can be created directly in the GCP console and they can be passed as a parameter through the request header; in this way, you can authenticate to the service without the need of gcloud. Additionally, I suggest you to take a look on this guide that contains the steps required to make REST requests with C#.
You can use this Restlet Client tool to test the following example:
REST content Example
Header
https://texttospeech.googleapis.com/v1beta1/text:synthesize?key=<YOUR_API_KEY>
Body
{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}
Finally, in case you want to consume a Service Account JSON file, you can use the Client libraries to create and send your TTS requests to then authenticate them directly from your code; however, this method require to install the TextToSpeech packages.
I have got a requirement,
When a work item is created (and status -say In progress) in TFS 2015(not vsts), I want my web hook to fire a post method which ll create a Channel in Slack, and invite few folks.
2) Once the Bug is closed - read all the history of channel and push the history back to Bug.
I was able to achieve the same with TFS server side plugin and it's working, but requirement got changed to Web hooks.
Could someone help me on how to achieve custom web hook.which ll enable events from TFS WI to Slack please?
Thanks,
You can not create new incoming webhooks in slack programmatically, but you can use any existing incoming webhook for a new channel.
Just add the channel property in your message to the webhook.
Example from the Slack documentation:
curl -X POST \
--data-urlencode 'payload={"text": "This is posted to #general and comes from *monkey-bot*.", "channel": "#general", "link_names": 1, "username": "monkey-bot", "icon_emoji": ":monkey_face:"}' \
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
So to implement your requirement I suggest you create a new channel and invite users as needed through the Slack web API. And then use an existing incoming webhook to send messages to that channel.
TFS has default slack service hook which can post a message to a channel. The API looks like below:
POST http://tfsserver:8080/tfs/DefaultCollection/_apis/hooks/subscriptions?api-version=3.2
Content-Type: application/json
{
"consumerActionId":"postMessageToChannel",
"consumerId":"slack",
"consumerInputs":{
"url":"https://hooks.slack.com/services/xxxxxx"},
"eventType":"workitem.created",
"publisherId":"tfs",
"publisherInputs":{
"areaPath":"",
"workItemType":"",
"projectId":"77e3c775-dc30-4354-xxxx-xxxxxxxxxxxx"}
}
For your second requirement, you need to check Slack Api to see how to read all the history of channel, and use Update work items to update Bug work items.
I've an android app and need to implement push notification on it, send and receive simple notifications.
My scenario; When userY submit form about userX will send userX notification that userY sent you message...
My Question: Do I need to create server side layer (C#, PHP or Node.js) to handle this part, so from android send data to C# and C# send to Firebase ? or there simple way to do it direct from Android application ?
Thank you.
You do not need a server to send the message itself. You can even send from the bash shell.
curl -H "Content-Type: application/json " -H "Authorization: key=Your_AUTHKEY" -X POST -d '
{ "data" : { "mykey" : "myvalue"},"notification": {"title": "My test 1","body": "bla bla"}
, "to" : "Your_looong_TOKEN"}'
A problem may arise when passing a token. There can be a useful durability value (write to the base).
Just send a post request with the appropriate headers.
As per my comment, you should have a look at Cloud Functions for Firebase, specifically, Realtime Database Triggers.
Let's say you're using Firebase Realtime Database. For your flow where "userY sends a form to userX", it could go like there'd be a forms node for a users, where you'll add forms from other users, and every time a form is added, you send a notification with Firebase Cloud Messaging. Similar on how you'd send when using Firebase Admin.
Via Postman I am receiving the the following response:
The WebHook request must contain an entity body formatted as JSON
With the help of some online tutorials I set up a webhook receiver that successfully reads in events from GitHub.
The next hurdle is being able to to receive a request containing XML data. I brought in the relevant WebHooks.Custom packages via NuGet so that I can handle a less specific request. I'm able to get into the ExecuteAsync method in my CustomWebHookHandler class and read in the data if it's sent as JSON, but if I change the raw body of the request to XML (along with the content-type in the header) I get the error listed above.
Do .NET Web API projects not handle XML out of the box? All commments I found elsewhere stated that they do handle XML.
If they don't handle XML out of the box how do I change the app to allow XML?
If they do handle XML out of the box why am I getting the error message above?