Firebase Push Notification how to set icon? Using Admin SDK in .NET - c#

Basically I want to set the icon on the push notification using Firebase. I am using their Firebase Admin .NET SDK. Which actually works just fine except for one minor detail, I cannot set the icon. Utilizing the class FirebaseAdmin.Messaging.Message then specifying the attribute Token then specifying the Notification object (which has three attributes):
Body
ImageUrl
Title
After setting those the push notification works fine, but the ImageUrl is an actual image withing the message not the icon. I want to set the icon. After look through the docs I noticed that Message has an attribute called Webpush of type WebpushConfig which that has an attribute Notification of type WebpushNotification and boom! there they are, a bunch of settings like Tile, Body, Vibrate and others, but the one I really want is in there Icon. Unfortunately setting the attributes for WebpushNotification do not seem to do anything. Here is my code.
public async Task Push(string token)
{
await messaging.SendAsync(new Message() {
Token = token,
Notification = new Notification() {
//Title = "This Title works",
//Body = "This body works",
//ImageUrl = "someUrlThatWorks"
},
Webpush = new WebpushConfig()
{
Notification = new WebpushNotification
{
Title = "This title does not work",
Body = "This body does not work",
Icon = "thisIconDoesNotWork.png"
}
}
});
}
Basically only the three attributes from FirebaseAdmin.Messaging.Notification work.
But the attributes from FirebaseAdmin.Messaging.WebpushNotification I cannot get to work, I just want the Icon from there.
Here are the Docs
Thank you.

add the following to AndroidManifest.xml file
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_stat_ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />

Related

What is the most simple way to make a local notification in Xamarin.Android?

I'm working on a Xamarin application and I'm very confused about making a local notification because it has a lot of details and channels things and others.
does anyone know how to make a simple notification
Even if you want to make it simple you need to know:
Android Notification is an element with several parts (title, description, logo...), that can be shown in the blocked screen or notification bar, that play a sound or vibrate, and that brings you to an application or make an action. You can control all of those elements.
To let the user the control of what the want to receive or not, devs must put their notification in channel, otherwise they won't work in Android 8.0 (Oreo) or above.
The steps are:
1-Create notification channel at the beggining of your Activity, inside OnCreate()
void CreateNotificationChannel()
{
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
//No need to create notification channel
return;
}
var name = Resources.GetString(Resource.String.channel_name);
var description = GetString(Resource.String.channel_description);
var channel = new NotificationChannel(CHANNEL_ID, name, NotificationImportance.Default)
{
Description = description
};
var notificationManager = (NotificationManager) GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);
}
2-Create notification with all of its components
var builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it
.SetContentIntent(new Intent()) // Just do nothing
.SetContentTitle("Simple notification") // Set the title
.SetNumber(count) // Display the count in the Content Info
.SetSmallIcon(Resource.Drawable.ic_stat_button_click) // This is the icon to display
.SetContentText("Description of the notification body"); // the message to display.
3-Put your notification in the channel
var notificationManager = NotificationManagerCompat.From(this);
notificationManager.Notify(NOTIFICATION_ID, builder.Build());
The whole example is taken from the official Xamarin docs, I really encourage you to take a few minutes to read the notifications docs, where you can learn about them in detail, I hope it helps!

Get notification origin in windows 10 uwp?

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.

Bot framework Directline -Change Bot name Run time

Is it possible to change the name of the bot during runtime. Current the name which i have added in portal is getting displayed under bot message. Is it possible to update it in run time rather than displaying the name configured in portal.
You can intercept all messages that are exchanged between user and bot, and you can check the value of activity.From.Name to detect if the message sent from your bot, and then you can specify a new value for activity.From.Name property, which would help achieve your requirement to show updated display name in webchat.
public async Task LogAsync(IActivity activity)
{
if (activity.From.Name== "fehanbasicbot")
{
activity.From.Name = "testbot";
}
}
Test result:
My bot settings:
In webchat:

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.

xamarin iOS non dismissible local notifications

I have a client that wants to have a local notification that the user can not dismiss and will be there until the app is closed. I can get this to work in android but not in iOS. I am working in xamarin and have had to break out of the pcl to accomplish this and the notifications in general. Is this something that can be accomplished(does apple allow this)? Or is a widget extension what I am in need of creating?
You can present a local notification on top of your running app
by implementing IUNUserNotificationCenterDelegate and calling the WillPresentNotification completionHandler with the UNNotificationPresentationOptions.Alert option.
But you can not prevent the user from dismissing it, thus is would be cleared from the Notification Center.
I'm not sure what information you are trying to show in the "permanent" notification, but it sounds like a Today View Widget is something you should look at. The downside of course is Today widgets require that the user manually adds the widget to the Today view and depending upon your needs that they enabled it for lock screen usage.
Here is how you would do a local notification and make it present itself on top of your app....
Implement IUNUserNotificationCenterDelegate:
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
completionHandler.DynamicInvoke( UNNotificationPresentationOptions.Alert );
}
Assign the UNUserNotificationCenter Delegate:
UNUserNotificationCenter.Current.Delegate = this;
Send a local notification:
var unAuthorizationOptions = UNAuthorizationOptions.Alert & UNAuthorizationOptions.Badge & UNAuthorizationOptions.Sound;
var authReply = await UNUserNotificationCenter.Current.RequestAuthorizationAsync(unAuthorizationOptions);
if (authReply.Item1 == true) // Xamarin.iOS does not label the tuple members ;-( (granted, error)
{
var content = new UNMutableNotificationContent
{
Title = "Local Notification",
Subtitle = "By SushiHangover",
Body = "StackOverflow rocks",
Badge = badgecount
};
var request = UNNotificationRequest.FromIdentifier("SushiHangover", content, null);
await UNUserNotificationCenter.Current.AddNotificationRequestAsync(request);
}

Categories

Resources