Send RAW Azure Push Message - azure

I'm trying to send a raw push notification message from Azure to my mobile device through an Web API. Previously I made use of a toast message and I got that working just fine, but not so much with the raw message type. This is what I've tried so far in my web API, without any success:
var jObject = new JObject
{
{
"Body", pushMessage.Body
},
{
"From", pushMessage.From
},
{
"Date", DateTime.Now.ToString(CultureInfo.InvariantCulture)
},
{
"Title", pushMessage.Title
},
{
"TargetType", pushMessage.TargetType.ToString()
}
};
Notification notification = new WindowsNotification(jObject.ToString());
notification.Headers.Add("X-WNS-Type", "wns/raw");
notification.ContentType = "application/json";
var task = Notifications.Instance.Hub.SendNotificationAsync(notification, "some tag value");
The above code never pushes the actual message. Could someone please provide me with some information regarding this. I've tried various methods described on the web, without any success.
Many thanks!

Turns out the above code works just fine - there was an issue with one of the settings in Azure ... pretty stupid mistake in the end o_O

Related

Sending the file from bot to user(1:1)

I am new to development in teams and botkit. There is a bot that is up and running on Teams.
I want to share a file generated by the bot to the user(send a file from bot to the user) on teams. I have read the Microsoft-teams document. According to which first step is to send a Message requesting permission to upload which I am able to complete successfully. Below is the code, I have used to show the card to the user to ask for permission.
controller.hears('download', ['message_received', 'direct_message', 'direct_mention'], function (bot, message) {
var reply = { text:"" ,attachments: [] }
var ticketObj = {
"contentType": "application/vnd.microsoft.teams.card.file.consent",
"name": "result.txt",
"content": {
"description": "Text recognized from image",
"sizeInBytes": 4348,
"acceptContext": {
"resultId": "1a1e318d-8496-471b-9612-720ee4b1b592"
},
"declineContext": {
"resultId": "1a1e318d-8496-471b-9612-720ee4b1b592"
}
}
}
reply.attachments.push(ticketObj)
bot.reply(message, reply)
})
According to the Microsoft-teams document, when the user will click on accept button, the bot will receive an Invoke activity with a location URL.
But, when I click on the accept, nothing goes to my bot. It shows the error message: "This card action is not supported".
How to provide support for this card action?
Adding answer from comment section for more visibility:
Issue is resolved now. The issue was of uploading the manifest.json.
To send and receive files in the bot, set the supportsFiles property
in the manifest to true. This property is described in the bots
section of the Manifest reference.
The definition looks like this, "supportsFiles": true. If the bot does
not enable supportsFiles, the features listed in this section do not
work.
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/bots-filesv4#configure-the-bot-to-support-files
Sample Link:
https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/56.teams-file-upload

How to create Quick Replies using MS Bot Framework on Facebook Messenger?

I have been using Node.js and the MS Bot Framework(3.0) for my bot development needs for quite some time now.
One of my needs is to request a user to share its e-mail address with the bot.
Facebook offers a Quick Replies API exactly for that.
I am having a hard time understanding how should i utilize the framework to create a custom message with the quick reply option.
One of my first attempts was to pass native metadata to a channel using custom channel data
I have succeeded implementing various templates which are supported by Messenger platform, but quick replies are sort of other beast compared to buttons, lists and other templates. currently i struggle to create a quick reply message using the framework provided tools.
Please point me in the right direction.
You can send Facebook quick replies either through the source data in V3 of the BotFramework or through the channel data in V4 of the framework. See the two examples below:
Node
V4
await turnContext.sendActivity({
text: 'What is your email?',
channelData: {
"quick_replies":[
{
"content_type": "user_email"
}
]
}
});
V3
var message = new botbuilder.Message(session)
.text('What is your email?')
.sourceEvent({
facebook: {
"quick_replies":[
{
"content_type": "user_email"
}
]
}
});
session.send(message);
CSharp
V4
Activity reply = turnContext.Activity.CreateReply();
reply.Text = "What is your location?";
reply.ChannelData = JObject.FromObject( new {
quick_replies = new object[]
{
new
{
content_type = "location",
},
},
});
await turnContext.SendActivityAsync(reply, cancellationToken);
Hope this helps!
On v3 you can just add the JSON of the quick_reply template defined by facebook to the channeldata as JSON object (JObject)
reply.channelData = new JOBject("[JSON HERE]");

Windows Azure node.js Push notification for Windows store 8.1 - How to use 'createRawTemplateRegistration' template?

Please explain with one example as I am getting Error: 400 - The specified resource description is invalid.
Basically, I want to update badge value. But there is no template for badge registration in WnsService API document (http://azure.github.io/azure-sdk-for-node/azure-sb/latest/WnsService.html). So, I am trying with "createRawTemplateRegistration" template to update the badge value.
Please help me on this.
You can directly use the function sendBadge() to push badge value to client devices.
Please try the following code:
var azure = require('azure');
var notificationHubService = azure.createNotificationHubService('<hubname>', '<connectionstring>');
notificationHubService.wns.sendBadge(null,99,function(error,response){
if(error) console.log(error);
console.log(response);
})
Any further concern, please feel free to let me know.
update
Do you mean that you want only one template and to handle all the types of notifications including Raw, Toast, Badge? If so, I think the answer is negative. According the description http://azure.github.io/azure-sdk-for-node/azure-sb/latest/WnsService.html#createRawTemplateRegistration:
Remember that you have to specify the X-WNS-Type header
So the header option is required. And according the REST API which is invoked via this api in nodejs is Create Registration, and we can find the description:
The BodyTemplate element is mandatory, as is the X-WNS-Type header.
So we should specify the notification type for the template.
update1
This code sample works fine on my side:
var channel = '<devicetoken>';
var templateMessage = { text1: '$(message)' };
notificationHubService.wns.createRawTemplateRegistration(channel,'tag',JSON.stringify(templateMessage), {headers: { 'X-WNS-Type': 'wns/raw' }},
function (e, r) {
if (e) {
console.log(e);
} else {
console.log({
id: r.RegistrationId,
deviceToken: r.DeviceToken,
expires: r.ExpirationTime
});
}
}
)

Yammer API - unseen messages and notifications

I am developing an integration from SharePoint to yammer enterprise.
The integration will be two images, the envelope and the bell icon from yammer.
Along those should the the correct numbers. Through all the API's given at
https://developer.yammer.com/docs/ I have only managed to find the amount of notifications at the networks/current.json.
Under many different api's are numbers with names such as unseen messages, but they do not referer to this specific number. It should be easy to find and I am sure that somebody out there is smart enough to know this.
If Anybody knows which api I should call, then I it would be much appreciated if they share it =)
you can check the following code and you will get unseen notification and unseen message count.
yam.platform.request({
url: "networks/current.json",
method: "GET",
data: {},
success: function (networks) {
for (var i = 0; i < networks.length; i++) {
if (networks[i].permalink === "permalink_name") {
var msgCount = networks[i].unseen_message_count;
var notificationCount = networks[i].unseen_notification_count;
}
}
},
error: function () {
console.log("There was an error with the request.");
}
});

Push notification for toast not working in azure

My Push notification code for toast notification is not running when run through scheduler in azure. my code is
function EWSReminder() {
push.wns.sendToastText01("https://sin.notify.windows.com/? token=Ysdfdhjkdjksj%2fAScjFHiwrUbS6y%2bvumj9sKUqhklsdfjgfdslcvl;dklslkskdlsdl;9XD58CMJebd04EknQY0Hgaxed6%uirutiuritubW%2fRcpdvapAYlMcnWLE360%3d", {
text1: "Sample toast from sample insert"
}, {
success: function(pushResponse) {
console.log("Sent push:", pushResponse);
}
);
}
I get this error
Error in script '/scheduler/EWSReminder.js'. Error: The options.client_id and options.client_secret must be specified as strings or the WNS_CLIENT_ID and WNS_CLIENT_ID environment variables must be set.
[external code]
at EWSReminder (</scheduler/EWSReminder.js>:2:16)
at </scheduler/EWSReminder.js>:1:13
[external code]
I can't figure out what the problem is pls help. I have applied code of all the microsoft samples available all have the same code, but none is working for me.
You need to set Client Secret and Package SID in Azure Portal (Push tab in your Mobile Service). These credentials can be obtained through Windows Store Developer Portal.
Even I too have the same issue and I have put the values in the portal which I took from the Windows Store Developer Portal.
The below code works for me but the above code doesn't as shown by Yesh.
var pushWNS = require('wns');
pushWNS.sendToastText01(uri, { text1: Name }, { client_id: 'xxx', client_secret: 'xxx' },
function (error, response)
{
if (!error)
{
// success code
}
else
{
// error handling
}
});
and also I wanted to know the difference between both the codes mentioned by me and Yesh

Resources