Notification format FCM firebase - firebase

I test a push notification fcm with a postman. When i put my data by
{
"to" : "YOUR_FCM_TOKEN_WILL_BE_HERE",
"collapse_key" : "type_a",
"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification"
},
"data" : {
"body" : "Body of Your Notification in Data",
"title": "Title of Your Notification in Title",
"key_1" : "Value for key_1",
"key_2" : "Value for key_2"
}
}
I receive a notification. But when i change it to a custom notification
{
"to" : "YOUR_FCM_TOKEN_WILL_BE_HERE",
"collapse_key" : "type_a",
"data" : {
"body" : "Sending Notification Body From Data",
"title": "Notification Title from Data",
"key_1" : "Value for key_1",
"key_2" : "Value for key_2"
}
}
I don't receive any notifications anymore. Anyone knows this problem ?
I follow this article https://medium.com/android-school/test-fcm-notification-with-postman-f91ba08aacc3
My thanks !!!

You are missing this from your second statement, which is required:
"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification"
},

Related

Hierarchical (Firebase) Database Structure, 'Posts/User', or 'Users/Posts'?

I am trying to build a structure that allows users to access only their own posts.
I have two possible ways in mind, and I'm not sure either of them is best practice. My end goal is to allow a user to read and write to all of their own posts only.
Approach A - Posts/Users (Not sure this can work from a security standpoint)
{
"posts" : {
"001" : {
"text" : "note 1",
"userID" : "user1"
},
"002" : {
"text" : "note 2",
"userID" : "user1"
},
"003" : {
"text" : "note 3",
"userID" : "user2"
}
}
}
Approach B - Users/Posts (Not as flat as Approach A)
{
"users" : {
"user1" : {
"posts" : {
"001" : {
"text" : "note 1",
},
"002" : {
"text" : "note 2",
},
}
},
"user2" : {
"posts" : {
"003" : {
"text" : "note 3",
},
},
}
}
I'm trying to follow the guidelines to keep data flat. In reality the post items will have more than just text, but not extend more than 2 levels deep. Thanks for any advice you can give!
I would have
{
"Users": {
"user1uniqueRef": {
"postIDUniqueRef1": {
"text" : "Here is someText"
"imageURL" : "https:// etc etc etc"
"postIDUniqueRef2": {
"text" : "Here is someText"
"imageURL" : "https:// etc etc etc"
"user2uniqueRef": {
"postIDUniqueRef1": {
"text" : "Here is someText"
"imageURL" : "https:// etc etc etc"
}
}
}

Loading mapbox with Firebase database

I'm trying to learn Firebase and Mapbox and wanted to integrate the two. Firebase stores some of my data in the following format:
{
"messages" : {
"-KUE2EwfvbI48Azw01Hv" : {
"geometry" : {
"coordinates" : [ 28.6618976, 77.22739580000007 ],
"type" : "Point"
},
"properties" : {
"description" : "xyz",
"hashtag" : "#xyz",
"imageUrl" : "xyz.jpg",
"name" : "Xyz Xyz",
"photoUrl" : "xyz.jpg",
"title" : "XYZ"
},
"type" : "Issue"
},
"-KUD2EwfvbI48Azw01Hv" : {
"geometry" : {
"coordinates" : [ 12.9715987, 77.59456269999998 ],
"type" : "Point"
},
"properties" : {
"description" : "xyz",
"hashtag" : "#xyz",
"imageUrl" : "xyz.jpg",
"name" : "Xyz Xyz",
"photoUrl" : "xyz.jpg",
"title" : "XYZ"
},
"type" : "Issue"
}
}
}
Is there a way to load the data and plot it into Mapbox? The examples require a GeoJSON file hosted somewhere that can be used to plot them. How can we use the Firebase database to plot on the Mapbox in realtime?
Sorry if my question is ambiguous. I'm willing to provide more information if needed :D
Thanks!
You can load the data, but you first have to convert it to a valid GeoJSON object.
Here is a JSFiddle using the data you provided:
https://jsfiddle.net/mkrv9uuy/
var firebaseGeojsonFeatures = [];
for (var key in firebaseData.messages) {
var f = firebaseData.messages[key];
f.type = "Feature";
firebaseGeojsonFeatures.push(f);
}

My structure in Firebase db. Is that proper hierarchy?

I would like to constract proper structure for an app which shows a list of companies. When I tap on one company, the app shows phone numbers in other view. Could somebody advise me with my structure?
{
"companies" : {
"c1" : {
"name" : "Secure Home LLP",
"subject" : "Security"
}
},
"phones" : {
"c1" : {
"p1" : {
"name" : "Check point",
"phone" : "201-478-4600"
},
"p2" : {
"name" : "Dispatcher",
"phone" : "201-478-4678"
}
}
}
}
The structure that you have given will be a great tiring work while parsing into the different data.
This following structure will be a better Option. You can parse into the phone numbers just by getting into the company keys. Here it is c1, c1
{
"companies" : {
"c1" : {
"name" : "Secure Home LLP",
"subject" : "Security",
"p1" : {
"name" : "Check point",
"phone" : "201-478-4600"
},
},
"c2" : {
"name": "neCompanyName",
"subject" : "Design",
"p2" : {
"name" : "Dispatcher",
"phone" : "201-478-4678"
}
}
}
}

Send mail to email addresses from webform when content is edited

I am attempting to use the rules, webform and webform rules modules to send an email to the email addresses of fetched submissions after existing content is edited.
QUESTION: Can anyone see why my rules are not sending emails?
The rules I have configured are:
event -After updating existing content
Actions -Fetch webform submissions of node ID
Loop -fetched submissions
loop action -Send mail.
For the send mail TO field I have set the PHP evaluation field to:
<?php print $list_itemb->data['components']['email_address']['value'][0]; ?>
I have also tried:
<?php print $list_itemb->data['email_address']['value'][0]; ?>
I have attempted to follow the steps outlined in the below submission but it is still not working correctly.
Link: https://drupal.stackexchange.com/questions/69134/send-mail-to-email-addresses-from-webform-when-a-content-is-saved
EXPORT OF RULES:
{ "rules_test_form_final" : {
"LABEL" : "Test form final",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "webform_rules", "php", "rules" ],
"ON" : { "node_update" : [] },
"DO" : [
{ "webform_submissions_load" : {
"USING" : { "nid" : "3333" },
"PROVIDE" : { "submissions" : { "submissions" : "Fetched submissions" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "submissions" ] },
"ITEM" : { "list_itemb" : "Current list item" },
"DO" : [
{ "mail" : {
"to" : "\u003C?php print $list_itemb-\u003Edata[\u0027components\u0027][\u0027title\u0027][\u0027value\u0027][0]; ?\u003E",
"subject" : "final test",
"message" : "test",
"language" : [ "" ]
}
}
]
}
}
]
}
}
Calling submission data using the fetch submissions action in the Drupal Rules module changes the format of the array.
The correct call is below:
<?php print $list_itemb->data['61'][0]; ?>

Mandrill API mis-reports bad formats

As specified in the documentation, I have to send arrays for google_analytics_domains and google_analytics_campaign fields.
http://mandrillapp.com/api/docs/messages.html#method=send
But mandrill generates a link with a wrong utm_campaign (Google analytics doesn't like the [0] part) :
utm_campaign[0]=test_campaign
I tried to send strings instead of arrays but the mandrallapi kicks me out (Please enter an array)... Did i miss something ? Thanks for your help !
Here is a request example with mandrillapp:
{
"key":"apikey",
"message":{
"html":"example html",
"text":"example text",
"subject":"example subject",
"from_email":"from_email#example.com",
"from_name":"example from_name",
"to":[
{
"email":"email#example.com",
"name":"example name"
}
],
"headers":{
"...":"..."
},
"track_opens":true,
"track_clicks":true,
"auto_text":true,
"url_strip_qs":true,
"bcc_address":"bcc_address#example.com",
"merge":true,
"global_merge_vars":[
{
"name":"example name",
"content":"example content"
}
],
"merge_vars":[
{
"rcpt":"rcpt#example.com",
"vars":[
{
"name":"example name",
"content":"example content"
}
]
}
],
"tags":[
"example tags[]"
],
"google_analytics_domains":[
"..."
],
"google_analytics_campaign":[
"..."
],
"metadata":[
"..."
],
"attachments":[
{
"type":"example type",
"name":"example name",
"content":"example content"
}
]
}
}

Resources