Webhook incoming with event subscription create loop - webhooks

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.

Related

Slack webhook not sending personal message

I am trying to send personal message to particular user using webhook. I created webhook so i am getting personal message. But I am not able to send personal message to others personal chat. I don't want to use bot.
slack.setWebhook("Webhook");
slack.webhook({
channel: "D01KMUZ4E4S",
username: "webhookbot",
text: "This is posted to #general and comes from a bot named webhookbot."
}, function(err, response) {
console.log(response);
});
Slack Webhook URLs are tied to a particular channel, individual message, or group message. You need to create a new webhook in your workspace for each user you would like to send messages to.

How to get user id using email id in teams using python

I'm creating a bot to notify a user after an action has been done. Where i'm able to get my details using the below(screenshot) code.
Now in order to send a message to a user through a bot i would need his/her ID before hand to send a notification like in the above case i'm able to extract my info as i'm already logged in Teams. Unfortunately alphanumeric ID is very difficult to use and needs to be there before requesting and sending the notification.
Below is the JSON result if the ID is already known.
Response body
{
"id": "29:1GcS4EyB_oSI8A88XmWBN7NJFyMqe3QGnJdgLfFGkJnVelzRGos0bPbpsfJjcbAD22bmKc4GMbrY2g4JDrrA8vM06X1-cHHle4zOE6U4ttcc",
"objectId": "9d3e08f9-a7ae-43aa-a4d3-de3f319a8a9c",
"givenName": "Larry",
"surname": "Brown",
"email": "Larry.Brown#fabrikam.com",
"userPrincipalName": "labrown#fabrikam.com",
"tenantId":"72f988bf-86f1-41af-91ab-2d7cd011db47",
"userRole":"user"
}
How i can get the unique ID of the user by using email id so that i can send a personal message to him/her using bot.
There is an option to fetch conversationChatId to send proactive message.
Before you fetch the conversation Id, you should check whether your bot is currently installed for a message recipient or not.
Note: Installation of app via Graph API triggers conversation update event for Bot.

Using Azure Notification Hub, who is reporting "no matching targets"?

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.

Streaming data consumed from third-party WebHooks to application using an event broker in Azure

I'm currently working on a project where I need to consume a third-party Webhook into my application. The issue is, this third-party service doesn't allow me to pick which events to push to my application through this Webhook, so I'll have to respond to all of them even if they are mostly useless, and if I need to expand on my application or divide it into microservices, I would be streaming the same data to all services even if they have different needs. Also, I would be facing data loss in case of issue with my application server.
The solution would be to use an Event Broker, which would collect all events from the Webhook, respond to the provider with a 200 OK status code, push the event to a specific topic which will be stored until all the concerned subscribed services receive that data.
I'm looking for a fully managed service in Azure, so far I've come across Azure Event Grid, Azure Event Hub and Azure Service Bus.
I wanted to know about the feasibility of this scenario, and if I can stream directly from a Webhook to one of these Azure services.
No, afaik you cannot stream directly into those service. You will need to setup something that accepts the webhook and sends it to one of those listened service.
However, what I would do is create an http triggered azure function. You should be able to configure the webhook to post to the function.
Once you got your function setup you can create some logic there to route the message to the proper channels based on its content. Now that could be an application of yours, a Service Bus Queue, Azure Storage Queue or Event Grid. I would not recommend an Event Hub as it is less suited for this specific purpose.
In the case of consuming a third-party events without guarantee their in order processing and the webhook payload is an array, the Azure Event Grid can be consumed your third-party webhook directly.
The following screen snippet shows this example:
The above integration is based on the Custom Topic Endpoint with a CustomInputSchema.
The Custom Topic Endpoint sends a response back to the webhook with the following HTTP response code:
Success 200 OK
Event data has incorrect format 400 Bad Request
Invalid access key 401 Unauthorized
Incorrect endpoint 404 Not Found
Array or event exceeds size limits 413 Payload Too Large
The AEG model distributing an event in the loosely decoupled Pub/Sub manner with a reliable and retry delivery to the subscriber based on its subscriptions. The AEG subscription represents a logical connectivity between the source of the interest and consumer. It is a set of metadata describing by consumer what, where and how.
Basically there are two delivery patterns such as:
Push-PushAck where the event is pushed to the subscriber handler for its business processing and the result is back to the AEG e.g. Web Hook (Azure Fuction) and Hybrid Connection.
Push-PullAck where the event is reliable delivered to the subscriber and the delivery response is returned back to the AEG. The event must be pulled out from this delivery target for its business post-processing, e.g. Service Bus Queue, Storage Queue and Event Hubs.
UPDATE:
For creating a custom topic endpoint with a CustomInputSchema can be used for example the REST API
The following is an example of the payload PUT request:
{
"location": "westus",
"properties": {
"inputSchema": "CustomEventSchema",
"inputSchemaMapping": {
"properties": {
"id": {
"sourceField": null
},
"topic": {
"sourceField": null
},
"eventTime": {
"sourceField": null
},
"eventType": {
"sourceField": null,
"defaultValue": "notification"
},
"subject": {
"sourceField": null,
"defaultValue": "/webhook/events"
},
"dataVersion": {
"sourceField": null,
"defaultValue": "1.0"
}
},
"inputSchemaMappingType": "Json"
}
}
}
The above CustomInputSchema enables to use any input event schema for this Custom Topic endpoint. That's very nice feature of the AEG. The "bad news" is that the events must be in the array included also a single event. I hope, that the AEG team will make an improvement for custom and domain topics when the single event can be published also as a JObject (no inside of the array).
For bypassing an input event schema via AEG eventing model, the subscriber (consumer of the source event interest) must declared a DeliverySchema = CustomInputSchema. The default output event schema is the EventGridSchema.
The following examples show an event message published to the custom topic with above CustomInputSchema and delivered to the subscribers using a CustomInptutSchema and the other one with the EventGridSchema.
Fire Event to the Custom Topic Endpoint (array of event(s)):
[
{
"abcd": 12345
}
]
Subscriber with DeliverySchema = CustomInputSchema:
{
"abcd": 12345
}
Subscriber with DeliverySchema = EventGridSchema (default schema):
{
"id": "f92a5dbf-d206-4e61-ac1e-7498c543039a",
"eventTime": "2019-07-14T07:19:00.3969337Z",
"eventType": "notification",
"dataVersion": "1.0",
"metadataVersion": "1",
"topic": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rk2012/providers/Microsoft.EventGrid/topics/testerTopic8",
"subject": "/webhook/events",
"data":
{
"abcd": 12345
}
}
Note, that the events can be filtered (selected) for each subscriber based on its subscription properties in the loosely decoupled Pub/Sub manner. In other words, subscriber can subscribed to the AEG eventing model any time via its subscription where is declared a specific source interest, e.g. topic, subject, event data, etc., mechanism of the delivery, retrying, deadlettering, etc.

Azure Notification Hub like simple sender

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.

Resources