Send GCM Push Notification to Multiple Token Id from nodeJs Server [duplicate] - node.js

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"]
}

Related

Send Batch events to Event Hub using REST API

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

Unable to send text message to India (+91) using AWS SNS

This is what the CloudWatch response looks like
{
"notification": {
"messageId": "69f1ef66-3db1-5ed0-bbdf-b8b32c6dbe03",
"timestamp": "2020-09-11 05:48:12.245"
},
"delivery": {
"destination": "+91xxxxxxxxxx",
"smsType": "Promotional",
"providerResponse": "Internal Error",
"dwellTimeMs": 41
},
"status": "FAILURE"
}
I'm using the region ap-south-1 which is in the supported regions and using an Indian phone number (+91) but still getting this error. Apart from AWS CLI, I've also tried python boto3 library to send the message to no avail.This is the python code that I've tried:
import botot3
client = boto3.client('sns','ap-south-1')
client.publish(PhoneNumber='+91xxxxxxxxxx',Message='Hello')
I believe sending SMS messages to Indian phone numbers requires you to register a sender ID as India has stricter laws on texts. Do you have a non-Indian phone number you can test with to confirm?
From Supported Regions and Countries:
Senders are required to use a pre-registered alphabetic sender ID.
Additional registration steps are required. For more information, see
Special requirements for sending SMS messages to recipients in India.

Directline API message to Microsoft Bot

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"
}

Getting the email id from the Outlook REST API when sending email

I am trying to use the Microsoft Rest API to send emails on behalf of our users. When I create a message as a draft, I get back an ID that I can use in future requests for editing, deleting, viewing the full conversation (after it is sent), etc.
I do not want to save it as a draft since I have no reason to, I just want to send it directly. After it is sent, I would still like to view the full conversation. However, if I just send the email (using the /sendmail endpoint), I do not get that ID. Is there anyway to get it? Here is my request:
POST https://outlook.office.com/api/v2.0/Users/email/sendmail
{
"Message": {
"Subject": "Test",
"Importance": "Normal",
"ToRecipients": [{
"EmailAddress": {
"Address": "<email>",
"Name": "<name>"
}
}],
"Sender": {
"EmailAddress": {
"Address": "<email",
"Name": "<name>"
}
},
"Body": {
"ContentType": "HTML",
"Content": "<html>\\n<head>\\n <style>\\n p { color: red; }\\n </style> \\n</head>\\n<body>\\n <p>Test</p>\\n</body>\\n</html>\\n"
}
},
"SaveToSentItems": "true"
}
The HTTP response code is 202, the email sends, but the body is empty (no content, whatsoever).
I don't think this matters, since I can recreate this in Postman, but I am running this in Nodejs using the node-outlook package.
Emails in Exchange via REST and EWS are submitted for transport, but the actual send and subsequent save to the sent items folder are done async. This is why you don't get the id. Transport is who actually writes the email to the sent items folder, not REST.
If you really need to find the item after it has been saved to the sentItems folder, set something like the PR_SEARCH_KEY and then do a view of the sent items folder and seek to that search key value.
Also note when you save a draft, the id that you get back will be different than the id of the item in the sent items folder because the folder Id is part of the id of the item, so that id wouldn't help you anyways.
I don't know which rest api version are you using (i'm using v2.0) but i will try to explain this issue. Sorry for my english i advance.
You have 2 ways to reply a message: on the fly way or the complete way.
On the fly way
Its the easy way, just send a post request to
https://outlook.office.com/api/v2.0/me/messages/{message_id}/reply
or
https://outlook.office.com/api/v2.0/me/messages/{message_id}/replyall
and with the body
{
"Comment": "This is your message in plain text or html code"
}
and thats all.
The problem with this methos that you can only send plain text or HTML, no attachments or anything else. If that's all you need this is your best option.
The complete way
If you need to send an attachment or perform any other action you need to perform these 3 steps:
1. Create a draft from the message you want to reply
Send a post request to
https://outlook.office.com/api/v2.0/me/messages/{message_id}/createreply
This will give you an json object save the "Id" property {draft_id} of this draft for later use.
2. Update the draft
Send a patch request to
https://outlook.office.com/api/v2.0/me/messages/{draft_id}
and with the body
{
"Body": {
"ContentType": "HTML or Text",
"Content": "Your response in plain text or html"
}
}
or any other parameter you want to change.
3. Send the draft
Send a post request to
https://outlook.office.com/api/v2.0/me/messages/{draft_id}/send
And thats it.
If you need more info abut this check https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations

Get channel list in Slack

I'm using Incoming webhooks to send message to the channel. I decide the channel in JSON format.
var message = {
"text" : "text",
"channel" : "#general",
"username" : "me"
};
How can I get the list of channels in Slack?
You would need to use the Web API. Incoming webhooks are insufficient for this.
(Specifically, you want channels.list.)

Resources