Get notification origin in windows 10 uwp? - c#

I'm writing a uwp app with notification listener and I'm trying to get the origin of a notification (like Google Chrome and the website it came from).
I tried using the AppInfo.DisplayInfo for a UserNotification but I can't get it to print the info, and I'm not sure if this is the right way to do this.
IReadOnlyList<UserNotification> notifs = await MainPage.listener.GetNotificationsAsync(Windows.UI.Notifications.NotificationKinds.Toast);
UserNotification n = notifs.Last();
var name = n.AppInfo.DisplayInfo.DisplayName;
I expected name to be the name of the app the notification came from but it seems to be empty or just not working. To be precise from a notification like this:
I want to extract the "Google Chrome" and / or "www.reddit.com".

Hopefully you have found a solution by now, but in case this helps anyone:
The notification doesn't know that your message is coming from a browser. The whole Windows notifications system doesn't take that into an account. Windows receives a UserNotification from an application, which in your case happens to be a browser. So your "origin" is the application "Google Chrome". Your best shot is to try and get the link from inside the notification itself, if it is inside the body somewhere.
I really think you should be able to find the link inside the text of the notification, but I would need more information on what exactly you are receiving to be sure. If you want to know how to read the text of the notification, do:
string appName = notif.AppInfo.DisplayInfo.DisplayName; //this will get you "Google Chrome"
NotificationBinding toastBinding = notif.Notification.Visual.GetBinding(KnownNotificationBindings.ToastGeneric);
if (toastBinding != null)
{
IReadOnlyList<AdaptiveNotificationText> textElements = toastBinding.GetTextElements();
string titleText = textElements.FirstOrDefault()?.Text;
string bodyText = string.Join("\n", textElements.Skip(1).Select(t => t.Text));
string website = ParseWebsiteFromText(bodyText); //my guess is the info you want is in here
}
From there you have to parse the information you want, if it's available.
If you want to know more, I suggest reading the documentation from here: https://learn.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener.

Related

repeat runs of URI google.navigation fail

I've been developing a small asp.net website in which I require to open the android (and iPhone) native map application with directions to a pre-specified address, to do this I'm using this link
protected void anLogic()
{
string street = "my address here";
string formattedstreet = street.Replace(" ", "+");
string address = "google.navigation:q=" + formattedstreet;
Label1.Text = address;
Response.Redirect(address);
}
However, if the user has already clicked the link before and pressed the return button on their phone and tries to reclick, or already has google maps open the button does nothing.
I have also tried the format:
<a href="https://www.google.com/maps/dir/?
api=1&destination=Pike+Place+Market+Seattle+WA&travelmode=bicycling">Text</a>
But I've had similar results.
Basically the only method I've found to get these to work again is for the user to completely close their mobile web browser and google maps and start from the beginning again, which is less than ideal.
Noticed that google uses intents on the google mobile site which does not share this issue:
So I've been modifying my link to use intents rather than universal links:
<a href="intent://www.google.com.au/maps/dir//(ADDRESS+HERE)
#Intent;scheme=http;package=com.google.android.apps.maps;end"> test </a>
I've still had no luck, link still only works once, anyone know a method of overcoming this issue?
Edit: 16/10/20118 not solved yet, anyone looking over this, note the google reference documents from most useful to me to least:
https://developer.chrome.com/multidevice/android/intents
and
https://developers.google.com/maps/documentation/urls/guide
and
https://developer.android.com/guide/components/intents-filters

Testing Slack Interactive Messages Locally

I'm currently using SlackConnector Repo https://github.com/noobot/SlackConnector. I've created a bot and it sends interactive messages to my chat. I would like to add functionality to my interactive buttons but upon clicking them i get this response. Darn – that didn’t work. Only Slack Apps can add interactive elements to messages. Manage your apps here: https://api.slack.com/apps/ So it looks like I need a request URL to get my past my current roadblock. Is there a way to Test the Interactive Message button locally?
List<SlackAttachment> attachments = new List<SlackAttachment>();
List<SlackAttachmentAction> actions = new List<SlackAttachmentAction>();
actions.Add(new SlackAttachmentAction
{
Name = "game",
Text = "chess",
Type = "button",
Value = "Chess"
});
actions.Add(new SlackAttachmentAction
{
Name = "game",
Text = "Falken's Maze",
Type = "button",
Value = "Maze"
});
actions.Add( new SlackAttachmentAction
{
Name = "game",
Text = "Thermonuclear War",
Type = "danger",
Value = "war"
});
attachments.Add(new SlackAttachment
{
Text = "Choose a game to play",
Fallback = "You are unable to choose a game",
CallbackId = "wopr_game",
ColorHex = "#3AA3E3",
Actions = actions
});
connection.Say(new BotMessage
{
ChatHub = chatHub,
Text = "Usage: !talk <user>",
Attachments = attachments
});
return Task.CompletedTask;
One thing I tried was I set the request URL to use a url generated from https://webhook.site/#/ and I still get the same response upon clicking
It looks to me like you have two problems.
You don't have a Slack app
Interactive Messages only work if you have a registered Slack app. That is why you got that error message. But you can easily create one. Just go here and click on "Create a new app". One reason you need one is that you need to tell Slack to which URL to send the request, after a user clicks a button.
Slack can't reach your local app
Slack's interactive messages will only work with apps that can be reached from the public Internet. So if you want to develop your app locally you need to open your web server to the Internet. There are many ways to do it, one secure way is to use a VPN tunnel service. One provider for this kind of service is ngrok, which is also recommended in the official Slack tutorials. I use it myself and it works great.

Sign in Card with username/password fields

I'd like to create a sign-in card that is not a link to a webpage to sign in to. Something that behaves something like this
All of the resources I've found online only show the button link like
Whose code looks something like this
var replytoconversation = context.MakeMessage();
replytoconversation.Text = "Authorize your Account";
replytoconversation.Attachments = new List<Attachment>();
var cardbuttons = new List<CardAction>();
cardbuttons.Add(new CardAction
{
Title = "connect",
Value = "http://mail.google.com",
Type = ActionTypes.Signin
});
SigninCard plcard = new SigninCard("Log in to your account", cardbuttons);
Attachment plattachment = plcard.ToAttachment();
replytoconversation.Attachments.Add(new SigninCard("Log in to your account", cardbuttons).ToAttachment());
await context.PostAsync(replytoconversation);
Any help would be appreciated thanks
What you are asking is not possible using the card system in the way you are asking. The only way I can think of at the moment would be to create a login web page alongside your web interface chat (if that's what you are using) and embed the web page in the chat bot (I've done something like this for a similar reason). This is a useful way of dealing with a number of things, such as connecting to a system that does not have an api. I know it's not the exact answer you want, but it's really the only way to my knowledge.
Just updating this as ive been working on it lately. If you use Adaptive-Cards, you can add in Input boxes using AdaptiveTextInput. Link these to a submit function and you can have the user input their details in,then pass them to another function. Here, you can either cast out of the bot to an auth protocol (not sure about how, havent tried yet), or you can do what I'm doing, and use a http/ftp database to authenticate data. Not that secure, but depends on what you are using it for.

calling another http request upon changing page

I'm working with windows phone apps and I'm using here rest places api for my data and i retrieving data as json that give me information about location nearby like this
position: [ 37.77704 , -122.39494 ]
distance: 1241
title: Caltrain-San Francisco
averageRating: 0.0
category: { Public transport }
icon: http://download.vcdn.nokia.com/p/d/places2/icons/categories/11.icon
vicinity: 700 4th St<br/>San Francisco, CA 94107
having: [ ]
type: urn:nlp-types:place
href: http://demo.places.nlp.nokia.com/places/v1/places/8409q8yy-a7395cccbfc4474ba469f3ddc03e041b;context=Zmxvdy1pZD00OWQxZDY0Zi0zODc5LTVlNDAtOWY4ZC04ZGFmNWMyMGZhZDFfMTM4OTg4NDQxMzUxNV8wXzM1MjkmcmFuaz0w?app_id=lp3VaO8uhOFe0akZ4J1m&app_code=JwL7MNaSarML92oqEDshAg
id: 8409q8yy-a7395cccbfc4474ba469f3ddc03e041b
and i notice that if i open
href: http://demo.places.nlp.nokia.com/places/v1/places/8409q8yy-a7395cccbfc4474ba469f3ddc03e041b;context=Zmxvdy1pZD00OWQxZDY0Zi0zODc5LTVlNDAtOWY4ZC04ZGFmNWMyMGZhZDFfMTM4OTg4NDQxMzUxNV8wXzM1MjkmcmFuaz0w?app_id=lp3VaO8uhOFe0akZ4J1m&app_code=JwL7MNaSarML92oqEDshAg
i will go into other page that contain much detailed information about that location, so how can i get all of this data?the general and detailed data from that href
method that i using to get general data is using this
WebClient client = new WebClient();
Uri uri = new Uri(transportURL1 + latitude + "%2C" + longitude + transportURL2, UriKind.Absolute);
client.DownloadStringCompleted += (s, e) =>
{
if (e.Error == null)
{
RootObject result = JsonConvert.DeserializeObject<RootObject>(e.Result);
hereRestProperty = new ObservableCollection<Item>(result.results.items);
}
else
{
MessageBox.Show(e.Error.ToString());
}
};
client.DownloadStringAsync(uri);
so my app scenario is mainpage showing general location data and when I tap one of the location data it will navigate to detailpage that contain information from that href
how to do that?
edit: my work around is getting href and using that href to calling http request but i have no idea how to do all that...
edit2: after looking around I come up with idea of having mainpage with list of general information and if I click into one of the item in list it will navigate me to detailpage that will request from that href but i just don't know how to execute that in mvvm aproach...
If it is safe to assume that you are trying to add value to your app by adding a places feature, I would suggest that for Windows Phone 8 you would be better off launching HERE Maps directly using the HERE Maps Launchers API
For example, if your app is about hiking trails it would make sense to add a feature for finding details of places to eat or stay near that hiking trail - but you wouldn't need to create your own code to request, format and display the in-depth places data, just fire up the Maps app already on the device (passing in the href from the initial REST request if necessary). The advantage of doing this is threefold, firstly you can add this feature in four lines of code, secondly the user is presented with the places information in a familiar format, and finally information is retrieved from the device itself which alleviates the need to make additional HTTP requests.
One or more of the following tasks may be useful:
ExploremapsShowPlaceTask allows you to start the Maps application with the map centered to a place shown in the map.
ExploremapsSearchPlacesTask allows you to start the Maps application with the search view.
ExploremapsExplorePlacesTask allows you to start the Maps application where the nearby places of interest are shown.
PlacesShowDetailsByLocationTask allows you to start the Maps application with the places view for the selected place.
PlacesShowDetailsByIdHrefTask allows you to start the Maps application with the places view for the selected place.
Note that if HERE Maps is not installed on the Windows Phone 8 device, the user will be directed to download it for free from the app store.

Post Media to User/Page Wall in Facebook with C# SDK

I'm using Facebook .Net SDK(http://facebooksdk.net/) in my application. I need post an image to the wall of the user or his page.
I have this piece of code to try do this:
var postUrl = "<fbid>/feed";
var fbParameters = new Dictionary<string,object>();
fbParameters["message"] = postRequest.FacebookPostContent;
if (postRequest.MediaData != null && postRequest.MediaData.Length > 0)
{
var stream = new MemoryStream(postRequest.MediaData);
if (postRequest.ContentType.Equals("image/jpeg"))
{
postUrl = postUrl.Replace("/feed", "/photos");
fbParameters["picture"] = new FacebookMediaStream { ContentType = postRequest.ContentType, FileName = DateTime.UtcNow.ToString("ddmmyyyyhhmmss") + "-photo.jpeg" }.SetValue(stream);
}
}
if (!string.IsNullOrWhiteSpace(postRequest.FacebookPageId))
{
fbUserID = postRequest.FacebookPageId;
}
postUrl = postUrl.Replace("<fbid>", fbUserID);
var result = await facebookClient.PostTaskAsync(postUrl, fbParameters);
Look at my postUrl variable. I update the with the user ID in Facebook or the PageID if it is a page so the post should be properly posted in the right object. If there is some image to upload, so add it to the dictionary.
So, with it in mind, I have the following questions:
When the fbUserID is a user ID, the post happens perfectly, with the image and description but, when the ID is a PageID, only the description text is posted and image is just ignored(the user has the manage_page permissions so I dont think it is a permission issue). What I'm doing wrong that the image is not being posted to the page's wall?
If I want to post a video instead of a image, what should I change in this code?
Already saw many problems with other technologies here in SO but never a conclusive solution.
Thank you very much for the help, I really appreciate.
Regards,
Gutemberg
Got it!
Facebook creates a different section inside the page called Recent Posts by Others on Test Page where people allowed to post images will be there, like an attachment icon. In order to post directly to the page's feed/wall, all I need to do is instead of use the user access_token(even if user granted manage_pages permission) just use the access_token that comes in /me/accounts object for the respective page.
About the video post, I just set the ContentType to "video/mpeg" and at server instead of set picture parameter on dictionary, I've set the video field with the video byte[].
Thanks!
Regards,
As an alternative you could try the Share Content button shown in one of the answers here:
Upload video on Facebook using Graph REST API on Windows Phone 8.1
I found that to be easier than tackling authorization and manually posting.

Categories

Resources