I am able to send events to Event Hub as a batch using the Nuget package Azure.Messaging.EventHubs.But I want to use REST API.
I am able to send single events to Event Hub using REST API using Postman. But as per documentation if I need to send batch events in REST API I need add header Content-Type:application/vnd.microsoft.servicebus.json and Also the message should be enclosed with the "Body"
like [{"Body":"Message1"},{"Body":"Message2"},{"Body":"Message3"}]
So if I need to send json as event then should I create a json string and send it?
Sample:
[
{
"Body":"{\"ID\":\"1\",\"Name\":\"abc1\"}"
},
{
"Body":"{\"ID\":\"2\",\"Name\":\"def1\"}"
},
{
"Body":"{\"ID\":\"3\",\"Name\":\"xyz1\"}"
}
]
OR is there any other option to send event as Batch using the REST API to Event Hub.
"Body" is a string content then yes, you must escape your JSON content first. Your sample looks OK to me.
Yes, you could create an events list -
List<Event> events = new List<Event>(){
new Event(1,"abc1"),
new Event(2,"def1"),
new Event(3,"xyz1"),
}
and send it via POST
Related
Looking at the docs for the SignalR bindings to send a message to a specified user you include the UserId property on the message as such -
[FunctionName("SendMessage")]
public static Task SendMessage(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")]object message,
[SignalR(HubName = "chat")]IAsyncCollector<SignalRMessage> signalRMessages)
{
return signalRMessages.AddAsync(
new SignalRMessage
{
// the message will only be sent to these user IDs
UserId = "userId1",
Target = "newMessage",
Arguments = new [] { message }
});
}
This example is taken straight from the documentation, but the comment implies you message multiple userids, even though the property is a string and not an array.
How would you specify multiple users? (If for example, they are in a private chat channel together) Or is this mistake in the wording of the comment and you would need to send a message per user?
With other versions of SignalR I would put them in a group, but bindings for this do not exist for functions.
Group operations were introduced in the latest release.
Now you can:
Send a message to a group using GroupName in SignalRMessage
Add/remove user in a group using IAsyncCollector<SignalRGroupAction> output
Unfortunately just like the doc says, right now with Azure function binding we can only send message to one user or to all clients.
See the code of current extension SDK Microsoft.Azure.WebJobs.Extensions.SignalRService v1.0.0-preview1-10002.
It shows the extension has only two methods SendToAll and SendToUser.
Task SendToAll(string hubName, SignalRData data);
Task SendToUser(string hubName, string userId, SignalRData data);
The comment confused you is actually for old sample, the author forgot to modify it.
Good news is that support for group operation is under progress.
I have created the bot in azure services using LUIS, which used as chatbot and can create conversations using dialogs.
At some point, I am trying to push messages to chatbot using Direct Line API 3.0, I'm using Postman to send the messages to bot.
I followed the instructions from this page, https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-send-activity?view=azure-bot-service-4.0
I'm able to send message to the conversation as bot, below is the image I sent message from Postman and got successful response.
But my issue is, after the message is sent, the bot tries to analyse even though it's not user message. Bot starts to send message from default message handler like below,
Even after sending the message successfully, my bot triggers the default message handler, which is expected only to happen for user messages but not for bot messages.
Also, I have checked with webchat channel, which it doesn't trigger this default message handler. This is happening only in DirectLine API, can anyone help me on this.
Instead of sending the message as type "message", you should send it as "event".
This way your MessagesController will see it as an ActivityType of Event instead of Message and you can process however you want without spaghettifying your actual message handling
If you want to send different kinds of event to make it even easier, then you can 'name' you event by supplying the 'name' field with a value in your json.
Third, if you need to include data with the message, you would supply a value in the 'value' field of your json.
The github page for the standard webchat client has some great information on sending events. It might shed a bit more light on the json.
You can read more about the 'event' activity type here
You message json would look something more like this:
{
"type": "event",
"from": {
"id": "user1"
},
"name": "theEvent",
"value": "someDataMyBotNeeds"
}
I want to send same message to multiple devices in android using GCM. Currently i am able to send push notification to my device as i am explicitly specifying my registration ID in PHP code. But i want to send it to multiple devices so how can i do this???
Any help or idea are highly appreciated.
Please guide for this
Thanks
What you should do is send multiple registrations Ids (up to 1000 at once) when you send your message to GCM, and you will need to use JSON as your request format.
You can read more about that here:
https://developers.google.com/cloud-messaging/server-ref#downstream
You will need to add your list of Id's to the registration_ids field:
A string array with the list of devices (registration IDs) receiving the message. It must contain at least 1 and at most 1000 registration IDs. To send a multicast message, you must use JSON. For sending a single message to a single device, you could use a JSON object with just 1 registration id, or plain text (see below). Required.
Here is an example request from their docs:
Here is a message with a payload and 6 recipients:
{ "data": {
"score": "5x1",
"time": "15:10"
},
"registration_ids": ["4", "8", "15", "16", "23", "42"]
}
Send Grid - Does anyone know how to pick a send grid template using its ID when using the api to send an email?
I've got this working for sending a subject, email address and body text but I want to select a template I made in send grid.
Is there any way to call a template in send grid by its ID?
*I'm using node js to call the send grid api using javascript.
Checkout the docs under "Templates" here: https://github.com/sendgrid/sendgrid-nodejs
From their example using node js:
email.addFilter('templates', 'enable', 1);
email.addFilter('templates', 'template_id', '09c6ab89-9157-4710-8ca4-db7927c631d6');
I'm using Zapier's REST Hooks. In my Zap, I also have a trigger field that is used to trigger the zap when the condition is met. In my case, the trigger field is "segment" - so as to only trigger the zap when the selected segment is created.
The trouble I'm having is POSTING the selected trigger field to the REST Hook Subscribe URL.
My first thought is to update the "REST Hook Subscribe URL" to be: https://domain.com/api/v1/hooks?filter={{segment}}
Which does work to pass the trigger field as a URL paramater. However, this creates an Error for the other Triggers, because the "segment" field does not exist.
How is this best accomplished?
The trick here is to use Zapier scripting to manipulate the requests made to your App's API.
The trigger fields are available with the bundle.trigger_fields object. So I passed these in the params during pre_subscribe like so:
'use strict';
var Zap = {
pre_subscribe: function(bundle) {
return {
url: bundle.request.url,
method: bundle.request.method,
auth: bundle.request.auth,
headers: bundle.request.headers,
params: bundle.trigger_fields,
data: bundle.request.data
};
}
}
That did the trick for me...