I am trying to display notifications in my flutter app using awesome_notifications package (https://pub.dev/packages/awesome_notifications) . Below is my code.
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: UniqueKey().hashCode,
groupKey: message.data["senderUid"],
channelKey: 'basic_channel',
title: message.data["title"],
body: message.data["body"],
summary: message.data["body"], // Anything you want here
notificationLayout: NotificationLayout.Messaging,
),
);
Below is my Json data
"message": {
"token": recieverFcm,
"data": {
"title": senderName,
"body": message,
"chatRoomId": chatRoomId,
"sender_profile_pic": senderProfilePic,
"senderUid": senderUid,
"click_action": "OPEN_CHAT_ROOM"
},
"android": {
"priority": "high"
},
"apns": {
"payload": {
"aps": {
"category": "OPEN_CHAT_ROOM"
}
}
}
}
This works fine and I get notifications like below.
In here it is displaying the first letter of the sender's name as the icon/profile picture. Instead, I would like to display the real photo of the sender. This profile photo is already being sent by the JSON code.
How can I do this?
Related
I have made an app for Teams that I want to use to display an adaptive card to the user when they pick an item from the list of search results. In order for this to happen, I need to trigger some code after the user selects a result. This works as expected from the Teams client, as well as in the browser, but from native mobile Teams app, the code is not triggered when selecting an item from the list of results.
const preview = CardFactory.heroCard( obj.package.name );
preview.content.tap = { type: 'invoke', value: { description: obj.package.description } };
The following pictures show the app working in a browser on the computer:
The list of results from the browser on PC
The expected adaptive card showing correctly on browser
And this is how it looks from the mobile perspective:
The list of results from mobile app
The result of selecting the same item from the list
The code used to display this has not been modified, except providing a bot to host it, and was found from Microsoft's bot samples on GitHub:
https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/typescript_nodejs/50.teams-messaging-extensions-search
The code in question looks as follows:
export class TeamsMessagingExtensionsSearchBot extends TeamsActivityHandler {
public async handleTeamsMessagingExtensionQuery( context: TurnContext, query: any ): Promise<any> {
const searchQuery = query.parameters[ 0 ].value;
const response = await axios.get( `http://registry.npmjs.com/-/v1/search?${ querystring.stringify( { text: searchQuery, size: 8 } ) }` );
const attachments = [];
response.data.objects.forEach( ( obj: any ) => {
const heroCard = CardFactory.heroCard( obj.package.name );
const preview = CardFactory.heroCard( obj.package.name );
preview.content.tap = { type: 'invoke', value: { description: obj.package.description } };
const attachment = { ...heroCard, preview };
attachments.push( attachment );
} );
return {
composeExtension: {
attachmentLayout: 'list',
attachments,
type: 'result'
}
};
}
public async handleTeamsMessagingExtensionSelectItem( context: TurnContext, obj: any ): Promise<any> {
return {
composeExtension: {
attachmentLayout: 'list',
attachments: [ CardFactory.thumbnailCard( obj.description ) ],
type: 'result'
}
};
}
}
Is this expected?
Thanks
Edit: Adding the manifest JSON used here:
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.5/MicrosoftTeams.schema.json",
"manifestVersion": "1.5",
"version": "1.0.0",
"id": "9211fa66-f930-414d-861a-40f18f7f1490",
"packageName": "com.teams.sample.teamsmessagingextensionssearch",
"developer": {
"name": "teamsStartNewThreadInChannel",
"websiteUrl": "https://www.microsoft.com",
"privacyUrl": "https://www.teams.com/privacy",
"termsOfUseUrl": "https://www.teams.com/termsofuser"
},
"icons": {
"outline": "icon-outline.png",
"color": "icon-color.png"
},
"name": {
"short": "Search Messaging Extension",
"full": "Microsoft Teams Search Based Messaging Extension"
},
"description": {
"short": "Sample demonstrating a Search Based Messaging Extension",
"full": "Sample Search Messaging Extension built with the Bot Builder SDK"
},
"accentColor": "#FFFFFF",
"bots": [
{
"botId": "9211fa66-f930-414d-861a-40f18f7f1490",
"scopes": [
"personal",
"groupchat",
"team"
],
"supportsFiles": false,
"isNotificationOnly": false
}
],
"composeExtensions": [
{
"botId": "9211fa66-f930-414d-861a-40f18f7f1490",
"canUpdateConfiguration": true,
"commands": [
{
"id": "searchQuery",
"context": [
"compose",
"commandBox"
],
"description": "Test command to run query",
"title": "Search",
"type": "query",
"parameters": [
{
"name": "searchQuery",
"title": "Search Query",
"description": "Your search query",
"inputType": "text"
}
]
}
]
}
],
"permissions": [
"identity",
"messageTeamMembers"
],
"validDomains": []
}
We are able to re-pro the issue at our end. Raised a bug.We are tracking the bug internally, we don't have ETA to share when it will be fixed. Will update once it is fixed.
The question is same as here Call onMessage method when the app is in background in flutter and I am following the thread but since there is no response, I am asking this question again.
I've connected my Flutter app with Firebase Messaging and I am receiving notification when my app is in Foreground using the Flutter Local Notifications Plugin. But I cannot receive any notification when my app is in Background
Following is my code:
// FIREBASE CONFIGURATION & HANDLING
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
debugPrint("onMessage: $message");
final notification = message['data']['notification'];
Map responseBody = convert.jsonDecode(notification);
_showNotification(
icon: responseBody['icon'],
title: responseBody['title'],
body: responseBody['body'],
);
setState(() {});
},
);
// DISPLAY NOTIFICATION - HEADS UP
Future<void> _showNotification({String icon, String title, String body}) async {
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your channel id',
'your channel name',
'your channel description',
importance: Importance.Max,
priority: Priority.High,
ticker: 'ticker',
);
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0,
title,
body,
platformChannelSpecifics,
);
}
Can someone please guide me how can I receive notifications when my app is in Background
Resolved!!
The issue was with the format of curl calling. As per the instructions given here
Changed this:
{
"data": {
"notification": {
"title": "Notification Title",
"body": "Notification Body",
},
"click_action": "FLUTTER_NOTIFICATION_CLICK"
},
"to": "YOUR_DEVICE_TOKEN"
}
To this:
{
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"id": "1",
"status": "done",
},
"notification": {
"body": "Notification Body",
"title": "Notification Title"
},
"priority": "high",
"to": "YOUR_DEVICE_TOKEN"
}
I checked the Open application on notification click in OneSignal and OneSignal Push Notification Click to open actiivty but still not answers yet. So, I'm building a news app and integrating it with OneSignal, I'm able to receive the notification and when I clicking on it I'm getting the below JSON code
OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
this.setState(() {
print(
"Opened notification:
${result.notification.jsonRepresentation().replaceAll("\\n","\n")}");
});
});
JSON Response
Opened notification: {
"payload": "{
"google.delivered_priority": "normal",
"google.sent_time": 1561415365754,
"google.ttl": 259200,
"google.original_priority": "normal",
"custom": "{"a":{"id":"43682"},"i":"b0f4ef57-9556-4163-9e5c- fbcea08b4ce8"}",
"from": "800826514709",
"alert": "Test Alert",
"title": "Test Title",
"google.message_id": "0:1561415365759264%e192c215f9fd7ecd",
"notificationId": -655945385
I/flutter (30970): }",
"displayType": 2,
"shown": true,
"appInFocus": true,
"silent": null
I/flutter (30970): }
And the below code to capture the payload keys
print(result.notification.payload.jsonRepresentation());
JSON Response
{
"google.delivered_priority": "normal",
"google.sent_time": 1561415365754,
"google.ttl": 259200,
"google.original_priority": "normal",
"custom": "{"rec":{"id":"43682"},"i":"b0f4ef57-9556-4163-9e5c-fbcea08b4ce8"}",
"from": "800826514709",
"alert": "Test Alert",
"title": "Test Title",
"google.message_id": "0:1561415365759264%e192c215f9fd7ecd",
"notificationId": -655945385
}
My Question is how do I read the Key "notificationId" and "custom", I tried something like below but getting null
Map<String, dynamic> data =
json.decode(result.notification.jsonRepresentation());
print(data['custom']);
i have this solution for you.
var notificationId = result.notification.payload.rawPayload["notificationId"];
Map<String, dynamic> custom = result.notification.payload.additionalData;
Good luck :)
You can get additional data with this:
OneSignal.shared.setNotificationOpenedHandler((openedResult) async{
var additionalData = openedResult.notification.payload.additionalData;
if(additionalData != null){
if(additionalData.containsKey("myKey")){
var myValue= additionalData["myKey"];
}
}
});
I'm using firebase cloud function for send push notification. It works but issue by default it shows badge and does not play sound when notification comes.
Below is my playload code.
var playload = {
notification: {
title: msgData.title,
body: msgData.message,
sound: 'default',
badge: '0',
click_action: 'FLUTTER_NOTIFICATION_CLICK'
},
data: {
title: msgData.title,
body: msgData.message,
sound: 'default',
badge: '0',
click_action: 'FLUTTER_NOTIFICATION_CLICK'
}
}
var options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
return admin.messaging().sendToDevice(tokens, playload, options).then((response) => {
console.log('Sent to all the devices');
return response;
}).catch((err) => {
console.log(err);
return 0;
})
I have set 'sound': 'default' and badge: '0' but doesn't help me.
UPDATED:
I have tried with double quote for both keys and values but didn't work yet.
var playload = {
"notification": {
"title": msgData.title,
"body": msgData.message,
"sound": "default",
"badge": "0",
"click_action": "FLUTTER_NOTIFICATION_CLICK"
},
"data": {
"title": msgData.title,
"body": msgData.message,
"sound": "default",
"badge": "0",
"click_action": "FLUTTER_NOTIFICATION_CLICK"
}
}
Have you tried to replace your single quotes with double quotes?
From JSON.org:
A value can be a string in double quotes, or a number, or true or
false or null, or an object or an array. These structures can be
nested.
The title and the body of your message is processed before it eventually will fail which might be why it seems that your formatting is okay.
Let me know whether this has helped you.
I am trying to speed up notifications delivery on firebase notifications.
Because sometimes it might take 10 seconds to get the notification.
Currently I am using this message to send notification with admin.messaging().send(message).
const message = {
notification: {
title: 'Immediate Notification',
body: 'Important Message',
},
data: {
title: 'data',
body: 'some data'
},
android: {
ttl: 1000,
"notification": {
"sound": "default"
}
},
apns: {
headers: {
"apns-expiration": "1000",
},
payload: {
aps: {
badge: 1,
"sound": "default"
},
},
},
};
I am not sure if the speed will increase.
Need Clerification:-
1) If I put "apns-priority": "10" for iOS ? and priority high for android ? Something like this:
headers: {"apns-priority": "10"}
"android":{"priority":"high"},
2) If I set Time To Live to 0 ? ttl:0 and "apns-expiration": 0
3) If I don't send anything in data object ?
Or maybe there are any other way to speed them up ?