Firebase negativ topic condition stop working - firebase

Actually today I received a customer report.
The push notification do not arrive at the devices.
After some research I figured out that the negative topic condition I use to send notifications to all devices, stop working.
One week ago the sending worked well with the same condotions.
I uses Postman for developing the requests.
I use the Rest API with "send" endpoint.
https://fcm.googleapis.com/fcm/send
here is my payload:
{
"condition":"!('nonExistingTopic' in topics)",
"data": {
"notification_foreground": true,
"link": "https://www.google.com"
},
"notification": {
"click_action": "FCM_PLUGIN_ACTIVITY",
"title": "notification title",
"body": "notification message"
}
}
I received an "ok"-status from Firebase ad the "message_id", but no message was send. So obviously the condition do not fit to any of the devices.
When I use the field "registration_ids" with a fcm token of my device I receive the notification.
I allready tried to find some kind of Update changes in firebase changelogs, that maybe changed the behavior of the condition field. But I did not find anything.
Does anybody have the same problems?
Any ideas for a work around!
Thank You!

I have the same problem here, as temporary solution I have to send notifications thought Firebase Console (because I use it just for communication with users).
Also I will launch a new update that now it is registering to a topic called "general" when start up.
I didn't figure out how to send to all users using negative topic condition. It stopped working about 10 days ago.

Meanwhile i found a solution for this problem.
I only use the condition-field for really existing topics.
"condition" = "'sport' in topics"
To send a message to all devices you can use the "to" parameter with the value "/topics/all", instead of the "negativ" condition.
{
"notification": {
"title": "myTitle",
"body": "myTeaser"
},
"to": "/topics/all",
"data": {
"myCustomDataField": "myFieldValue"
}
}

Related

Always get “Cannot parse non Measurement Protocol hits”

I have a little Python program that other people use and I would like to offer opt-in telemetry such that can get an idea of the usage patterns. Google Analytics 4 with the Measurement Protocol seems to be the thing that I want to use. I have created a new property and a new data stream.
I have tried to validate the request and set it to www.google-analytics.com/debug/mp/collect?measurement_id=G-LQDLGRLGZS&api_secret=JXGZ_CyvTt29ucNi9y0DkA via post and send this JSON payload:
{
"app_instance_id": "MyAppId",
"client_id": "TestClient.xx",
"events": [
{
"name": "login",
"params": {}
}
]
}
The response that I get is this:
{
"validationMessages": [
{
"description": "Cannot parse non Measurement Protocol hits.",
"validationCode": "INTERNAL_ERROR"
}
]
}
I seem to be doing exactly what they do in the documentation or tutorials. I must be doing something wrong, but I don't know, what is missing. What do I have to do in order to successfully validate the request?
Try to remove /debug part in the URL. In the example you followed it is not present so it is not quite exactly the same.
we just came across the same issue and the solution for us was to put https:// in front of the URL. Hope this helps.

Google calendar API return conference data as pending

When we create an event using google calendar API, it would not return hangout link in some cases, but return the status as pending.
"conferenceData": {
"createRequest": {
"requestId": "kavprurmn7h34jxcq6vgiufs2k",
"conferenceSolutionKey": {
"type": "hangoutsMeet"
},
"status": {
"statusCode": "pending"
}
}
},
I would assume that Google would return the Hangout link if we try to get the event after some time. The challenge is how to test this scenario. It is hard to reproduce this issue when you need to test, but the issue happens once in a while in production. How do we test this ? Is there a way to simulate this API behavior?
If the event is still pending not all information might be available. You have to try to get it until the event status is success.
In this situation you should use exponential backoff to try to get the Hangouts link. This prevents making unnecessary calls that may fill your quota or throttle your network. To accomplish this on Javascript, as an example, you can use .setTimeout(). Feel free to ask any question to expand this answer.

Custom sound push notification does not work (Flutter)

{
"to": "XXXX",
"notification": {
"title": "ASAP Alert",
"body": "Please open your app"
},
"data": {
"screen": "/Nexpage1",
"sound": "alarm",
"click_action": "FLUTTER_NOTIFICATION_CLICK"
}
}
Above is my payload for the push notification. I have insert the alarm.mp3 file inside the raw folder, however it still does not give me the alarm sound, i have try for alarm.mp3 also, is there anything wrong with the json? of it because of the code on my dart file?
Reading this it seems that it should be manage automatically (if you didn't use a notification builder) on Android but you have to specify the .mp3 extension too and put it inside notification field and not data one..
"sound": "alarm.mp3"
iOS behaves very differently under the hood but you can use a custom sound by setting the sound: field in the notification payload too. Anyway .mp3 is not a valid APN notification file format, and you need to specify also the file extention.
"sound": "filename.caf"
Follow Apple documentation in order to forge your custom sound file for your app.
mp3 is not a valid format
Preparing Custom Alert Sounds
Local and remote notifications can specify custom alert sounds to be
played when the notification is delivered. You can package the audio
data in an aiff, wav, or caf file. Because they are played by the
system-sound facility, custom sounds must be in one of the following
audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
Place custom sound files in your app bundle or in the
Library/Sounds folder of your app’s container directory. Custom
sounds must be under 30 seconds when played. If a custom sound is
over that limit, the default system sound is played instead.
You can use the afconvert tool to convert sounds. For example, to
convert the 16-bit linear PCM system sound Submarine.aiff to IMA4
audio in a CAF file, use the following command in the Terminal app:
afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v
For exampole to convert your mp3 file in a caf file you could type in terminal:
afconvert -f caff -d LEI16 alarm.mp3 alarm.caf
Read this doc in order to have a deep inside of all generic and specific notifciation payload fields.
UPDATE
I've tested the Android part and I can confirm that putting your .mp3 file in res/raw/ folder the sound is played as documented and expected.
That's my notification payload:
{
"to" : "my_device_token",
"collapse_key" : "type_a",
"priority" : "high",
"notification" : {
"body" : "Test Notification body for custom sound {{datestamp}}",
"title": "Custom sound alert.mp3",
"sound": "alert.mp3"
}
}
I've tested also the iOS version after converting .mp3 file to .caf file in that way:
afconvert -f caff -d LEI16 alert.mp3 alert.caf
the same json payload with the different filename works:
{
"to" : "my_device_token",
"collapse_key" : "type_a",
"priority" : "high",
"notification" : {
"body" : "Test Notification body for custom sound {{datestamp}}",
"title": "Custom sound alert.mp3",
"sound": "alert.caf"
}
}
Remember to add the file in your main bundle.
That works if the app is terminated or in background.
If you want to show an alert and play a sound when the app is in foreground you have to manage it on onMessage event like someone already have told you here, or you can use a platform-channel here to build your own notification with a Notification.Builder on Android and a UNNotificationCenter on iOS (for example).
UPDATE
This issue has been solved. See here the official comment:
Hey all 👋
As part of our roadmap (#2582) we've just shipped a complete rework of
the firebase_messaging plugin that aims to solve this and many other
issues.
If you can, please try out the dev release (see the migration guide
for upgrading and for changes) and if you have any feedback then join
in the discussion here.
Given the scope of the rework I'm going to go ahead and close this
issue in favor of trying out the latest plugin.
Thanks everyone 🤓
ShadowSheep did a good job at answering this question, but there's one thing I want to clarify for trying to get the iOS sounds to work.
You have to add the sound into XCode (which is where ShadowSheep speaks of including the asset inside of the main bundle). You can just drag and drop the audio file (in .caf or other supported format mentioned above) into the root directory (usually called Runner for Flutter) in XCode:
If you have done this and follow the setup described in the above question/answer, you should be in business.
For me I am using the flutter_local_notifications to create the notification channel.
include this function (may create multiple notification channel)
Future<void> _createNotificationChannel(String id, String name,
String description, String sound) async {
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
var androidNotificationChannel = AndroidNotificationChannel(
id,
name,
description,
sound: RawResourceAndroidNotificationSound(sound),
playSound: true,
);
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(androidNotificationChannel);}
call the function in initState: (this created 2 notification channel)
_createNotificationChannel("channel_id_1", "channel_name", "description", "alert");
_createNotificationChannel("channel_id_2", "channel_name", "description", "alarm");
Remember to save the file of alert and alarm in the res/raw in file format of .mp3.
with this payload :
{
"notification": {
"title": "My First Notification",
"body": "Hello, I'm push notification"
},
"data": {
"title": "My First Notification"
},
"android": {
"notification": {
"channel_id": "channel_id_1"
}
},
"to": "device_token"}
For the people who try to make custom sound for both android and ios good guide here:
For iOS:
To add a custom sound for iOS, add the audio clip for iOS to your
project's App_Resources/iOS/ directory (iOS only accepts .wav, .aiff,
and .caf extensions).
For Android:
First, add the audio clip to your project's
App_Resources/Android/src/main/res/raw/ directory ((Android only
accepts .wav, .mp3 and .ogg extensions).
So we can use .wav file in order to use custom sound available for both platform:
"notification": {
"body": "Test notification",
"title": "Test Test Test",
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"sound": "your_custom_sound.wav"
"android_channel_id": "channel_id_youcreated",
},
'to':
"",
},
after try this solution in Android I still can't change with custom sound. You need .ogg file type to resolve this issue. After changed to .ogg file type, I can change with custom sound. Thanks.

Using webhooks with Google Analytics

I'm trying to integrate my CRM with Google Analytics to monitor lead changes (from lead to sell) and so on. As I understood, I need to use Google Measurement Protocol, to receive webhooks from CRM and translate it to Analytics Conversions.
But in fact, I don't really understand how to do it. I need to make some script, to translate webhook code to analytics, but where I need to place that script? Are there some templates? And so on.
So, If you know some tutorials/courses/freelancers to help me with intergrating webhooks with Analytics - I need your advice.
Example of webhook from CRM:
{
"leads": {
"status": {
"id": "25399013",
"name": "Lead title",
"old_status_id": "7039101",
"status_id": "142",
"price": "0",
"responsible_user_id": "102525",
"last_modified": "1413554372",
"modified_user_id": "102525",
"created_user_id": "102525",
"date_create": "1413554349",
"account_id": "7039099",
"custom_fields": [
{
"id": "427183",
"name": "Checkbox custom field",
"values": ["1"]
},
{
"id": "427271",
"name": "Date custom field",
"values": ["1412380800"]
},
{
"id": "1069602",
"name": "Checkbox custom field",
"values": ["0"]
},
{
"id": "427661",
"name": "Text custom field",
"values": ["Валера"]
},
{
"id": "1075272",
"name": "Date custom field",
"values": ["1413331200"]
}
]
}
}
}
"Webhook" is a fancy way of saying that your CRM can call a web based service whenever something interesting happens (i.e. the CRM can "hook" into a web based application). E.g. if a new lead is created you can call an url with the lead details as parameters.
Specifics depend on your CRM, but when you set up a webhook there should be a field to set a url; the script that evaluates the CRM data is located at the URL.
You have that big JSON thing as your example - No real way to tell without knowing your system, but I assume that is sent as request body. So in your script you evaluate the request body, extract the parameters you want to send to analytics (be mindful that you are not allowed to store personally identifiable information) and sent it via the measurement protocol as described in the documentation linked in the other answer.
Depending on the system you might even be able to call the measurement protocol without having a custom script in between (after all the measurement protocol is an url with a few parameters).
This is an awfully generic answer, but then the question is really broad.
I've done just this in my line of work.
You need to first decide your data model on how you would like the CRM data to look within Google Analytics. This could be just mapping Google Analytics' event category, event label, event action to your data, or perhpas using custom dimensions and metrics.
Then to make it most useful, you would like to be able to link the CRM activity of a customer to their online activity. You can do this if they login online. In that case, you can set the cid and/or uid of the user to your CRM id.
Then, if you send in a GA hit with the same cid/uid in your Measurement Protocol hit, you will link the online sessions with your offline CRM activity.
To make the actual record hit Google Analytics, you will need to program something that takes the CRM data and turns it into a Measurement Protocol hit, which is essentially just a URL with the correct parameters. Look here for reference: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference
An example could be: http://www.google-analytics.com/collect?v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageA
We usually have this as a seperate process, that fires when the CRM data is written to its database (the webhook in your example). If its a lot of data, you should probably implement checks to see if the hit was sucessful, and caching in case the service is not online - you have an optional parameter that gives you 4 hours leeway in sending data.
Hope this gets you at least started.

Find out my own user ID for sending a message with Telegram API

For Telegram, how can I find out my own user id (chat_id) for use with the Telegram API?
I want to send myself a message via the Telegram API, like this:
https://api.telegram.org/bot<BOTID>/sendMessage
Send a message to your bot then retrieve the update with:
https://api.telegram.org/bot<BOTID>/getUpdates
In the json string returned you will find you chat_id/user_id.
In single chat with the bot chat_id is equal to user_id.
Now you can send your message with:
https://api.telegram.org/bot<BOTID>/sendMessage?chat_id="yourchatid"&text="Hello!"
You could use Json Dump Bot.
The relevant section of the output will be similar to:
{
"message": {
"from": {
"id": WHAT_YOU_ARE_LOOKING_FOR,
"is_bot": false,
"first_name": "Paolo",
"language_code": "it"
}
}
}
or: https://t.me/userinfobot - just forward message to get his id
The easier way is to go to the web version of Telegram and go to the chat whose ID you want to know. It'll be in the URL which is in form:
https://web.telegram.org/#/im?p=u<ID>_<something>
For groups this works too, but their IDs are negative, so if URL looks like
https://web.telegram.org/#/im?p=g1234567
then group chat ID is -1234567.
On Android (or rather Lineage) I was able to look up the user_id under "Settings > Accounts > Telegram"
The placeholder is actually a token, not a key. Surely you already know what that is and can use it?
https://core.telegram.org/bots/api#authorizing-your-bot

Resources