I have some question about Azure notification hub.
It is possible to send push message to gcm or apns without registration devices? I would like only to pass e.g. gcm model like:
{
"to": "registraionId",
"data": {
"title": "Some title",
"message": "Some message"
}
}
I saw that exists defined REST https://msdn.microsoft.com/en-us/library/azure/dn223273.aspx but for me it not working, I suppose that flow should look like [make installation] -> [make registration] -> [send message] is it correct? I also tried to send message by visual studio and azure portal.
Is it possible to send messages without registration etc. ?
I will be very gratefull for any examples :)
I solved my problem, of course exists Rest api https://msdn.microsoft.com/en-us/library/azure/mt608572.aspx which is used to sending direct messages to devices without registrations.
Related
I'm using Azure Alerts to use webhooks. I added the webhook in the action group. The URL I used is the one from Slack.
I also added a Notification Type Email. The notification email gets triggered but I am not receiving any message in the Slack channel.
I was able to push messages to the webhooks using postman hence I know my webhook is correct. But Azure Alert is not able to trigger the webhook. I am not receiving any messages in the Slack channel.
Azure Monitor sends a notification with its own schema definition. Slack doesn't recognize it, so you cannot see any notifications in the channel. It is possible to create a Logic App or Azure Function to transform the default schema.
Here the more information about it:
https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-common-schema
Slack expect a json object when using webhooks. When sending directly from azure alert you will get bad request.
Every slack channel has an e-mail adress. You can post messages to the channel using that email in azure alerts
Anyone looking for using Slack and Azure Alerts. This seems to work fine:
...
webhook_receiver {
name = "Slack"
service_uri = "https://hooks.slack.com/services/secret"
use_common_alert_schema = false
}
Then in the scheduled query rules alert:
...
action {
action_group = [data.azurerm_monitor_action_group.actiongroup.id]
email_subject = "Disk storage at less than 10%"
custom_webhook_payload = "{ \"text\" : \"Warning: Storage has less than 10% diskspace remaining!\"}"
}
When sending notifications to FCM, either from my Azure Service via Azure Notification Hub or it's test send, I am not getting any error messages, but the notification is not delivered to the specified device. The hub's test send reports "Message was successfully sent, but there were no matching targets." However, from the FCM portal test send it is, so I know the device is configured correctly.
Is it FCM reporting "no matching targets" or the hub?
I have tried a variety of device ids as targets, both the token received from FCM by the device and variations of the FCM Token generated by the GetFMToken method.
Using VS, I see in the hub registrations for APNS; I don't see any for FCM, even though I have seen registration events for my pushes in the hub's Overview Monitoring.
An example of the latest notice semantics:
"{ "priority": "high", "data": { "Raw": "PIDMe54*****64Test190801142953088468/1/2019 2:29:53 PM"}, "notification": {"channel_id": "MyNotications"}, "to" : "f-E6xD_YkFs:APA91bEsHI_Fc9zNKFfYWm2b5-ebVuS-Kp8WLMM0YgWVv6fc6dXpqvwJGUNedE9ZfaBpiDC69IQJt4hjizm98l7Lbo3RzyeHi5dAzKnFvKNZ4nCgEIoQShEGfgB5AkhS-2j7LXtcjudC"}
I expect just ""Message was successfully sent" and the notification delivered.
I am using a web service api to receive message from a slack channel (event subscription) and the same web service api to send message (Incoming webhook) to the user on the same slack channel.
But when I send a message, this same message is send back to my api by the slack event subscription. That create an infinite loop.
How can I declare my message that I am sending to the channel which I can check when I receive back by the event subscription ?
This is normal behavior of Slack and can not be changed by any configuration. When you subscribe to message events you will receive events for all messages, including the ones from your own app.
To avoid an infinite loop you therefore need to detect and filter out the messages from your own bot before continue processing. This can be done easily, since all messages contain the name of the the sender. e.g. you can filter out all messages that are have the bot_id of your Slack app or all messages from bots (that have subtype = bot_message).
Here are some examples how messages look like and how messages from real users are different then message from Slack apps:
Example message from a real user:
{
"type": "message",
"user": "U12345467",
"text": "Good read for some of guys",
"ts": "1531745292.000021"
}
Example message from a Slack app or bot
{
"text": "Hey guys",
"bot_id": "B12345678",
"type": "message",
"subtype": "bot_message",
"ts": "1531700187.000049"
}
See also this answer.
I'm testing out Azure Event Grid with a Azure Relay, Hybrid Connection handler. It's not working for me.
I can see messages being published to Azure Event Grid. So far so good.
I've set up a subscription to the Event Grid topic and I've configured it to send events to a handler specified as an Azure Relay with a Hybrid Connection endpoint.
Looking at the metrics for the subscription with the Hybrid Connection handler, I see the following telemetri:
Matched Events
Delivery Failed
Expired Events
… but I see no Delivery Succeeded event???
Also, the Hybrid Connection listener (just a simple Console App) connected to the Azure Relay receives nothing. I've tested the listener by sending some test messages directly to the Relay and that works fine.
The logical conclusion, is that the events published to the Event Grid are not being delivered probably to the Relay Hybrid Connection handler. But why? There are not that many parameters, so I not sure what I'm doing wrong. It seems rather straight forward to configure this.
I'm a the point where I'm beginning to believe that the Event Grid / Hybrid Connection scenario is currently not working. It is in preview after all, so that could explain it.
I know that there is not much to go on here, but I was hoping that others might have some experience with this?
The issue still remains. The issues seems to be related to the formating of the json being passed from the Event Grid Subscription to the Hybrid Connect.
Update
I finally had some time to look more carefully into this.
I set up the Event Grid Tester and every time the Event Grid recieves a message I can see this error in the log:
HybridConnection: Message processing failed - Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'.
I'm still not able to fix this, as I do not control the message. The message is generated by Azure Logic App and send to the Event Grid using the Event Grid connector. The Event Grid Connector in Azure Logic Apps is in preview, so that might explain the challenges I'm seeing.
I've successfully tested Event Grid subscriber locally using Azure Relay and documented it here. It is based on a sample Microsoft is providing and implemented using WCF variant of client, not the .NET Standard version.
you can simulate an Event Grid message to the HybridConnection url using a http POST request:
POST https://{myNamespace}.servicebus.windows.net/{myHybridConnectionName}
headers:
content-type: application/json
x-ms-version: 2015-07-08
Aeg-Event-Type: Notification
Authorization: SharedAccessSignature sr=xxx&sig=xxxx&se=11111111&skn=xxxxx
body:
{
"id": "123456",
"eventTime": "2018-07-22T13:09:07.5164877Z",
"eventType": "recordInserted",
"dataVersion": "1.0",
"metadataVersion": "1",
"subject": "/myapp/vehicles/motorcycles",
"data": {
"make": "Ducati",
"model": "Monster"
}
}
Note, that the sasToken for authorization header can be copied from the Azure Event Grid Tester log panel, when the HybridConnection has been opened.
the other option is to generate it by the following code:
using Microsoft.Azure.Relay;
// ...
var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("hybridconnectionPolicyName", "hybridconnectionPrimaryKey");
var token = tokenProvider.GetTokenAsync("https://{myNamespace}.servicebus.windows.net/{myHybridConnectionName}", TimeSpan.FromDays(10)).Result.TokenString;
I use Notification Hubs to send Notifications to IPhone and Windows Store app. The IPhone is working perfectly fine, but there is some issue with Windows Store when sending the notification.
Error: The Push Notification System handle for the registration is invalid.
Template:
String WindowsTemplateStr = #"<toast><visual><binding template=""ToastImageAndText03""><image id=""1"" src=""https://"" alt=""Customer""/><text id=""1"">$(headlineText)</text><text id=""2"">$(bodyText)</text></binding></visual></toast>";
I use this code to register:
registration = await hubClient.CreateWindowsTemplateRegistrationAsync(userDeviceInformation.ChannelUri, Templates.WindowsNotificationTemplate,
new string[]
{
userDeviceInformation.InstallationId,
userDeviceInformation.UserName
});
The registration goes through fine and I can see the tags properly associated using "Service Bus Explorer".
When I try to send the Notification this is what I do:
notification.Add("src", ImageUrl);
notification.Add("headlineText", String.Format("Message from {0}", fullName));
notification.Add("bodyText", String.Format("Message {0}", message));
When the notification is sent, nothing is received on the device; and I see the registration is also being deleted.
I can't seem to find what is causing this behavior.
Any ideas ?
If WNS returns invalid handle then the corresponding registration will be removed from the notification hubs.
You can use test send to check the error details:
http://msdn.microsoft.com/en-us/library/microsoft.servicebus.notifications.notificationhubclient.enabletestsend.aspx