Rich Push notification with firebase and sending push notification with FCM on ios devices - swift

I have integrated the normal text based push notification through Firebase Cloud Messaging. The push is send through FCM server and its working fine.
But I am stuck on media based push notification including images and media based notification. I have also tested with postman console with format mentioned below:
Use a service api.
URL: https://fcm.googleapis.com/fcm/send
Method Type: POST
Headers:
Content-Type: application/json
Authorization: key=your api key
Body/Payload:
{ "notification": {
"title": "Your Title",
"text": "Your Text"
},
"data": {
"message": "Offer!",
"mediaUrl": "https://cdn.pixabay.com/photo/2018/01/21/01/46/architecture-3095716_960_720.jpg"
},
"to" : "to_id(firebase refreshedToken)"
}
Through this, I am receiving only normal text based push. What should be the error or correct way to send rich notification in ios 10 or later device??
Thanks in advance.

The correct format is this (tested)
{
"to": "deviceFCMtoken",
"notification":{
"title" : "Check this Title",
"subtitle" : "Subtitle",
"body" : "Body",
"mutable_content" : true,
"category" : "categoryID"
},
"data":{
"image-url": "www.something.com"
}
}

You should provide the mutable-content and content-available in your FCM payload. Both are boolean and must also be outside the notification parameter
{
"to" : "to_id(firebase refreshedToken),
"mutable_content": true,
"content-available": true,
"data": {
"message": "Offer!",
"mediaUrl": "https://cdn.pixabay.com/photo/2018/01/21/01/46/architecture-3095716_960_720.jpg
},
"notification": {
"title": "my title",
"subtitle": "my subtitle",
"body": "some body"
}
}

Related

Messenger bot with dialogflow does not respond to user

I have a messenger bot built with google's dialogflow engine, to respond the user I have a webhook. when I send a message with a "hello", the default welcome intent its triggered and the webhook it its called and it responds to me.
After that I need the products of my business so I write "Comprar" (Buy), the Products intent it is triggered and the webhook responds with a fulfillment message with a list of available products.
In the history section in google dialogflow, I can see the json respond of the wekhook with the message that the user will receive.
But facebook does not show the message. I use the same webhook for many intents, and it is not working in this case.
this is the respond I got in the History section for this case:
{
"id": "f75002cd-2f8a-422a-960d-dd2c9e00b490-74fe87bc",
"fulfillmentText": "",
"language_code": "es",
"queryText": "Comprar",
"webhookPayload": {},
"intentDetectionConfidence": 1,
"action": "GET_CATEGORIES",
"webhookSource": "",
"parameters": {},
"fulfillmentMessages": [
{
"quickReplies": {
"title": "Escoge alguna de estas Categorías:",
"quickReplies": [
"Volver",
"",
"FIRMA ELECTRONICA"
]
}
}
],
"diagnosticInfo": {
"webhook_latency_ms": "732.0"
},
"webhookStatus": {
"webhookStatus": {
"message": "Webhook execution successful"
},
"webhookUsed": true
},
"outputContexts": [
{
"lifespanCount": 1,
"name": "vercatalogo-followup",
"parameters": {}
}
],
"intent": {
"isFallback": false,
"displayName": "ver.catalogo",
"id": "41dcecf2-11b6-4e50-8294-b86d849093e1"
}
}
I solved lol
Apparently quickReplies must not contain a empty string ("") as a quick reply, that option is not valid. So I removed it and it worked.

How can I send notification from Postman using FCM?

I am using a Post method from the postman to send notifications to my flutter app, If I include the body outside of the notification in this way I can send notifications.
{
"to": "cu6HFvgXSCyKz5kjp..........",
"notification": {
"sound": "default",
"body": "test body",
"title": "test title",
"content_available": true,
"priority": "high"
},
"data": {
"sound": "default",
"body": "test body",
"title": "test title",
"content_available": true,
"priority": "high",
"ride_request_id":"asdfasd"
}
}
I can parse the data to get my value from ride_request_id but the catch is I get double notification, so FCM has suggested including the body inside the notification, Now, neither do I get the notification nor able to parse it. Although in Postman it shows as successful.
{
"to": "cu6HFvgXSCyKz5kjp..........",
"notification": {
"sound": "default",
"body": "test body",
"title": "test title",
"content_available": true,
"priority": "high",
"data": {
"sound": "default",
"body": "test body",
"title": "test title",
"content_available": true,
"priority": "high",
"ride_request_id": "asdfasd"
}
}
}
here is an article about sending a notification using postman:
Test FCM Notification with POSTMAN

Adding Videos to a Magento 2 product using REST

Magento version 2.2.5
Endpoint in question /V1/products/{sku}/media METHOD: POST
I am trying to add a video under a product sku using Magento's provided API endpoint.
{
"entry": {
"media_type": "external-video",
"label": "Video 2",
"position": 2,
"disabled": false,
"types": ["thumbnail"],
"content" : {
"base64_encoded_data": "encoded image data ",
"type": "image/jpeg",
"name": "0.jpg"
},
"extension_attributes": {
"video_content": {
"media_type": "external-video",
"video_provider": "youtube",
"video_url": "some youtube video url",
"video_title": "some title",
"video_description": "",
"video_metadata": ""
}
}
}
The response I get from this call is "invalid option value", I had debugged this in a local environment which leads me to failure during ProductRepository->save() within Magento\Catalog\Model\Product\GalleryGalleryManagement.php on line 70.
Is this an issue with my payload or actual magento bug?
Resolved this issue by adding videos directly using POST /V1/products or PUT /V1/products/{sku} endpoints.
post method example:
{
"product": {
"sku": "some-sku",
..... other product data,
"media_gallery_entries": {
"media_type": "external-video",
"label": "Video 2",
"position": 2,
"disabled": false,
"types": [],
"content" : {
"base64_encoded_data": "encoded image data ",
"type": "image/jpeg",
"name": "0.jpg"
},
"extension_attributes": {
"video_content": {
"media_type": "external-video",
"video_provider": "youtube",
"video_url": "some youtube video url",
"video_title": "some title",
"video_description": "",
"video_metadata": ""
}
}
}
}
I had no luck with Magento's MediaGallery POST endpoint (/V1/products/{sku}/media.
If you want to add a video to the product page then why you did not try using YouTube API?
You just need to follow these steps:
Generate a YouTube API Key by going goodle developer console
Then add Youtube API key to your Magento 2 by going to STORES --> Configuration
Then Add Video URL

sending push notification to Iphone using FCM

I am trying to send push notification to iPhone using FCM but notification is not received on my phone. Is there any issue in request json? please help me.
my request json is
{ "notification":{"aps": {"alert": "Hello","badge": 1,"sound ": "default "},"pushtype": "", "message": "Hello"} ,"to" : "c6IJyzv8LiY:APA91bHE1g-51dWnh_ofus0nUfVGwWQBV8zOp5fn9VcQe5GLL6gqLUCQQv1RUnYvQ0MP7Q5bKwgG1_8Uuudf67HV4hU1N-3U4u4uRVpdXw3QrivE8ONxjAAfcbn5cIUzu3B6FbHR8EkG"}
and my response json is:
{\"multicast_id\":5810493506209108338,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1473238399084785%fc69f82ff9fd7ecd\"}]}
I have fixed my problem, correct request json is:
{
"notification ": {
"title": "some title",
"text": "some text"
},
"to": "XjV2kOqh1yXNkJsQop17RlwSwT4jZpuAu-...",
"priority": "high"
}

How to add title, action buttons in ionic push notification

I'm implementing push notifications using ionic framework. I'm following sending push example given by ionic documentation. According to that the send request should be like
{
"tokens":[
"b284a6f7545368d2d3f753263e3e2f2b7795be5263ed7c95017f628730edeaad",
"d609f7cba82fdd0a568d5ada649cddc5ebb65f08e7fc72599d8d47390bfc0f20"
],
"notification":{
"alert":"Hello World!",
"ios":{
"badge":1,
"sound":"ping.aiff",
"expiry": 1423238641,
"priority": 10,
"contentAvailable": true,
"payload":{
"key1":"value",
"key2":"value"
}
},
"android":{
"collapseKey":"foo",
"delayWhileIdle":true,
"timeToLive":300,
"payload":{
"key1":"value",
"key2":"value"
}
}
}
}
I want ios notification to have title, body and action buttons like
"alert" : {
"body" : "This is a message from server",
"action-loc-key" : "VIEW",
"action" : [
{
"id" : "buttonTapped",
"title" : "View"
}
]
}
Is it possible with ionic push notification service? Any help please or any other APIs which does that?